View Full Version : Subtract lisp
robert.1.hall72202
2005-10-13, 01:47 PM
Does anyone have a lisp routine that will subtract 2 numbers?????
jwanstaett
2005-10-13, 01:55 PM
where are you getting the number from
this will subtract 2 number
(- 10 20)
or just use the cal command
Command: cal
>> Expression: 10-20
-10
tyeelaw13
2005-10-13, 05:11 PM
you can also run the CAL command inside of another command, for instance if you were making a rectangle, you can type in 'cal when it asks for the length or width, and do a numeric function (like 20-10) and it will input the result into the command.. Pretty cool stuff
robert.1.hall72202
2005-10-13, 05:27 PM
I am looking to get the numbers from some dtext. Same as the add number routines just with subtraction instead.
kennet.sjoberg
2005-10-13, 08:28 PM
... Same as the add number routines just with subtraction instead.
You can ty to substitute the "+" with "-" in the lisp file.
: ) Happy Computing !
kennet
robert.1.hall72202
2005-10-14, 12:29 PM
That doesn't quite work.....I think it needs to figure out which order to use the numbers.
This is what I have for addition
(defun C:sub ()
(setq SSET (ssget (list (cons 0 "TEXT")))
CNT 0
SUM 0
)
(repeat (sslength SSET)
(setq ENAM (ssname SSET CNT)
CNT (1+ CNT)
EOBJ (vlax-ename->vla-object ENAM)
)
(if (equal (atof (rtos (atof (vla-get-textstring EOBJ)) 2))
(atof (vla-get-textstring EOBJ))
0.0001
)
(setq SUM (+ SUM (atof (vla-get-textstring EOBJ))))
)
)
SUM
)
kennet.sjoberg
2005-10-14, 03:19 PM
Well nice to see that you are trying to make your own code ;) this one is a bit modified
(defun C:sub (/ SelSet Counter VLO-Text Sum )
(setq SelSet (ssget (list (cons 0 "TEXT" )) ) Counter 0 )
(repeat (sslength SelSet )
(vl-load-com)
(setq VLO-Text (vlax-ename->vla-object (ssname SelSet Counter ) ) )
(if (equal (atof (rtos (atof (vla-get-textstring VLO-Text )) 2 )) (atof (vla-get-textstring VLO-Text )) 0.0001 )
(progn
(if (not Sum )
(setq Sum (atof (vla-get-textstring VLO-Text )) )
(setq Sum (- Sum (atof (vla-get-textstring VLO-Text ))) )
)
)
( )
)
(setq Counter (1+ Counter ) )
)
Sum
)
: ) Happy Computing !
kennet
robert.1.hall72202
2005-10-18, 12:45 PM
Thanks for your help, that is exactly what I was trying to work towards. I am going to understand this stuff sooner or later.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.