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
(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
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.
Thanks Scot-65 for the pointers,
Im still getting an error
"; error: malformed list on input"
not sure where i have it wrong.
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) )
(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.
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
@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!!!
@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
@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]
Happy to 'see' you my friend! 🙂
Cheers
Henrique
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.
@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
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!!!
@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
Can't find what you're looking for? Ask the community or share your knowledge.