# Attributes with math formulas

## Recommended Posts

hi, I'm trying to create blocks with some mathematical formulas in the attributes, so that inserting values into the other attributes gives me a result in the attribute with the formula.

I have succeeded in very simple cases, but I would like to try with more complex formulas...

1) the biggest problem is that the procedure is too much intricate...(for example):

2) ...and the next problem is that I do not know the syntax for writing complicated formulas with roots, exponentiation, logarithms ecc...

Do you have any suggestions to give me or some discussion to signal me?

##### Share on other sites

sqrt function page 149 of my Acad 12 lisp manual (setq y 4) (sqrt y) =2

(exp number) constant e raised to the power of number page 111

(log number) natural log number page 131

What I am saying is that if you look up lisp help you will find the answers, writing a complex formula in lisp does require a bit of thought often requiring more than 1 line of code. compared to say normal coding expression VBA basic etc

##### Share on other sites

thank you...then, if I understood correctly, enter a formula into an attribute using the data field, has the same syntax as in lisp? and this also applies to autocad tables?

however, beyond the syntax, the procedure is really laborious ... muble muble ...

##### Share on other sites
On 8/8/2018 at 5:03 AM, itacad said:

1) the biggest problem is that the procedure is too much intricate...(for example):

2) ...and the next problem is that I do not know the syntax for writing complicated formulas with roots, exponentiation, logarithms ecc...

hi

1.) IMO in order to be more handy, you need to learn some coding

i recall Lee Mac's - FIELDMATH demo

2.) AFAIK, the FIELD code formula is evaluated in string format
which similar to 'CAL' (geomcal.arx) expression, it's different with LISP which function&expression is evaluated in a list

```CAL        -- LISP
------------------------
log(real)  -- (log real)
exp(real)  -- (exp real)
exp10(real) -- (expt 10 real)
sqr(real)  -- (expt real 2)
sqrt(real) -- (sqrt real)```

For more functions 'F1' (AutoCAD HELP)  search in  CAL topic

##### Share on other sites

mmmh...maybe I do not understand the suggestion, but I would like to work only with the formulas in the attributes, so I could pass the drawing without having to pass the lisp...maybe if you had an example ready to show me...Thank you in advance

##### Share on other sites
On 9/5/2018 at 3:47 AM, itacad said:

mmmh...maybe I do not understand the suggestion, but I would like to work only with the formulas in the attributes, so I could pass the drawing without having to pass the lisp...maybe if you had an example ready to show me...Thank you in advance

As mentioned in my previous, there 's link has few FIeld examples by Lee Mac

On 8/30/2018 at 10:40 PM, hanhphuc said:

hi

1.) IMO in order to be more handy, you need to learn some coding

i recall Lee Mac's - FIELDMATH demo

2.) AFAIK, the FIELD code formula is evaluated in string format
which similar to 'CAL' (geomcal.arx) expression, it's different with LISP which function&expression is evaluated in a list

This lisp is used to populate the objectid, string value then concatenation in field format / expression "%<\AcExpr >%".

programming makes thing simple

```(defun c:test ( / en1 en2 en3 f num)
(and
(setq en1 (car(nentsel "\nPick formula ")))
(setq en2 (car(nentsel "\nPick number ")))
(setq en3 (car(nentsel "\nPick result string ")))
(mapcar  ''((a b)(set a (strcat "%<\\AcObjProp Object(%<\\_ObjId "(itoa (vla-get-objectid (vlax-ename->vla-object b)))">%).TextString>%")))
'(f num )(list en1 en2 )
)
(vla-put-textstring (vlax-ename->vla-object en3) (strcat "%<\\AcExpr (" f " (" num ") )>%"))
)
(vl-cmdf "_.REGEN")
(princ)
)```