Error too many Arguments (AKA I can't figure out what's wrong with my code)

Error too many Arguments (AKA I can't figure out what's wrong with my code)

Anonymous
Not applicable
1,277 Views
6 Replies
Message 1 of 7

Error too many Arguments (AKA I can't figure out what's wrong with my code)

Anonymous
Not applicable

I work in transmission engineering, and for a small exercise to learn some AutoLISP in my downtime I wrote a code to calculate and plot the sag of a line in AutoCAD. It looks right to me, but AutoCAD says there's are too many arguments in one section (Lines 30 to 36). I've compared that section to similar sections in other LISP programs I've written, and I can't seem to find the error. What am I missing? I've put the section I'm having issues with in bold red. 

 

; goal: make an autocad program that can plot accurate sagging for lines

(defun c:autosag ()
	;---------User Inputs-----------
	(setq p1 (getpoint "Choose starting pole"))
	(setq p2 (getpoint "Choose ending pole"))
	(setq tension (getint "Tension: "))
	(setq weight (getint "Weight per unit length: "))
	
	;--------- Snapping ----------------
	(setq oldsnap (getvar "osmode"))
	(setq oldblipmode (getvar "blipmode"))
	
	;switch off system variables
	(setvar "osmode" 0)
	(setvar "blipmode" 0)
	
	;---------Find X&Y values-------
	(setq x0 (car p1))
	(setq y0 (cadr p1))
	
	(setq xf (car p2))
	(setq yf (cadr p2))
	
	(setq l (- xf x0))
	(setq h (- yf y0))
	
	(setq lsqr (* l l))
	
	(if (eq h 0)
		(setq sag (/ (* weight lsqr) (* 8 tension)))
		
		;sag at
		(setq x_sag (/ l 2))
		(setq y_sag (- y0 sag))
	)
	(if (/= h 0)
		;Find x1 & x2
		(setq x1 (- (/ l 2) (/ (* tension h) (* weight l))))
		(setq x2 (+ (/ l 2) (/ (* tension h) (* weight l))))
		
		;Find sag
		(setq sag (/ (* weight (* x1 x1)) (* 2 tension)))
		
		;sag at
		(setq x_sag (+ x0 x1))
		(setq y_sag (- y0 sag))
	)
	
	;xy variable
		(setq sagPoint '(x_sag y_sag))
	
	;---------Draw the Curve------
	(command "spline"
	p1
	sagPoint
	p2
	)
	
	(setvar "osmode" oldsnap)
	(setvar "blipmode oldblipmode")
)
0 Likes
1,278 Views
6 Replies
Replies (6)
Message 2 of 7

Satoews
Advocate
Advocate

Are you missing a progn to do three things in the if statement?

 

(if (eq h 0)
  (progn
		(setq sag (/ (* weight lsqr) (* 8 tension)))
		
		;sag at
		(setq x_sag (/ l 2))
		(setq y_sag (- y0 sag))
  )
)

 

Shawn T
Message 3 of 7

Anonymous
Not applicable

Looks like you would be right! I was unaware of the progrn function. Thanks!

0 Likes
Message 4 of 7

Satoews
Advocate
Advocate

No problem, glad I could help!

Shawn T
Message 5 of 7

ВeekeeCZ
Consultant
Consultant

@Tornac wrote:

Are you missing a progn to do three things in the if statement?

 

(if (eq h 0)
  (progn
		(setq sag (/ (* weight lsqr) (* 8 tension)))
		
		;sag at
		(setq x_sag (/ l 2)) ;better with dot -> 2.
		(setq y_sag (- y0 sag))
  )
)

 


Could be solved by using one (setq) for more variables too...

 

(if (eq h 0)
  (setq sag (/ (* weight lsqr) (* 8 tension)))
  (setq x_sag (/ l 2)
        y_sag (- y0 sag))
)

BTW be careful with dividing by an INTEGER! (/ l 2)

If your l would be an integer (e.g. 3), then result would be an integer as well!! (/ 3 2) = 1 !!!

If you not sure what l gonna be, the use a real: (/ l 2.) = see the dot! Atleast one of those members has to be a real to get a real. (/ 3 2.) = 1.5

 

 

0 Likes
Message 6 of 7

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:

BTW be careful with dividing by an INTEGER! (/ l 2)  ....

If you not sure what l gonna be, the use a real: (/ l 2.) = see the dot! Atleast one of those members has to be a real to get a real. (/ 3 2.) = 1.5


That's not necessary in this case -- they are sure what the 'l' variable is gonna be.  It's a result of calculations based on coordinates of points, and those are always real numbers, so 'l' will also always be a real number, so the integer divider will not cause any problem.
Kent Cooper, AIA
0 Likes
Message 7 of 7

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:
....

Could be solved by using one (setq) for more variables too...

 

(if (eq h 0)
  (setq sag (/ (* weight lsqr) (* 8 tension)))
  (setq x_sag (/ l 2)
        y_sag (- y0 sag))
)

.... 


Didn't go quite far enough.  All three of those settings should be in one (setq) function if you want to eliminate the need for the (progn) "wrapper."  And to go even further, the original has an (if) test with something to do if h is 0, and another (if) test for something else to do if it's not 0.  Those can be collapsed into one (if) function -- if it's 0, do this, otherwise, do that:

 

(if (= h 0)

  (setq ; 'then' expression

    sag (/ (* weight lsqr) (* 8 tension))

    x_sag (/ l 2)

    y_sag (- y0 sag)

  ); setq
  (setq ; 'else' expression

    x1 (- (/ l 2) (/ (* tension h) (* weight l)))
    x2 (+ (/ l 2) (/ (* tension h) (* weight l)))
    sag (/ (* weight (* x1 x1)) (* 2 tension))
    x_sag (+ x0 x1)
    y_sag (- y0 sag)

  ); setq
); if

Kent Cooper, AIA
0 Likes