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

Вернуться   Форум DWG.RU > Программное обеспечение > Программирование > Быстрое поле ссылающееся на атрибут блока

Быстрое поле ссылающееся на атрибут блока

Ответ
Поиск в этой теме
Непрочитано 22.04.2014, 12:55 #1
Быстрое поле ссылающееся на атрибут блока
pro9
 
Конструктор
 
Уфа
Регистрация: 01.09.2012
Сообщений: 80

Добрый день!
На сайте Lee-mac нашел функцию quick field для быстрого создания полей

но не получается ее переделать, чтобы создать "Быстрое поле ссылающееся на атрибут блока"

пробовал что то вроде: (defun c:test4 ( ) (LM:QuickField "TextString" "%tc1" 3))
но поле создается только для текста и Мтекста

Можно ли как то осуществить быстрое создание поля ссылающегося на атрибут?
Просмотров: 6401
 
Непрочитано 22.04.2014, 17:46
#2
Do$

AutoCAD/Civil3D LISP/C#
 
Регистрация: 15.08.2008
Санкт-Петербург
Сообщений: 1,702
Отправить сообщение для Do$ с помощью Skype™


Суть в том, что Вы указываете блок, у которого нет такого свойства "TextString". А надо указывать конкретный атрибут. Возможно, что такого в программе не предусмотрено.
__________________
Толковый выбор приходит с опытом, а к нему приводит выбор бестолковый. (The Mechanic)
Do$ вне форума  
 
Автор темы   Непрочитано 22.04.2014, 18:19
#3
pro9

Конструктор
 
Регистрация: 01.09.2012
Уфа
Сообщений: 80


А можно ли сделать выбор конкретного атрибута? Или это слишком сложно.
pro9 вне форума  
 
Непрочитано 22.04.2014, 23:39
1 | #4
gomer

строю, ломаю
 
Регистрация: 03.04.2008
Украина
Сообщений: 5,515


можно воспользоваться функцией nentsel, которая позволяет выбирать примитивы внутри блока
gomer вне форума  
 
Непрочитано 23.04.2014, 07:51
1 | #5
Do$

AutoCAD/Civil3D LISP/C#
 
Регистрация: 15.08.2008
Санкт-Петербург
Сообщений: 1,702
Отправить сообщение для Do$ с помощью Skype™


Я не смог найти полностью код программы на сайте Lee Mac'a. По идее - да, надо подправить entsel на nentsel.
__________________
Толковый выбор приходит с опытом, а к нему приводит выбор бестолковый. (The Mechanic)
Do$ вне форума  
 
Автор темы   Непрочитано 23.04.2014, 11:25
#6
pro9

Конструктор
 
Регистрация: 01.09.2012
Уфа
Сообщений: 80


Цитата:
Сообщение от gomer Посмотреть сообщение
можно воспользоваться функцией nentsel, которая позволяет выбирать примитивы внутри блока
Цитата:
Сообщение от Do$ Посмотреть сообщение
Я не смог найти полностью код программы на сайте Lee Mac'a. По идее - да, надо подправить entsel на nentsel.
скачать и посмотреть полный код можно вверху страницы
http://www.lee-mac.com/lisp/QuickFieldV1-1.lsp - скачать lsp
http://www.lee-mac.com/lisp/html/QuickFieldV1-1.html - Посмотреть HTML версию

Код:
[Выделить все]
;;==========================================================================;;
;; 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 in uppercase (%tc1)  ;;
;;                                                                          ;;
;;==========================================================================;;

(defun c:test4 ( ) (LM:QuickField "TextString" "" 3))


