bohoon Posted July 28, 2014 Share Posted July 28, 2014 (edited) Hi everyone I am trying to write short lisp to check if layer (specified in a lisp) exists and if so change it's draw order (send it to back or front). I have combined my 2 other lisps which both work just fine and found out that now it doesn't work: "error: bad function: " The code goes like this: (defun C:cdo( ); Correct Draw Order (progn (if (tblsearch "LAYER" "l1");test if layer exists ( (setq la1 (ssget "X" '((8 . "l1")))) (command "draworder" la1 "" "F") );else (command "");do this );end if (princ) ) ) I didn't put anything after "else", however the error appears even when the layer exists. It must be something really simple but I got confused and can't find the error by myself. Can someone point it out for me, please? Edited July 29, 2014 by SLW210 Changed Quote Tags to Code Tags Quote Link to comment Share on other sites More sharing options...
BlackBox Posted July 28, 2014 Share Posted July 28, 2014 (defun c:SendLayerToBack (/ ss) (if (setq ss (ssget "_x" '((8 . "L1")))) (progn (sssetfirst nil ss) (ai_draworder "_b") ) (prompt "\n** Layer not found ** ") ) (princ) ) (defun c:BringLayerToFront (/ ss) (if (setq ss (ssget "_x" '((8 . "L1")))) (progn (sssetfirst nil ss) (ai_draworder "_f") ) (prompt "\n** Layer not found ** ") ) (princ) ) Quote Link to comment Share on other sites More sharing options...
bohoon Posted July 28, 2014 Author Share Posted July 28, 2014 Thank you for quick response. Your code works perfect:) I was just wondering what am I doing wrong? Can you tell me where this error may come from in my code? It is just for my understanding of the lisp. Thanks again Quote Link to comment Share on other sites More sharing options...
BlackBox Posted July 28, 2014 Share Posted July 28, 2014 Thank you for quick response. Your code works perfect:) I was just wondering what am I doing wrong? Can you tell me where this error may come from in my code? It is just for my understanding of the lisp. You're welcome, bohoon; I'm happy to help. By simply checking for a valid selection set, you both verify that the layer exists, and that there are objects on said layer - note that this does not check for locked layers, as is just an example. Once that returns non-Nil, the previously made selection set is selected on screen, as the draw order sub-function (ai_draworder) requires an implicit selection be made first, and then we call the sub-function supplying the necessary 'back' or 'front' parameters to complete the Command. Hope that make (more?) sense now. Cheers Quote Link to comment Share on other sites More sharing options...
bohoon Posted July 28, 2014 Author Share Posted July 28, 2014 OK, So your function ai_draworder requires selection to be made first. However I thought I did the same in this 2 lines: (setq la1 (ssget "X" '((8 . "l1")))) (command "draworder" la1 "" "F") made a selection la1 and then use it in regular draworder command It did work before I added an "if" function : (if (tblsearch "LAYER" "l1");test if layer exists Does it mean that somehow inside "if" it switches the order of my commands? Quote Link to comment Share on other sites More sharing options...
BlackBox Posted July 28, 2014 Share Posted July 28, 2014 OK, So your function ai_draworder requires selection to be made first. It's not my sub-function; it's AutoCAD's and is defined within Acad20##Doc.lsp However I thought I did the same in this 2 lines: (setq la1 (ssget "X" '((8 . "l1")))) (command "draworder" la1 "" "F") made a selection la1 and then use it in regular draworder command It did work before I added an "if" function : (if (tblsearch "LAYER" "l1");test if layer exists Does it mean that somehow inside "if" it switches the order of my commands? No, your call to TBLSEARCH returns non-Nil, so your IF statement's test expression is fine - it is unnecessary given the fact that you want to manipulate entities found on said layer, just call SSGET instead which tests for a valid selection set of entities on said layer (which implicitly exists, if entities are assigned that layer). In a quick test, these also work fine: (defun c:SendLayerToBack2 (/ ss) (if (setq ss (ssget "_x" '((8 . "L1")))) (command "._draworder" ss "" "_b") (prompt "\n** Layer not found ** ") ) (princ) ) (defun c:BringLayerToFront2 (/ ss) (if (setq ss (ssget "_x" '((8 . "L1")))) (command "._draworder" ss "" "_f") (prompt "\n** Layer not found ** ") ) (princ) ) ... The main difference being that my functions supply the "_b" and "_f" localized options, and your original code above does not. In one test adding this localized option does 'fix' your code. HTH Quote Link to comment Share on other sites More sharing options...
bohoon Posted August 1, 2014 Author Share Posted August 1, 2014 Thanks again. I appreciate your help. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 1, 2014 Share Posted August 1, 2014 Thanks again. I appreciate your help. You're welcome. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.