Need help getting a Lisp to work

Need help getting a Lisp to work

Anonymous
Not applicable
1,904 Views
11 Replies
Message 1 of 12

Need help getting a Lisp to work

Anonymous
Not applicable

Hello, I am having a hard time getting this Lisp to run in autocad.It gives me a "too many arguments" error. It is supposed to create a legend based on the pointstyle name of the points. This is being modified to work with the pointstyle name of the cogo points, previously a tblnext was used on the blocks, and worked flawlessly.

any advice would be appreciated. Thanks.

 

(defun c:legend ()
(vl-load-com) 
	(setq temperr *error*)				;store *error*
	(setq *error* trap1)				;re-assign *error*
	
(setq oldhigh (getvar "Highlight")
      oldsnap (getvar "Osmode")
      oldecho (getvar "Cmdecho")
      oldtext (getvar "Textstyle")
      oldlay  (getvar "clayer")
); gets variables to reset at the end of the routine
;;-------------------------------------------------------------------------------------------------
(c:pointSelection); select cogo pointstyle names, defun at end of file
;;-------------------------------------------------------------------------------------------------
(setvar "osmode" 0) ;turns off all snap in osnap
(setvar "clayer" "LEGEND")
(setvar "textstyle" "S80");
(setq lf 1)
(setq curh (cdr (assoc 40 (tblsearch "STYLE" (getvar "textstyle")))))
(setvar "cmdecho" 1)
;;-------------------------------------------------------------------------------------------------
(setq bbp (getpoint "\nPick start of legend: "))
(setq lfile (open "P:\\Lisp\\LEGEND.TXT" "r"))
(setq bllist nil)
(while 
	(setq blockn (read-line lfile))
	(setq blockd (read-line lfile))
	(setq bllist (cons (list blockn blockd) bllist))
)
(close lfile)
(setq lfile (open "P:\\Lisp\\LEGEND.TXT" "a"))
(setq 
	n (sslengtth styleList)
	cnt 1
	index 0)
(repeat n
   (setq bname (nth index styleList))
		(setq bdesc (cadr (assoc bname bllist)))
   (command-s "insert" bname
             (setq cbp (polar bbp (/ (* 270 PI) 180) (* cnt (/ lf 3))))
             lf
             ""
             0.0
   )
   (if (= curh 0.0)
    (command-s "TEXT" "j" "ml"
             (polar cbp 0 (/ lf 1.6))
             (* lf 0.08)
             0.0
             (STRCAT "= " BDESC)
    )
    (command-s "TEXT" "j" "ml"
             (polar cbp 0 (/ lf 1.6))
             0.0
             (STRCAT "= " BDESC)
    )
   )
	(setq cnt (1+ cnt)
		index (1+ index))
);end repeat
;;-------------------------------------------------------------------------------------------------
;;end of routine
	(close lfile)
	(setvar "Highlight" oldhigh)
	(setvar "Osmode" oldsnap)
	(setvar "Cmdecho" oldecho)
	(setvar "textstyle" oldtext)
	(setvar "clayer" oldlay); returns vars to orignal state before lisp
	(princ)
) ;end defun Legend
	(setq *error* temperr)				;restore *error*
	
	(defun trap1 (errmsg)					;define function
	;(command-s "u" "b")				;undo back
	(setvar "osmode" oldsnap)			;restore variables
	(setvar "highlight" oldhigh)
	(setvar "cmdecho" oldecho)
	(setvar "textstyle" oldtext)
	(setvar "clayer" oldlay)
	(setq *error* temperr)				;restore *error*
	(prompt "\nRe-Setting System Variables " temperr)	;inform user
)

(defun c:pointselection (/ pntSel index pntStyle pntName styleList)
(vl-load-com) 
  (if (setq pntSel (ssget "X" '((0 . "AECC_COGO_POINT"))))
    (progn
      (repeat (setq index (sslength pntSel))
        (and (setq pntStyle (vlax-get (vlax-ename->vla-object (ssname pntSel (setq index (1- index)))) 'style))
             (setq pntName (vlax-get-property pntStyle 'name))
             (or (member pntName styleList)
                 (setq styleList (cons pntName styleList))
                 )
             )
        )
      )
    )(princ)
  )
0 Likes
Accepted solutions (1)
1,905 Views
11 Replies
Replies (11)
Message 2 of 12

Ranjit_Singh
Advisor
Advisor

prompt just takes one argument. You have an error in your *error*  function. It's a good habit to leave out the error function in development stages.

(prompt "\nRe-Setting System Variables " temperr); temperr is the extra argument

Did the routine work before adding the error function?

 

Message 3 of 12

ВeekeeCZ
Consultant
Consultant
a typo, sslengtth
Message 4 of 12

Anonymous
Not applicable

The routine worked before I modified it. Thanks for catching that.

0 Likes
Message 5 of 12

Anonymous
Not applicable

Thanks for catching that typo.

 

the lisp is still not performing, it errors out without message.

0 Likes
Message 6 of 12

Anonymous
Not applicable

I took out the error handling as suggested and got this error message

 

Command: LEGEND
Pick start of legend: ; error: bad argument type: lselsetp nil

0 Likes
Message 7 of 12

ВeekeeCZ
Consultant
Consultant

Unless you post something to test it on, I'm out.
dwg, txt, block.
And the original lisp may help as well.

0 Likes
Message 8 of 12

hmsilva
Mentor
Mentor
Accepted solution

@Anonymous wrote:

I took out the error handling as suggested and got this error message

 

Command: LEGEND
Pick start of legend: ; error: bad argument type: lselsetp nil


Change

(sslength styleList)

to

(length styleList)

 

Hope this helps,
Henrique

EESignature

Message 9 of 12

ВeekeeCZ
Consultant
Consultant

@hmsilva wrote:
Change

(sslength styleList)

to

(length styleList)

 

Hope this helps,
Henrique


Hi Henrique, glad you came by and dropped something smart here! Merry Christmas to you and for the new year I hope that you do this little more often than this year, despite the fact that is harder not to. Cheers!

0 Likes
Message 10 of 12

Anonymous
Not applicable

@hmsilva wrote:

@Anonymous wrote:

I took out the error handling as suggested and got this error message

 

Command: LEGEND
Pick start of legend: ; error: bad argument type: lselsetp nil


Change

(sslength styleList)

to

(length styleList)

 

Hope this helps,
Henrique


Thank you, this solved the problem of the lisp not running. I really appreciate the help here.

0 Likes
Message 11 of 12

hmsilva
Mentor
Mentor

@ВeekeeCZ wrote:
...

Hi Henrique, glad you came by and dropped something smart here! Merry Christmas to you and for the new year I hope that you do this little more often than this year, despite the fact that is harder not to. Cheers!


Hello Beekee!

 

It has been a busy year and no spare time....
But I have given some help at the Português forums.

 

Merry Christmas to you too.

 

Cheers
Henrique

 

EESignature

0 Likes
Message 12 of 12

hmsilva
Mentor
Mentor

@Anonymous wrote:
...

Thank you, this solved the problem of the lisp not running. I really appreciate the help here.


You're welcome, aftermethod!
Glad I could help

Henrique

EESignature