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

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

Как получить значение аттрибута, как объекта?

Ответ
Поиск в этой теме
Непрочитано 22.05.2017, 09:43 #1
Как получить значение аттрибута, как объекта?
AlexZh
 
Регистрация: 23.09.2015
Сообщений: 146

Здравствуйте!

Как получить значение атрибута как объекта? Например, чтоб потом использовать данных атрибут в полях. Аттрибут может быть многострочным, может быть скрытым, может быть и постоянным.
__________________
Проекты СС
Просмотров: 2541
 
Непрочитано 22.05.2017, 10:17
#2
Кулик Алексей aka kpblc
Moderator

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


vla-get-textstring, кажется.
__________________
Моя библиотека lisp-функций
---
Обращение ко мне - на "ты".
Все, что сказано - личное мнение.
Кулик Алексей aka kpblc вне форума  
 
Автор темы   Непрочитано 22.05.2017, 10:52
#3
AlexZh


 
Регистрация: 23.09.2015
Сообщений: 146


Цитата:
Сообщение от Кулик Алексей aka kpblc Посмотреть сообщение
vla-get-textstring, кажется.
не, не то. возвращает текст. а нужен именно объект.

но нашел в справке, то что надо!

Код:
[Выделить все]
 (vl-load-com)
(defun c:Example_GetAttributes()
    ;; This example creates a block. It then adds attributes to that
    ;; block. The block is then inserted into the drawing to create
    ;; a block reference.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
    
    ;; Create the block
    (setq insertionPnt (vlax-3d-point 0 0 0))
    (setq blockObj (vla-Add (vla-get-Blocks doc) insertionPnt "TESTBLOCK"))
    
    ;; Define the attribute definition
    (setq attHeight 1
          attMode acAttributeModeVerify
          attPrompt "Attribute Prompt"
          attTag "Attribute_Tag"
          attValue "Attribute Value"
          insertionPoint (vlax-3d-point 5 5 0))
    
    ;; Create the attribute definition object in model space
    (setq attributeObj (vla-AddAttribute blockObj attHeight attMode attPrompt insertionPoint attTag attValue))
    
    ;; Insert the block
    (setq insertionPnt (vlax-3d-point 2 2 0))
    (setq modelSpace (vla-get-ModelSpace doc))
    (setq blockRefObj (vla-InsertBlock modelSpace insertionPnt "TESTBLOCK" 1 1 1 0))
    (vla-ZoomAll acadObj)
    
    ;; Get the attributes for the block reference
    (setq varAttributes (vlax-variant-value (vla-GetAttributes blockRefObj)))
    
    ;; Move the attribute tags and values into a string to be displayed in a Msgbox
    (setq strAttributes ""
          I 0)
    (while (>= (vlax-safearray-get-u-bound varAttributes 1) I)
        (setq strAttributes (strcat strAttributes "\n  Tag: " (vla-get-TagString (vlax-safearray-get-element varAttributes I))
                                                  "\n  Value: " (vla-get-TextString (vlax-safearray-get-element varAttributes I)) "\n"))
        (setq I (1+ I))
    )

    (alert (strcat "The attributes for blockReference " (vla-get-Name blockRefObj) " are: " strAttributes))
    
    ;; Change the value of the attribute
    ;; Note: There is no SetAttributes. Once you have the variant array, you have the objects.
    ;; Changing them changes the objects in the drawing.
    (vla-put-TextString (vlax-safearray-get-element varAttributes 0) "NEW VALUE!")
    
    ;; Get the attributes
    (setq newvarAttributes (vlax-variant-value (vla-GetAttributes blockRefObj)))
    
    ;; Again, display the tags and values
    (setq strAttributes ""
          I 0)
    (while (>= (vlax-safearray-get-u-bound varAttributes 1) I)
        (setq strAttributes (strcat strAttributes "\n  Tag: " (vla-get-TagString (vlax-safearray-get-element varAttributes I))
                                                  "\n  Value: " (vla-get-TextString (vlax-safearray-get-element varAttributes I)) "\n"))
        (setq I (1+ I))
    )
    (alert (strcat "The attributes for blockReference " (vla-get-Name blockRefObj) " are: " strAttributes))

да и здесь чего то не разобраться.
__________________
Проекты СС

Последний раз редактировалось AlexZh, 22.05.2017 в 11:07.
AlexZh вне форума  
 
Непрочитано 22.05.2017, 11:07
#4
Кулик Алексей aka kpblc
Moderator

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


Для справки: есть постоянные и непостоянные атрибуты. Методика работы может отличаться.
Значения могут быть "по умолчанию" или "у вхождения". Тоже по-разному обрабатывается.
Ты уж определись, что именно и для каких случаев тебе надо.
__________________
Моя библиотека lisp-функций
---
Обращение ко мне - на "ты".
Все, что сказано - личное мнение.
Кулик Алексей aka kpblc вне форума  
 
Автор темы   Непрочитано 22.05.2017, 11:15
#5
AlexZh


 
Регистрация: 23.09.2015
Сообщений: 146


Цитата:
Сообщение от Кулик Алексей aka kpblc Посмотреть сообщение
Для справки: есть постоянные и непостоянные атрибуты. Методика работы может отличаться.
Значения могут быть "по умолчанию" или "у вхождения". Тоже по-разному обрабатывается.
Ты уж определись, что именно и для каких случаев тебе надо.
Нужно значение у вхождения, которое меняется.
и его (значение этого атрибута) "упаковать в поле"
Код:
[Выделить все]
 ;; Field Code  -  Lee Mac
;; Returns the field expression associated with an entity
 
(defun LM:fieldcode ( ent / replacefield replaceobject enx )
 
    (defun replacefield ( str enx / ent fld pos )
        (if (setq pos (vl-string-search "\\_FldIdx" (setq str (replaceobject str enx))))
            (progn
                (setq ent (assoc 360 enx)
                      fld (entget (cdr ent))
                )
                (strcat
                    (substr str 1 pos)
                    (replacefield (cdr (assoc 2 fld)) fld)
                    (replacefield (substr str (1+ (vl-string-search ">%" str pos))) (cdr (member ent enx)))
                )
            )
            str
        )
    )
 
    (defun replaceobject ( str enx / ent pos )
        (if (setq pos (vl-string-search "ObjIdx" str))
            (strcat
                (substr str 1 (+ pos 5)) " "
                (LM:ObjectID (vlax-ename->vla-object (cdr (setq ent (assoc 331 enx)))))
                (replaceobject (substr str (1+ (vl-string-search ">%" str pos))) (cdr (member ent enx)))
            )
            str
        )
    )
    
    (if
        (and
            (wcmatch  (cdr (assoc 0 (setq enx (entget ent)))) "TEXT,MTEXT,ATTRIB,MULTILEADER,*DIMENSION")
            (setq enx (cdr (assoc 360 enx)))
            (setq enx (dictsearch enx "ACAD_FIELD"))
            (setq enx (dictsearch (cdr (assoc -1 enx)) "TEXT"))
        )
        (replacefield (cdr (assoc 2 enx)) enx)
    )
)
 
;; ObjectID  -  Lee Mac
;; Returns a string containing the ObjectID of a supplied VLA-Object
;; Compatible with 32-bit & 64-bit systems
 
(defun LM:ObjectID ( obj )
    (eval
        (list 'defun 'LM:ObjectID '( obj )
            (if
                (and
                    (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
                    (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring)
                )
                (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false)
               '(itoa (vla-get-objectid obj))
            )
        )
    )
    (LM:ObjectID obj)
)
 
;; Active Document  -  Lee Mac
;; Returns the VLA Active Document Object
 
(defun LM:acdoc nil
    (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
    (LM:acdoc)
)
__________________
Проекты СС
AlexZh вне форума  
 
Непрочитано 22.05.2017, 13:18
#6
roaa

ОПС
 
Регистрация: 29.03.2012
Kazakhstan
Сообщений: 128


Цитата:
Сообщение от AlexZh Посмотреть сообщение
Как получить значение атрибута как объекта?
http://forum.dwg.ru/showthread.php?t=22653
https://forum.dwg.ru/showthread.php?t=71229

Последний раз редактировалось roaa, 22.05.2017 в 13:24.
roaa вне форума  
Ответ
Вернуться   Форум DWG.RU > Программное обеспечение > Программирование > LISP > Как получить значение аттрибута, как объекта?

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


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
LISP. Создание поля (field), ссылающегося на текстовое значение ячейки таблицы. skkkk Готовые программы 141 24.11.2023 15:49
Как перенести значение площади объекта в таблицу Libet AutoCAD 22 05.04.2015 15:15
Lisp/ActiveX. Как получить значение элемента безопасного массива? Kirill_Ja LISP 1 15.08.2013 12:28
Значение аттрибутов блоков Андрей Будзинский AutoCAD 5 16.12.2009 17:18
Можно ли получить список реакторов объекта? kos Программирование 1 13.01.2005 13:28