| Правила | Регистрация | Пользователи | Сообщения за день |  Справка по форуму | Файлообменник |

Вернуться   Форум DWG.RU > Программное обеспечение > Программирование > LISP > Извлечение атрибута блока в поле

Извлечение атрибута блока в поле

Ответ
Поиск в этой теме
Непрочитано 26.04.2020, 15:58 #1
Извлечение атрибута блока в поле
Kavalergrad
 
Москва
Регистрация: 21.11.2014
Сообщений: 60

Подскажите, пожалуйста, как извлечь атрибут блока в поле?
Просмотров: 1804
 
Непрочитано 26.04.2020, 16:28
#2
Сергей812


 
Регистрация: 10.08.2013
Сообщений: 11,040


Поле внутри блока расположено или вне?
Сергей812 вне форума  
 
Автор темы   Непрочитано 26.04.2020, 16:33
#3
Kavalergrad


 
Регистрация: 21.11.2014
Москва
Сообщений: 60


Поле располагается не в блоке, а в другом конце чертежа.
Kavalergrad вне форума  
 
Непрочитано 26.04.2020, 16:46
#4
Сергей812


 
Регистрация: 10.08.2013
Сообщений: 11,040


ну как и к другим объектам - выбираете в диалоге вставки поля объект, выбираете нужную вставку блока в качестве объекта, затем нужный атрибут
Сергей812 вне форума  
 
Автор темы   Непрочитано 26.04.2020, 17:07
#5
Kavalergrad


 
Регистрация: 21.11.2014
Москва
Сообщений: 60


Извините, я имел ввиду средствами LISP.
Kavalergrad вне форума  
 
Непрочитано 26.04.2020, 19:08
#6
Кулик Алексей aka kpblc
Moderator

LISP, C# (ACAD 200[9,12,13,14])
 
Регистрация: 25.08.2003
С.-Петербург
Сообщений: 39,843


Тема перенесена. Kavalergrad, внимательнее выбирай раздел форума.
__________________
Моя библиотека lisp-функций
---
Обращение ко мне - на "ты".
Все, что сказано - личное мнение.
Кулик Алексей aka kpblc вне форума  
 
Автор темы   Непрочитано 27.04.2020, 09:49
#7
Kavalergrad


 
Регистрация: 21.11.2014
Москва
Сообщений: 60


А куда вы ее перенесли? Где искать?
Kavalergrad вне форума  
 
Непрочитано 27.04.2020, 09:58
#8
Кулик Алексей aka kpblc
Moderator

LISP, C# (ACAD 200[9,12,13,14])
 
Регистрация: 25.08.2003
С.-Петербург
Сообщений: 39,843


Из раздела "AutoCAD" в раздел "LISP":

Миниатюры
Нажмите на изображение для увеличения
Название: 2020-04-27_09-57-35.png
Просмотров: 93
Размер:	5.4 Кб
ID:	225522  
__________________
Моя библиотека lisp-функций
---
Обращение ко мне - на "ты".
Все, что сказано - личное мнение.
Кулик Алексей aka kpblc вне форума  
 
Автор темы   Непрочитано 27.04.2020, 09:59
#9
Kavalergrad


 
Регистрация: 21.11.2014
Москва
Сообщений: 60


Спасибо
Kavalergrad вне форума  
 
Непрочитано 28.04.2020, 07:21
#10
skkkk


 
Регистрация: 20.03.2008
Сообщений: 2,653


Цитата:
Сообщение от Kavalergrad Посмотреть сообщение
Подскажите, пожалуйста, как извлечь атрибут блока в поле?
Цитата:
Сообщение от Kavalergrad Посмотреть сообщение
средствами LISP
У Lee Mac есть отличная программа QuickField. Сейчас почему-то его сайт недоступен, поэтому приведу код здесь (тем более, что для данной задачи его пришлось немного подправить - добавить один символ):
Код:
[Выделить все]
 ;;======================================================================;;
