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
2,256 Views
5 Replies
Message 1 of 6

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
2,257 Views
5 Replies
Replies (5)
Message 2 of 6

Shneuph
Collaborator
Collaborator

Yah... looks like your if statement has 3 arguments instead of 2.  It can only take an "if true" and "if false" argument.  If you need to do more than one thing in either use (progn (your stuff)) to combine them.

 

Try:

 

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

 

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
0 Likes
Message 3 of 6

Kent1Cooper
Consultant
Consultant

[See the other thread on the same subject -- accidental double posting, I assume.]

Kent Cooper, AIA
0 Likes
Message 4 of 6

john.uhden
Mentor
Mentor

I thought sags were catenaries.  Does a spline approximate a catenary pretty well?

John F. Uhden

0 Likes
Message 5 of 6

stevor
Collaborator
Collaborator

Close enough for visual acuity.

Yet the end conditions alter the true catenary anyway,

which are somewhat solved by the Spline.

One  hyperbolic cosine curve lsp :

http://www.digitalcad.com/2001/05_may/images/math/catenary.lsp

More detail:

https://mysite.du.edu/~jcalvert/math/catenary.htm

 

 

S
0 Likes
Message 6 of 6

Anonymous
Not applicable
(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)
          (progn
            (setq sag (/ (* weight lsqr) (* 8 tension)))
            ;sag at
            (setq x_sag (/ l 2))
            (setq y_sag (- y0 sag))
            );end of first progn
          (progn
            ;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))
            );end of second progn
          );end of if
	
	;xy variable
  (setq sagPoint (list x_sag y_sag))

	
	;---------Draw the Curve------
	(command "spline" p1 sagpoint p2 "" 0 "")
	(setvar "osmode" oldsnap)
	(setvar "blipmode" oldblipmode)
);End of defun

I do not know calculations are true or not; but when using "if" condition with more than one function, you have to use "progn" function. I edited the if part at the code with progns.

 

(if (eq h 0)
(progn
(do something when h equals to 0)
(then another thing)
)
(progn
(or do something when h does not equal 0)
(then another thing...)
)

 Spline command suggest more than 3 inputs... so i change the code...

 

And setting sagpoint variable like this

 

(setq sagPoint (list x_sag y_sag))

 

0 Likes