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
-
and if only that was so simple…
- make sure that attribute1 has a numeric value.
- duble click on attribute2.
- in the "Edit attribute Definition" window, in "default" field right click → insert field.
- Under "Object" select "Formula"
- In The "Formula" field right click again and "Insert Field".
- In the "field names" click on "Objects". from the dropdown list select "Object".
- click on the arrow between "Object Type" and "Field Value".
- a selection box appeeres. select attribute1.
- Under "Object Type" and "Attribute Definition" you have a scroll down list of properies. scroll down to "value", select it and click "OK".
- Now you are back at the first formula field and see attribute1 value in the field.
- add *5.
- you are done.
0 -
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.
0 -
you're welcome.
try "UPDATEFIELD" command and select al the blocks.
0 -
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.
0 -
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.
0 -
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.
0 -
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)0