Jump to content

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?

Thank you in advance

Link to comment
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

Link to comment
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 ...

Link to comment
Share on other sites

  • 3 weeks later...
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
------------------------
sin(deg)   -- (sin rad) 
cos(deg)   -- (cos rad)  
tang(deg)  -- (/ (sin rad)(cos rad))
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
 

Link to comment
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

Link to comment
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)
)

 

 

math.gif

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...