;;  Quick Field Program  -  Lee Mac                                     ;;
;;======================================================================;;
;;                                                                      ;;
;;  Program Description                                                 ;;
;;  -------------------------------                                     ;;
;;                                                                      ;;
;;  This function is designed to enable the user to quickly create      ;;
;;  custom  programs for inserting multiple fields into a drawing.      ;;
;;                                                                      ;;
;;  This could be for use in situations in which the user is required   ;;
;;  to create many fields in a drawing, with each field referencing     ;;
;;  the same object property, and continued use of the Field Command    ;;
;;  Dialog can become tedious.                                          ;;
;;                                                                      ;;
;;  Custom programs can be created by calling the 'LM:quickfield'       ;;
;;  function with a string describing the object property to be         ;;
;;  referenced by the field; a string describing the field formatting;  ;;
;;  and an integer to determine how the field will be created.          ;;
;;                                                                      ;;
;;  When creating the custom field programs, the user is advised to     ;;
;;  first use the Field Command dialog with all settings set to create  ;;
;;  the desired field, then make note of the Field Expression           ;;
;;  displayed at the bottom of the dialog. The required QuickField      ;;
;;  parameters may then be read directly from this Field Expression.    ;;
;;                                                                      ;;
;;  Each parameter is described in more detail below.                   ;;
;;                                                                      ;;
;;======================================================================;;
;;  Notes on QuickField Parameters                                      ;;
;;======================================================================;;
;;                                                                      ;;
;;  'prop'    [STR]                                                     ;;
;;                                                                      ;;
;;  This parameter is a string describing the object property to be     ;;
;;  referenced by the field.                                            ;;
;;                                                                      ;;
;;  Example:                                                            ;;
;;  ------------------                                                  ;;
;;  Field Expression displayed in Field Command Dialog:                 ;;
;;                                                                      ;;
;;  %<\AcObjProp Object(%<\_ObjId 2129673136>%).Area \f "%lu6%qf1">%    ;;
;;                                                                      ;;
;;  For the above expression, the object property is "Area"             ;;
;;                                                                      ;;
;;----------------------------------------------------------------------;;
;;                                                                      ;;
;;  'format'  [STR]                                                     ;;
;;                                                                      ;;
;;  This parameter is a string describing the field formatting for the  ;;
;;  object property that is to be displayed.                            ;;
;;                                                                      ;;
;;  If no formatting is to be used, 'format' should be an empty         ;;
;;  string ("").                                                        ;;
;;                                                                      ;;
;;  Example:                                                            ;;
;;  ------------------                                                  ;;
;;  Field Expression displayed in Field Command Dialog:                 ;;
;;                                                                      ;;
;;  %<\AcObjProp Object(%<\_ObjId 2129673136>%).Area \f "%lu6%qf1">%    ;;
;;                                                                      ;;
;;  For the above expression, the field formatting is "%lu6%qf1"        ;;
;;  This formatting string indicates that the Area property of the      ;;
;;  object will be displayed using the current units and precision in   ;;
;;  the drawing.                                                        ;;
;;                                                                      ;;
;;----------------------------------------------------------------------;;
;;                                                                      ;;
;;  'mode'    [INT]                                                     ;;
;;                                                                      ;;
;;  This integer parameter determines how the field should be created   ;;
;;  in the drawing.                                                     ;;
;;                                                                      ;;
;;  mode = 1  :  Replace Existing Text / MText / Attribute string.      ;;
;;                                                                      ;;
;;               This mode will prompt the user to select an existing   ;;
;;               object to contain the field.                           ;;
;;                                                                      ;;
;;  mode = 2  :  Create Text Object                                     ;;
;;                                                                      ;;
;;               The user will be prompted to pick a point at which a   ;;
;;               Text Object containing the field will be created.      ;;
;;                                                                      ;;
;;  mode = 3  :  Create MText Object                                    ;;
;;                                                                      ;;
;;               This user will be prompted to pick a point at which    ;;
;;               an MText Object containing the field will be created.  ;;
;;                                                                      ;;
;;                                                                      ;;
;;======================================================================;;
;;  Example Custom Field Programs                                       ;;
;;======================================================================;;
;;                                                                      ;;
;;  Example Program #1:                                                 ;;
;;  -----------------------------------                                 ;;
;;                                                                      ;;
                                                                      
    (defun c:test1 ( ) (LM:QuickField "Area" "%lu6%qf1" 2))        
                                                                      
