clint0577 Posted October 27, 2012 Posted October 27, 2012 I have a routine that I've been using but I would like to modify it just a bit. The function is for creating Deed Sketches that allows the user to create a new layer and select a color. It works great but if you happen to exit the command, and need to start again, it still asks for a new layer. I would like to change the code to have the option to first, USE THE CURRENT LAYER. If not then I would have the option I already have, which is to create the new layer but then I need to, if that layer already exists, set it to current. Here is that portion of the code. I've tried tons of different ways but I know just enough about lisp routines to get myself into trouble. ;main program (DEFUN C:deed () (while (or (not (snvalid (setq name (getstring t "\nSpecify Layer Name: ")))) (tblsearch "LAYER" name) ) (princ "\nLayer Name Invalid or Already Exists.") ) (if (setq color (acad_colordlg 7 nil)) (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 name) (cons 70 0) (cons 62 color) ) ) ) (command "layer" "s" NAME "") Quote
giskumar Posted October 28, 2012 Posted October 28, 2012 Hi, Modify While loop as below. This will checks the layer name for vlididty. It it is a valid layer then checks weather it already exists or Not. If the layer exists sets the layer as current layer. I hopes this works for you. (DEFUN C:deed () (setq newlayer T) (while (not (setq name (getstring t "\nSpecify Layer Name: "))) (if (tblsearch "LAYER" name) (progn (command "Layer" "S" name "") (setq newlayer nil)) (princ "\nLayer Name Invalid.") ) ) (if newlayer (progn (if (setq color (acad_colordlg 7 nil)) (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 name) (cons 70 0) (cons 62 color) ) ) ) (command "layer" "s" NAME "") ) ) ) Quote
Dadgad Posted October 28, 2012 Posted October 28, 2012 (edited) Welcome to the forum. What you are trying to do, while not exactly the same, brings to mind one of my very favorite lisps, which runs nonstop on my machines. That is Lee Mac's LAYER DIRECTOR. Thanks Lee! Everybody should use this lisp, it is simply brilliant, and very easily modified to suit personal needs, even by those who are lisp-challenged, like myself. This is but one of a great many wonderful lisps generously made available on Lee's site. Do yourself a favor, check them out. Edited October 28, 2012 by Dadgad Quote
SLW210 Posted October 29, 2012 Posted October 29, 2012 Welcome to the CADTutor! clint0577, Please read the CODE POSTING GUIDELINES and place your Code in CODE TAGS. Quote
clint0577 Posted October 29, 2012 Author Posted October 29, 2012 (edited) This works Giskumar but if the layer exists, it still promps me for a color. Edited October 29, 2012 by clint0577 Quote
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.