TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: PM on January 15, 2022, 03:09:23 PM
-
Hi is possible to write a lisp to calculate a sigle text (this text must be anythig with numbers )
for examle
E1 = (1/2 x 59.328 x 102.361) + (1/2 x 16.672 x 85.953) = 3752.93 sq.m
or
E= 3036.410 + 716.521 = 3752.93 sq.m
Select the text
E1 = (1/2 x 59.328 x 102.361) + (1/2 x 16.672 x 85.953) =
and insert the calculation.
I get the idia by this photo
Thanks
-
Wouldn't you just use a table for that need?
-
i was thinking if i can do this without use a table, but a single text
-
There was a post I think over at Forums/autodesk convert formula to lisp, pretty sure for simple x*y x-y x+y x/y that has been done. I think did something
Anyway for autocad users Cal. Note no Cal in Bricscad
Command Cal
1234*456
562704
Command: CAL
>> Expression: (1/2 * 59.328 * 102.361) + (1/2 * 16.672 * 85.953)
You can save the cal into a variable
Command: (setq m2 (cal "(1/2 * 59.328 * 102.361) + (1/2 * 16.672 * 85.953)"))
3752.94
(setq str "(1/2 * 59.328 * 102.361)+(1/2 * 16.672 * 85.953)")
Command: (vl-cmdf "cal" str)
3752.94091
3752.94091
-
Is it possible to select the text , if have x instend of * to understand it and insert a text with the result ?
Thanks
-
Post updated, to allow for a string input.
Yes you will need to replace x with * in the text string when you pick the table text, lee-mac.com/stringsubst.html
-
I try this but is not working
(defun c:test
( new old str
/ inc len
) inc 0
)
inc (+ inc len)
)
)
str
)
thanks
-
not sure how to do this with lisp, but you can create an expression in fields I.e. %<\AcExpr (2*4)>%
I think LM has lisp tools to work with fields
-
Still need to convert x to * the others are ok / - +
-
The answer is a bit long winded, still need to replace X with *
http://www.theswamp.org/index.php?topic=41681
You need say (setq ans (eval (infix->prefix "2 * 2 * 34")))
-
I had problems but this works
(defun rep ( new old / inc len )
(setq len (strlen new) inc 0)
(while (setq inc (vl-string-search old str inc))
(setq str (vl-string-subst new old str inc))
(setq inc (+ inc len))
)
)
(setq str "2+(3x6/4)")
(rep "*" "x")
(princ str)
(vl-cmdf "cal" str)