Error in my code

This widget could not be displayed.

Error in my code

Anonymous
Not applicable

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

0 Likes
Reply
Accepted solutions (1)
1,266 Views
17 Replies
Replies (17)

scot-65
Advisor
Advisor
(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.


0 Likes

Anonymous
Not applicable

Thanks Scot-65 for the pointers,

 

Im still getting an error

 

"; error: malformed list on input"

 

not sure where i have it wrong.

 

 

0 Likes

Satoews
Advocate
Advocate

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
0 Likes

Satoews
Advocate
Advocate
(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
0 Likes

hmsilva
Mentor
Mentor

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

0 Likes

Anonymous
Not applicable

@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!!!
0 Likes

pbejse
Mentor
Mentor

@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

hmsilva
Mentor
Mentor

@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

Anonymous
Not applicable

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.

0 Likes

hmsilva
Mentor
Mentor
Accepted solution

@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

Satoews
Advocate
Advocate
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

Satoews
Advocate
Advocate
Malformed list on input :

http://www.cadforum.cz/cadforum_en/qaID.asp?tip=3901
Shawn T
0 Likes

Anonymous
Not applicable

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!!!

 

 

0 Likes

Satoews
Advocate
Advocate

Glad I could help Smiley Happy

Shawn T
0 Likes

hmsilva
Mentor
Mentor

@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

0 Likes

Anonymous
Not applicable

Man what an awesome group of guys here!!!

 

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

 

LG

0 Likes

pbejse
Mentor
Mentor

@hmsilva wrote:

 

 

 [Off-Topic]

@pbejse

Happy to 'see' you my friend! 🙂

 

Cheers

Henrique


Happy to be seen my friend Smiley Happy

0 Likes