Formula with attribute values

Dear all,

I cannot get the result of attribute value from a formula defined in a field. I just can get ####.

I defined 2 Attributes :

Attribute1 value = 500

Attribute2 value → Insert Field → Formula → 5*Attribute1

I also tried

Attribute2 value → Insert Field → Formula → 5*atof (Attribute1)

Does anyone could help me?

Comments

  • aridzv
    edited December 6

    and if only that was so simple…

    1. make sure that attribute1 has a numeric value.
    2. duble click on attribute2.
    3. in the "Edit attribute Definition" window, in "default" field right click → insert field.
    4. Under "Object" select "Formula"
    5. In The "Formula" field right click again and "Insert Field".
    6. In the "field names" click on "Objects". from the dropdown list select "Object".
    7. click on the arrow between "Object Type" and "Field Value".
    8. a selection box appeeres. select attribute1.
    9. Under "Object Type" and "Attribute Definition" you have a scroll down list of properies. scroll down to "value", select it and click "OK".
    10. Now you are back at the first formula field and see attribute1 value in the field.
    11. add *5.
    12. you are done.

  • Thank you very much for your time.

    It works well. The point now is when I duplicate the block in the drawing, the second one does not calculate the attribute2 value (#### even after a regenall). I mean I expect that if this block is imported twice in my drawing with 2 different Attribute1 values, I would get 2 different value of attribute2 after a regenall.

    Could it work so ?

    Thanks again for you precious help.

  • you're welcome.

    try "UPDATEFIELD" command and select al the blocks.

  • It does not work. The attribute1 value does not figure any more in the formula of the block I have inserted the second time. the formula shows :*5 on the duplicated block. So the dynamic link is no more effective.

  • aridzv
    edited December 6

    O.K…

    when you create the block don't inset the formula,

    just make the 2 attributes.

    after you insert the block make the formula field in attribute2.

    then use updatefield after changing the value of attribute1.

    see attached video.

  • Not sure if this is relevant but when inserting blocks with a field linked to attributes you have to re-do the field code every time updating object source ID's. I used the method of inserting the block then using

    (Vlax-put obj 'textstring updatedIDofobject+fieldcode). Hope that makes sense.

  • @ALANH

    How do you use this line of code: (Vlax-put obj 'textstring updatedIDofobject+fieldcode) ?

    can you give an example?

    thanks.

  • Like this for 3rd attribute.

    ; 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" "c" (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)