;;                                                                      ;;
;;  Here,                                                               ;;
;;                                                                      ;;
;;     prop   =  "Area"                                                 ;;
;;     format =  "%lu6%qf1"                                             ;;
;;     mode   =  2                                                      ;;
;;                                                                      ;;
;;  This program will hence prompt the user to select an object with    ;;
;;  the "Area" property, then prompt for a point at which to create a   ;;
;;  Text Object (mode=2) containing the field.                          ;;
;;                                                                      ;;
;;  The displayed Area will be formatted using the current settings     ;;
;;  for Units and Precision.                                            ;;
;;                                                                      ;;
;;======================================================================;;
;;                                                                      ;;
;;  Example Program #2:                                                 ;;
;;  -----------------------------------                                 ;;
;;                                                                      ;;

    (defun c:test2 ( ) (LM:QuickField "Length" "%lu2%pr3%ps[Length:,]%ct8[0.1]" 3))

;;                                                                      ;;
;;  Here,                                                               ;;
;;                                                                      ;;
;;     prop   =  "Length"                                               ;;
;;     format =  "%lu2%pr3%ps[Length:,]%ct8[0.1]"                       ;;
;;     mode   =  3                                                      ;;
;;                                                                      ;;
;;  This program will prompt the user to select an object with the      ;;
;;  "Length" property (Lines / LWPolylines / Polylines), then prompt    ;;
;;  for a point at which to create an MText Object (mode=3) containing  ;;
;;  the field.                                                          ;;
;;                                                                      ;;
;;  The Length value will be formatted...                               ;;
;;                                                                      ;;
;;     -  in Decimal Units (%lu2)                                       ;;
;;     -  to a Precision of 3 d.p. (%pr3)                               ;;
;;     -  with a Prefix of "Length:"  (%ps[Length:,])                   ;;
;;     -  with a Conversion Factor of 0.1  (%ct8[0.1])                  ;;
;;                                                                      ;;
;;======================================================================;;
;;                                                                      ;;
;;  Example Program #3:                                                 ;;
;;  -----------------------------------                                 ;;
;;                                                                      ;;

    (defun c:test3 ( ) (LM:QuickField "StyleName" "%tc1" 1))

;;                                                                      ;;
;;  Here,                                                               ;;
;;                                                                      ;;
;;     prop   =  "StyleName"                                            ;;
;;     format =  "%tc1"                                                 ;;
;;     mode   =  1                                                      ;;
;;                                                                      ;;
;;  This program will prompt the user to select an object with the      ;;
;;  "StyleName" property (Text / MText / ...anything with a Style),     ;;
;;  then prompt for an existing object (mode=1) to house the field.     ;;
;;                                                                      ;;
;;  The referenced StyleName property will be displayed as              ;;
;;  uppercase (%tc1).                                                   ;;
;;                                                                      ;;
;;======================================================================;;

;;--------------------------=={ Quick Field }==-------------------------;;
;;                                                                      ;;
;;  Creates a field using the method encoded by the 'mode' argument,    ;;
;;  using the supplied field property and format strings.               ;;
;;----------------------------------------------------------------------;;
;;  Author:  Lee Mac, Copyright © 2011  -  www.lee-mac.com              ;;
;;----------------------------------------------------------------------;;
;;  Arguments:                                                          ;;
;;  prop    -  Object Property to link to field (e.g. "Area")           ;;
;;  format  -  Field formatting string (use "" for none)                ;;
;;  mode    -  Integer to determine how the field is created            ;;
;;                                                                      ;;
;;             mode=1 : Replace Existing Text, MText, Attribute         ;;
;;             mode=2 : Create Text Object                              ;;
;;             mode=3 : Create MText Object                             ;;
;;----------------------------------------------------------------------;;
;;  Returns:  -None-                                                    ;;
;;----------------------------------------------------------------------;;
;;  Version 1.1    -    2012-04-20                                      ;;
;;                                                                      ;;
;;  - First release.                                                    ;;
;;----------------------------------------------------------------------;;
;;  Version 1.2    -    2015-10-10                                      ;;
;;                                                                      ;;
;;  - Program updated to account for selection of annotation objects    ;;
;;    which already contain a field expression.                         ;;
;;----------------------------------------------------------------------;;
;;  Version 1.3    -    2016-04-10                                      ;;
;;                                                                      ;;
;;  - Program updated to incorporate UPDATEFIELD command when inserting ;;
;;    a field into attribute content.                                   ;;
;;----------------------------------------------------------------------;;

