Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error in my code

17 REPLIES 17
SOLVED
Reply
Message 1 of 18
Anonymous
1265 Views, 17 Replies

Error in my code

Hello, 

 

Can anybody help me debug this code i wrote. Also is there a program I can use to debug my lisp? 

 

I'm a Newbie Man Happy

 

(defun c:demo (/ ent flag hnd i lst ss)
   (if (setq ss (ssget "_X" (list '(0 . "INSERT") '(66 . 1))))
      (repeat (setq i (sslength ss))
         (setq hnd (ssname ss (setq i (1- i))))
         (while (and
                   (setq hnd (entnext hnd))
                   (setq ent (entget hnd))
                   (= (cdr (assoc 0 ent)) "ATTRIB")
                )
            (if (wcmatch (strcase (cdr (assoc 2 ent))) "REV,REV*")
               (setq flag1 T)
            )
         )
      )
)
	(setvar "tilemode" 1) 
	(setq dr (getvar "dwgname"))
	(setq a (getvar "EXTMAX"))
	(setq pt1 (caddr a))
		(if 
			((= pt1 0) (command "_saveas" "2010" (strcat "H:\\2D\\" dr))
		)
		 (cond 
			((> pt1 0) (setq lay1 (tblsearch "LAYER" "system"))
		      
		       	;((= lay1 flag1) (command "_saveas" "2010" (strcat "H:\\3D\\Cadworx-Titleblock\\" dr)))
		       
			(lay1 (command "_saveas" "2010" (strcat "H:\\3D\\Cadworx\\" dr)))
		       	
			((/= lay1 T) (command "_saveas" "2010" (strcat "H:\\3D\\Misc\\" dr)))
		)
	(princ)
)

Thanks for the pointers.

 

LG

17 REPLIES 17
Message 2 of 18
scot-65
in reply to: Anonymous

(if
((= pt1 0)
extra left parenthesis.

lay1is not defined before entering the COND.
Even if you define inside the COND, that line is evaluated and then
the flow skips past the rest of the cond's - meaning if the test fails,
lay1 will not be defined for successive tests.

Also, what happens if ss is nil?
Expressions past the line "setvar tilemode 1" are still evaluated, which
should not (flag1 is not set when ss is nil).

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 3 of 18
Anonymous
in reply to: scot-65

Thanks Scot-65 for the pointers,

 

Im still getting an error

 

"; error: malformed list on input"

 

not sure where i have it wrong.

 

 

Message 4 of 18
Satoews
in reply to: Anonymous

Been playing around with this one even though its a bit out of my skill level, lets try this on for size.

 

(defun c:demo (/ ent flag hnd i lst ss)
  (setvar "tilemode" 1) 
  (setq dr (getvar "dwgname"))
  (setq a (getvar "extmax"))
  (setq pt1 (caddr a))
  (setq flag1 nil)
  (setq lay1 nil)
  (if(> pt1 0) 
    (setq lay1 (tblsearch "layer" "system")))	
      (if (setq ss (ssget "_x" (list '(0 . "insert") '(66 . 1))))
        (repeat (setq i (sslength ss))
           (setq hnd (ssname ss (setq i (1- i))))
             (while (and
                   (setq hnd (entnext hnd))
                   (setq ent (entget hnd))
                   (= (cdr (assoc 0 ent)) "attrib")
                    )
               (if (wcmatch (strcase (cdr (assoc 2 ent))) "rev,rev*")
                 (setq flag1 t)
			  
               )
             )
        )
       )
        (cond 
		    
			((= pt1 nil) (command "_saveas" "2010" (strcat "h:\\2d\\" dr)))
		      
		    ((and(=/ lay1 nil) (= flag1 t)) (command "_saveas" "2010" (strcat "h:\\3d\\cadworx-titleblock\\" dr)))
		       
			((=/ lay1 nil)(command "_saveas" "2010" (strcat "h:\\3d\\cadworx\\" dr)))
		       	
			(t (command "_saveas" "2010" (strcat "h:\\3d\\misc\\" dr)))
		 )
	(princ)
)

 

Shawn T
Message 5 of 18
Satoews
in reply to: Satoews

(defun c:demo (/ ent flag hnd i lst ss dr a pt1 lay1)
  (setvar "tilemode" 1) 
  (setq dr (getvar "dwgname"))
  (setq a (getvar "extmax"))
  (setq pt1 (caddr a))
  (setq flag1 0)
  (setq lay1 0)
  (if(> pt1 0) 
    (setq lay1 (tblsearch "layer" "system")))	
      (if (setq ss (ssget "_x" (list '(0 . "insert") '(66 . 1))))
        (repeat (setq i (sslength ss))
           (setq hnd (ssname ss (setq i (1- i))))
             (while (and
                   (setq hnd (entnext hnd))
                   (setq ent (entget hnd))
                   (= (cdr (assoc 0 ent)) "attrib")
                    )
               (if (wcmatch (strcase (cdr (assoc 2 ent))) "rev,rev*")
                 (setq flag1 t)
			  
               )
             )
        )
       )
        (cond 
		    
			((= pt1 nil) (command "_saveas" "2010" (strcat "h:\\2d\\" dr)))
		      
		    ((and(=/ lay1 0) (= flag1 t)) (command "_saveas" "2010" (strcat "h:\\3d\\cadworx-titleblock\\" dr)))
		       
			((=/ lay1 0)(command "_saveas" "2010" (strcat "h:\\3d\\cadworx\\" dr)))
		       	
			(t (command "_saveas" "2010" (strcat "h:\\3d\\misc\\" dr)))
		 )
	(princ)
)

For some reason I can't revise my post, huh. Well I wanted to adjust a couple of things so try this one.

 

 

Shawn T
Message 6 of 18
hmsilva
in reply to: Anonymous

Hi ACER79,
let's see if I understand your goal...

 

Your goal is to save the current dwg in one of four different folders:

 

if not 3d -> "H:\\2D\\"

if 3d, test if there are a 'system' layer,

if exist a 'system' layer, and a titleblock (test attribs 'REV' or 'REV*' -> "H:\\3D\\Cadworx-Titleblock\\"

if exist a 'system' layer, and not a titleblock -> "H:\\3D\\Cadworx\\"

if none of the above tests is true, -> "H:\\3D\\Misc\\"

 

I'm correct?

 

(defun c:demo (/ a dr ent flag hnd i lay1 lst ss)
   (if (setq ss (ssget "_X" (list '(0 . "INSERT") '(66 . 1))))
      (repeat (setq i (sslength ss))
         (setq hnd (ssname ss (setq i (1- i))))
         (while (and
                   (setq hnd (entnext hnd))
                   (setq ent (entget hnd))
                   (= (cdr (assoc 0 ent)) "ATTRIB")
                )
            (if (wcmatch (strcase (cdr (assoc 2 ent))) "REV,REV*")
               (setq flag T)
            )
         )
      )
   )
   (setvar "tilemode" 1)
   (setq dr  (getvar "dwgname")
         a   (getvar "EXTMAX")
         pt1 (caddr a)
   )
   (if (> pt1 0 )
      (setq lay1 (tblsearch "LAYER" "system"))
   )
   (if (equal pt1 0 1e-8)
      (command "_saveas" "2010" (strcat "H:\\2D\\" dr))
      (cond ((and lay1 flag) (command "_saveas" "2010" (strcat "H:\\3D\\Cadworx-Titleblock\\" dr)))
            (lay1 (command "_saveas" "2010" (strcat "H:\\3D\\Cadworx\\" dr)))
            (T (command "_saveas" "2010" (strcat "H:\\3D\\Misc\\" dr)))
      )
   )
   (princ)
)

 

Hope this helps,
Henrique

EESignature

Message 7 of 18
Anonymous
in reply to: hmsilva


@hmsilva wrote:

Hi ACER79,
let's see if I understand your goal...

 

Your goal is to save the current dwg in one of four different folders:

 

if not 3d -> "H:\\2D\\"

if 3d, test if there are a 'system' layer,

if exist a 'system' layer, and a titleblock (test attribs 'REV' or 'REV*' -> "H:\\3D\\Cadworx-Titleblock\\"

if exist a 'system' layer, and not a titleblock -> "H:\\3D\\Cadworx\\"

if none of the above tests is true, -> "H:\\3D\\Misc\\"

 

I'm correct?

 

 

Hope this helps,
Henrique


Yes that is exactly correct!!!
Message 8 of 18
pbejse
in reply to: Anonymous


@Anonymous wrote:

Hello, 

 

......Also is there a program I can use to debug my lisp? 

 

 

 LG


Command prompt : Vlide

 

Menubar: Tools-> Autolisp - > Visual Lisp Editor

 

Ribbons: Manage-> Appication -> Visual Lisp Editor

 

Inside Vlide: Debug -> Break on Error

------>  if error -> Ctrl+F9 [ will highlight where the error is ]

------>  to step out of error -> Ctrl+Q

 

HTH

Message 9 of 18
hmsilva
in reply to: Anonymous


@Anonymous wrote:

@hmsilva wrote:

Hi ACER79,
let's see if I understand your goal...

 

Your goal is to save the current dwg in one of four different folders:

 

if not 3d -> "H:\\2D\\"

if 3d, test if there are a 'system' layer,

if exist a 'system' layer, and a titleblock (test attribs 'REV' or 'REV*' -> "H:\\3D\\Cadworx-Titleblock\\"

if exist a 'system' layer, and not a titleblock -> "H:\\3D\\Cadworx\\"

if none of the above tests is true, -> "H:\\3D\\Misc\\"

 

I'm correct?

 

 

Hope this helps,
Henrique


Yes that is exactly correct!!!

Ok, I did understood your goal...

And the revised code did worked as expected?

 

[Off-Topic]

@pbejse

Happy to 'see' you my friend! 🙂

 

Cheers

Henrique

EESignature

Message 10 of 18
Anonymous
in reply to: hmsilva

I'm testing the code by dragging and dropping into the autocad drawing and this error occurs;

 

"error: malformed list on input"

 

if i load the lsp from appload it says it is loaded successfully but then unknown command when demo is typed.

Message 11 of 18
hmsilva
in reply to: Anonymous


@Anonymous wrote:

I'm testing the code by dragging and dropping into the autocad drawing and this error occurs;

 

"error: malformed list on input"

 

if i load the lsp from appload it says it is loaded successfully but then unknown command when demo is typed.


Try the attached code...

 

Henrique

EESignature

Message 12 of 18
Satoews
in reply to: Anonymous

Copy and paste silvas code above into notepad (not word) and save as with .lsp ext. Then follow below.


http://www.ellenfinkelstein.com/acadblog/how-to-load-an-autolisp-program/
Shawn T
Message 13 of 18
Satoews
in reply to: Anonymous

Malformed list on input :

http://www.cadforum.cz/cadforum_en/qaID.asp?tip=3901
Shawn T
Message 14 of 18
Anonymous
in reply to: hmsilva

Thank you Hmsilva,

 

Your code works great. I added in a line of code to also change ucs to world before checking the coordinates.

 

Could you possibly send me your code with some comments to each line?  I'd like to get a better understanding to the code.

 

Much appreciated.

 

Tornc Thanks for the pointers!!!

 

 

Message 15 of 18
Satoews
in reply to: Anonymous

Glad I could help Smiley Happy

Shawn T
Message 16 of 18
hmsilva
in reply to: Anonymous


@Anonymous wrote:

Thank you Hmsilva, 

Your code works great. I added in a line of code to also change ucs to world before checking the coordinates.

Could you possibly send me your code with some comments to each line?  I'd like to get a better understanding to the code.

...


You're welcome, ACER79!
Glad I could help.

Attached, the code with some comments...

Henrique

EESignature

Message 17 of 18
Anonymous
in reply to: hmsilva

Man what an awesome group of guys here!!!

 

I hope one day i'll be able to return the favor.

 

LG

Message 18 of 18
pbejse
in reply to: hmsilva


@hmsilva wrote:

 

 

 [Off-Topic]

@pbejse

Happy to 'see' you my friend! 🙂

 

Cheers

Henrique


Happy to be seen my friend Smiley Happy

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report