;;---------------------=={ 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    -    20-04-2012                            ;;
;;------------------------------------------------------------;;

(defun LM:QuickField ( prop format mode / ent pt str )
    (if (null acdoc)
        (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
    )    
    (if (setq str (LM:ConstructFieldString prop format))
        (cond
            (   (= 1 mode)
                (if (setq ent (LM:SelectIfHasProp "Textstring" nentsel))
                    (vla-put-textstring (vlax-ename->vla-object ent) str)
                )
            )
            (   (= 2 mode)
                (if (setq pt (getpoint "\nSpecify Point for Text: "))
                    (vla-addtext
                        (vlax-get-property acdoc
                            (if (= 1 (getvar 'CVPORT)) 'paperspace 'modelspace)
                        )
                        str (vlax-3D-point (trans pt 1 0)) (getvar 'TEXTSIZE)
                    )
                )
            )
            (   (= 3 mode)
                (if (setq pt (getpoint "\nSpecify Point for MText: "))
                    (vla-addmtext
                        (vlax-get-property acdoc
                            (if (= 1 (getvar 'CVPORT)) 'paperspace 'modelspace)
                        )
                        (vlax-3D-point (trans pt 1 0)) 0.0 str
                    )
                )
            )
        )
    )
    (princ)
)

(defun LM: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.")
                )
                (   (eq 'ENAME (type ent))
                    (if (not (vlax-property-available-p (vlax-ename->vla-object ent) prop))
                        (princ (strcat "\nObject does not have " prop " property."))
                    )
                )
            )
        )
    )
    ent
)

(
    (lambda ( )
        (vl-load-com)
        (if (null acdoc)
            (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
        )
        (eval
            (list 'defun 'LM:ConstructFieldString '( prop format / ent )
                (list 'if '(setq ent (LM:SelectIfHasProp prop entsel))
                    (list 'strcat "%<\\AcObjProp Object(%<\\_ObjId "
                        (if
                            (and
                                (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
                                (vlax-method-applicable-p (vla-get-utility acdoc) 'getobjectidstring)
                            )
                            (list 'vla-getobjectidstring (vla-get-utility acdoc) '(vlax-ename->vla-object ent) ':vlax-false)
                           '(itoa (vla-get-objectid (vlax-ename->vla-object ent)))
                        )
                        ">%)." 'prop '(if (not (eq "" format)) (strcat " \\f \"" format "\">%") ">%")
                    )
                )
            )
        )
    )
)
(princ)

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

заменил LM:SelectIfHasProp prop entsel на LM:SelectIfHasProp prop nentsel и заработало

gomer, Do$ Спасибо большое!
Еще один маленький вопрос можно ли сделать так чтобы он не создавал новый mtext а добавлял к существующему mtext?
pro9 вне форума  
 
Непрочитано 23.04.2014, 11:30
#7
kakt00z

инженер-проектировщик КИПиА
 
Регистрация: 30.08.2008
Минск
Сообщений: 159


Цитата:
;; 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. ;;
(defun c:test4 ( ) (LM:QuickField "TextString" "" 1))
kakt00z вне форума  
 
Автор темы   Непрочитано 23.04.2014, 11:38
#8
pro9

Конструктор
 
Регистрация: 01.09.2012
Уфа
Сообщений: 80


Цитата:
Сообщение от kakt00z Посмотреть сообщение
(defun c:test4 ( ) (LM:QuickField "TextString" "" 1))
таким образом он заменяет текст, а можно ли сделать чтобы он добавлял к существующему тексту поле

Текст --> Текст"поле"
pro9 вне форума  
 
Непрочитано 23.04.2014, 11:48
1 | #9
kakt00z

инженер-проектировщик КИПиА
 
Регистрация: 30.08.2008
Минск
Сообщений: 159


( (= 4 mode)
(if (setq ent (LM:SelectIfHasProp "Textstring" nentsel))
(vla-put-textstring
(vlax-ename->vla-object ent)
(strcat (vla-get-TextString (vlax-ename->vla-object ent)) str)
)
)
)
kakt00z вне форума  
 
Автор темы   Непрочитано 23.04.2014, 11:53
#10
pro9

Конструктор
 
Регистрация: 01.09.2012
Уфа
Сообщений: 80


kakt00z, то что нужно. Спасибо большое!
pro9 вне форума  
 
Непрочитано 23.04.2014, 11:58
#11
kakt00z

инженер-проектировщик КИПиА
 
Регистрация: 30.08.2008
Минск
Сообщений: 159


пока до спецсимволов не дошел - будет работать
kakt00z вне форума  
 
Непрочитано 23.04.2014, 13:07
#12
Do$

AutoCAD/Civil3D LISP/C#
 
Регистрация: 15.08.2008
Санкт-Петербург
Сообщений: 1,702
Отправить сообщение для Do$ с помощью Skype™


Цитата:
Сообщение от pro9 Посмотреть сообщение
скачать и посмотреть полный код можно вверху страницы
В этом коде применяется функция LM:ConstructFieldString, вот ее описание я и не смог найти.
А, блин... Все, разобрался. Вот ведь извращенец! Он ее динамически создает в зависимости от разрядности процессора
__________________
Толковый выбор приходит с опытом, а к нему приводит выбор бестолковый. (The Mechanic)
Do$ вне форума  
 
Непрочитано 19.08.2015, 21:26 pro9
#13
perpetule


 
Регистрация: 23.09.2008
Волгоград
Сообщений: 810
<phrase 1= Отправить сообщение для perpetule с помощью Skype™


Удалось ли довести до ума функцию? Если да, просьба опубликовать.
__________________
tc71
perpetule вне форума  
 
Автор темы   Непрочитано 20.08.2015, 11:02
#14
pro9

Конструктор
 
Регистрация: 01.09.2012
Уфа
Сообщений: 80


Цитата:
Сообщение от perpetule Посмотреть сообщение
Удалось ли довести до ума функцию? Если да, просьба опубликовать.
Код:
[Выделить все]
 ;;==========================================================================;;
;; 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 in uppercase (%tc1)  ;;
;;                                                                          ;;
;;==========================================================================;;

(defun c:quickfield ( ) (LM:QuickField "TextString" "" 4))


;;---------------------=={ 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                     ;;
;;           mode=4 : Add to MText Object                     ;;
;;------------------------------------------------------------;;
;;  Returns:  -None-                                          ;;
;;------------------------------------------------------------;;
;;  Version 1.1    -    20-04-2012                            ;;
;;------------------------------------------------------------;;

(defun LM:QuickField ( prop format mode / ent pt str )
    (if (null acdoc)
        (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
    )    
    (if (setq str (LM:ConstructFieldString prop format))
        (cond
            (   (= 1 mode)
                (if (setq ent (LM:SelectIfHasProp "Textstring" nentsel))
                    (vla-put-textstring (vlax-ename->vla-object ent) str)
                )
            )
            (   (= 2 mode)
                (if (setq pt (getpoint "\nSpecify Point for Text: "))
                    (vla-addtext
                        (vlax-get-property acdoc
                            (if (= 1 (getvar 'CVPORT)) 'paperspace 'modelspace)
                        )
                        str (vlax-3D-point (trans pt 1 0)) (getvar 'TEXTSIZE)
                    )
                )
            )
            (   (= 3 mode)
                (if (setq pt (getpoint "\nSpecify Point for MText: "))
                    (vla-addmtext
                        (vlax-get-property acdoc
                            (if (= 1 (getvar 'CVPORT)) 'paperspace 'modelspace)
                        )
                        (vlax-3D-point (trans pt 1 0)) 0.0 str
                    )
                )
            )
			( (= 4 mode)
(if (setq ent (LM:SelectIfHasProp "Textstring" nentsel))
(vla-put-textstring
(vlax-ename->vla-object ent)
(strcat (vla-get-TextString (vlax-ename->vla-object ent)) str)
)
)
)
        )
    )
    (princ)
)

(defun LM: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.")
                )
                (   (eq 'ENAME (type ent))
                    (if (not (vlax-property-available-p (vlax-ename->vla-object ent) prop))
                        (princ (strcat "\nObject does not have " prop " property."))
                    )
                )
            )
        )
    )
    ent
)

(
    (lambda ( )
        (vl-load-com)
        (if (null acdoc)
            (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
        )
        (eval
            (list 'defun 'LM:ConstructFieldString '( prop format / ent )
                (list 'if '(setq ent (LM:SelectIfHasProp prop nentsel))
                    (list 'strcat "%<\\AcObjProp Object(%<\\_ObjId "
                        (if
                            (and
                                (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
                                (vlax-method-applicable-p (vla-get-utility acdoc) 'getobjectidstring)
                            )
                            (list 'vla-getobjectidstring (vla-get-utility acdoc) '(vlax-ename->vla-object ent) ':vlax-false)
                           '(itoa (vla-get-objectid (vlax-ename->vla-object ent)))
                        )
                        ">%)." 'prop '(if (not (eq "" format)) (strcat " \\f \"" format "\">%") ">%")
                    )
                )
            )
        )
    )
)
(princ)

;;------------------------------------------------------------;;
;;                         End of File                        ;;
;;------------------------------------------------------------;;
Добавил код из http://forum.dwg.ru/showpost.php?p=1257401&postcount=9

и соответственно (defun c:quickfield ( ) (LM:QuickField "TextString" "" 4))

Еще хотел сделать чтоб код поля копировался в буфер обмена, чтобы его можно было потом в любом месте посреди текста вставить. Случайно никто не знает как это сделать?
pro9 вне форума  
 
Непрочитано 20.08.2015, 11:11
#15
Кулик Алексей aka kpblc
Moderator

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


Цитата:
Сообщение от pro9 Посмотреть сообщение
чтоб код поля копировался в буфер обмена, чтобы его можно было потом в любом месте посреди текста вставить. Случайно никто не знает как это сделать?
В поиск по форуму "лисп буфер обмена"
__________________
Моя библиотека lisp-функций
---
Обращение ко мне - на "ты".
Все, что сказано - личное мнение.
Кулик Алексей aka kpblc вне форума  
 
Непрочитано 13.09.2017, 16:01
#16
pobat

инжинириг
 
Регистрация: 26.01.2012
Сообщений: 20


Подскажите как реализовать следующую функцию
а меня есть блок с атрибутом скажем N и копия того же блока
можно ли копировать атрибут из первой копии блока в атрибут второй копии?
pobat вне форума  
 
Непрочитано 13.09.2017, 16:14
#17
Кулик Алексей aka kpblc
Moderator

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


Атрибут - вряд ли. Значение атрибута - запросто. В чем трудность?
__________________
Моя библиотека lisp-функций
---
Обращение ко мне - на "ты".
Все, что сказано - личное мнение.
Кулик Алексей aka kpblc вне форума  
 
Непрочитано 13.09.2017, 17:43
#18
pobat

инжинириг
 
Регистрация: 26.01.2012
Сообщений: 20


Цитата:
Сообщение от Кулик Алексей aka kpblc Посмотреть сообщение
Атрибут - вряд ли. Значение атрибута - запросто. В чем трудность?
да-да. значение.
не могу разобраться
pobat вне форума  
 
Автор темы   Непрочитано 18.09.2017, 17:11
#19
pro9

Конструктор
 
Регистрация: 01.09.2012
Уфа
Сообщений: 80


Цитата:
Сообщение от pobat Посмотреть сообщение
можно ли копировать атрибут из первой копии блока в атрибут второй копии?
Добрый вечер!
Попробуй код из поста №14. Должен подойти.
pro9 вне форума  
Ответ
Вернуться   Форум DWG.RU > Программное обеспечение > Программирование > Быстрое поле ссылающееся на атрибут блока

Размещение рекламы
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Лишние символы в поле на многосточный атрибут блока. shartal AutoCAD 8 25.05.2020 14:06
Атрибут аннотативного динамического блока sergeev_2005 Динамические блоки 15 17.02.2015 15:00
Возврат данных о координате объекта в атрибут блока d.mOnII AutoCAD 15 13.10.2013 13:14
Изменить поле (формула) атрибута блока EfremenkoDO Программирование 5 08.04.2010 11:43
ПОле, вставленное в атрибут блока maestro AutoCAD 46 10.03.2007 01:43