(defun LM:quickfield ( prop format mode / ent ins obj str )  
    (if (setq str (LM:quickfield:constructfieldstring prop format))
        (cond
            (   (= 1 mode)
                (if (setq ent (LM:quickfield:selectifhasprop "Textstring" nentsel))
                    (progn
                        (setq obj (vlax-ename->vla-object ent))
                        (vla-put-textstring obj "") ;; To clear any existing field
                        (vla-put-textstring obj str)
                        (if (= "ATTRIB" (cdr (assoc 0 (entget ent))))
                            (vl-cmdf "_.updatefield" ent "")
                        )
                    )
                )
            )
            (   (= 2 mode)
                (if (setq ins (getpoint "\nSpecify point for text: "))
                    (vla-addtext
                        (vlax-get-property (LM:quickfield:acdoc)
                            (if (= 1 (getvar 'cvport))
                                'paperspace
                                'modelspace
                            )
                        )
                        str (vlax-3D-point (trans ins 1 0)) (getvar 'textsize)
                    )
                )
            )
            (   (= 3 mode)
                (if (setq ins (getpoint "\nSpecify point for mtext: "))
                    (vla-addmtext
                        (vlax-get-property (LM:quickfield:acdoc)
                            (if (= 1 (getvar 'cvport))
                                'paperspace
                                'modelspace
                            )
                        )
                        (vlax-3D-point (trans ins 1 0)) 0.0 str
                    )
                )
            )
        )
    )
    (princ)
)

(defun LM:quickfield:selectifhasprop ( prop func / ent )
    (while
        (progn
            (setvar 'errno 0)
            (setq ent (car (func (strcat "\nSelect object with " prop " property: "))))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (null ent)
                    nil
                )
                (   (not (vlax-property-available-p (vlax-ename->vla-object ent) prop))
                    (princ (strcat "\nSelected object does not have " prop " property."))
                )
            )
        )
    )
    ent
)

(defun LM:quickfield:acdoc nil
    (eval (list 'defun 'LM:quickfield:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
    (LM:quickfield:acdoc)
)

(   (lambda nil (vl-load-com)
        (eval
            (list 'defun 'LM:quickfield:constructfieldstring '( prop format / ent )
                (list 'if '(setq ent (LM:quickfield:selectifhasprop prop nentsel))
                    (list 'strcat "%<\\AcObjProp Object(%<\\_ObjId "
                        (if (vlax-method-applicable-p    (vla-get-utility (LM:quickfield:acdoc)) 'getobjectidstring)
                            (list 'vla-getobjectidstring (vla-get-utility (LM:quickfield:acdoc)) '(vlax-ename->vla-object ent) ':vlax-false)
                           '(itoa (vla-get-objectid (vlax-ename->vla-object ent)))
                        )
                        ">%)." 'prop '(if (/= "" format) (strcat " \\f \"" format "\">%") ">%")
                    )
                )
            )
        )
    )
)
(princ)

;;----------------------------------------------------------------------;;
;;                             End of File                              ;;
;;----------------------------------------------------------------------;;


Нужно обеспечить загрузку этого кода, и вызывать его при помощи такой конструкции:
Код:
[Выделить все]
(LM:QuickField "TextString" "" 3)
На запрос Select object with TextString property: указать нужный атрибут. Далее последует запрос точки вставки мтекста. Если нужен простой текст, 3 в строке нужно заменить на 2, а если нужно вставить поле в существующий текст или мтекст, то заменить на 1. Пустые кавычки соответсвуют отсутсвию формата. В данном случае внутри них можно поместить то, что появляется в конце Формулы для поля при выборе, в окне Формат: например для пункта Верхний регистр - внутри кавычек нужно прописать %tc1, Нижний регистр - %tc2 и так далее.
skkkk вне форума  
Ответ
Вернуться   Форум DWG.RU > Программное обеспечение > Программирование > LISP > Извлечение атрибута блока в поле

Размещение рекламы


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Мои динамические блоки [2] Кулик Алексей aka kpblc Динамические блоки 4334 22.04.2019 09:16
Извлечение данных атрибута, в 2015 1234 Программирование 7 14.09.2015 09:07
Изменение значения атрибута в составе блока rzinnurov Программирование 27 06.12.2013 17:50
Извлечение текста из атрибута блока xag AutoCAD 4 30.03.2012 11:20
Создание динамически изменяемого атрибута для блока. Brobobo Динамические блоки 5 29.09.2011 13:20