Block Attribute - Concatenated value

Dear All,

Is there any way to calculate automatically the value of a block attribute according the values of others attributes. For example :
Attribute 1 value = DN100
Attribute 2 value = 30m3/h
Attribute 3 value = DN100 - 30m3/h

Attribute3 value results from Attrubute 1 et 2 values.
It will be very apprecited if someone could provide an example.

Thanks for your help. BR

Comments

  • ALANH
    edited May 2023
    YES, you will need to edit to suit your block.

    ; add 2 attributes and put the value as a field into the 3rd attribute.
    ; BY AlanH

    (defun c:test ( / obj lst x )
    (setq oldatt (getvar 'attdia))
    (setvar 'attdia 0)
    (command "-insert" "yourblockname" (getpoint "\npick point") 1 1 0 (getstring "\nEnter Att1 ") (getstring "\nEnter Att2 ") (getstring "\nEnter Att3 ") "-")
    (setq obj (vlax-ename->vla-object (entlast)))
    (setq lst '())
    (foreach att (vlax-invoke obj 'getattributes)
    (princ "\n")
    (setq lst (cons (strcat "%<\\AcObjProp Object(%<\\_ObjId "
    (vlax-invoke-method (vla-get-Utility (vla-get-activedocument (vlax-get-acad-object))) 'GetObjectIdString att :vlax-false)
    ">%).Textstring>%"
    ) lst ))
    )
    (setq str nil)
    (setq x (length lst))
    (setq str (strcat "%<\\AcExpr "
    (nth (setq x (- x 1)) lst) " + "
    (nth (setq x (- x 1)) lst) " + "
    (nth (setq x (- x 1)) lst) ">%"
    )
    )
    (setq x 1 y 4)
    (foreach att (vlax-invoke obj 'getattributes)
    (if (= x y)
    (Vla-put-textstring att str)
    )
    (setq x (+ x 1))
    )
    (setvar 'attdia oldatt)
    (princ)
    )
    (c:test)
  • Thank you for your feedback. Is there any alternative without any Lisp Code ? Maybe with fields ?

  • Sukovykhap
    edited January 30

    Hello, you can insert field in to another field.

    Like a sample:

    1. Select block with attributes
    2. Right click on value of attribute "insert Field"
    3. Select "Objects"> "Formula"
    4. In input "formula" right click and select "Insert field"
    5. Select "Object"
    6. Select the same block
    7. Now you can choose one of attributes of this particular block and use it in formulas

    p.s. for correctly work maybe need "regen all"