Subtract Throws Error

Subtract Throws Error

Anonymous
Not applicable
976 Views
7 Replies
Message 1 of 8

Subtract Throws Error

Anonymous
Not applicable

I'm trying to subtract 2 numbers. I have made sure the numbers that I am trying to subtract are valid numbers, and they are. I have even just manually typed in numbers, but whenever the operator is a "-", the script doesn't complete.

(setq 
    w (- 10 2)
)
(princ w)

I have changed the "-" to addition, division, and multiplication and they all work fine, but if I do nothing but only change the "+" or whatever operator it is back to a "-", the script fails.

 

Any idea what might be causing this?

0 Likes
977 Views
7 Replies
Replies (7)
Message 2 of 8

dbhunia
Advisor
Advisor

can you post the script......


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 3 of 8

Anonymous
Not applicable

I started to work on a script that I plan on using Lee Mac's Steal command to import layers into older drawings:

 

(defun c:steal_60k ()
	; Get width and height
	(setq
		template_path (strcat (getvar "ROAMABLEROOTPREFIX") "Template\\")
		30k "30K-ACE"
		60k "60K-ACE.dwt"
		dwg_min (getvar "EXTMIN")
		dwg_max (getvar "EXTMAX")
w (- 10 4) ;w (- (nth 0 dwg_max) (nth 0 dwg_min)) ;h (- (nth 1 dwg_max) (nth 1 dwg_min)) ) (princ template_path) (PRINC "\nreached end") (princ) )

 When I either delete the "w (- 10 4)" line, or change the hyphen to a plus, the script works fine.

0 Likes
Message 4 of 8

dbhunia
Advisor
Advisor

After running this....

(defun c:steal_60k ()
	; Get width and height
	(setq
		template_path (strcat (getvar "ROAMABLEROOTPREFIX") "Template\\")
		30k "30K-ACE"
		60k "60K-ACE.dwt"
		dwg_min (getvar "EXTMIN")
		dwg_max (getvar "EXTMAX")
                ;w (- 10 4)
		w (- (nth 0 dwg_max) (nth 0 dwg_min))
		h (- (nth 1 dwg_max) (nth 1 dwg_min))
	)
	(princ template_path)
	(print W)
	(print h)
	(PRINC "\nreached end")
	(princ)
)

I did not get anything wrong....

 

My output is......(what is your output )

 

Capture.PNG


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 5 of 8

Anonymous
Not applicable

This is what I got when I copy/pasted what you did.

image.png

 

But if I change the subtraction to addition:

image.png

0 Likes
Message 6 of 8

dbhunia
Advisor
Advisor

I do not know why it is happening......... post your drawing I shall check it tomorrow.......

 

You can also do one thing by reset your AutoCAD to "Reset Settings to Default" and try it ..... But be careful it will reset all the custom settings to default ......

 

Good night have a nice day....

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 7 of 8

CodeDing
Advisor
Advisor

@Anonymous,

 

Try declaring your variables as local, so they reset  each time. See if that helps any...

 

(defun c:steal_60k ( / template_path 30k 60k dwg_min dwg_max w h)

Best,

 

~DD

0 Likes
Message 8 of 8

Anonymous
Not applicable

I will try that. Restarting AutoCAD luckily fixed the error, but I will add them as local too. (I'm still learning LISP. I'd rather use VBA, but I was told LISP is more powerful within AutoCAD, and my IT department won't install the VBA IDE for me).