Henryjohn Posted December 20, 2008 Posted December 20, 2008 Sorry if this has been all ready been dealt with but I couldn't find anything when I did a search. Using 2008 and currently getting drawings with all the layers (about 60) having the same pen color, line type and thickness. Therefore all lines are the same. As the all of the drawings I'm getting from this one partiuclur source have the same layers and layer names, I thought there might be a lisp routine that will changed the pen color, line type and thickness to a pre determine value so I can then save the drawing with the new layer values. You can assume that one particluer layer name is "water_tap" so I can see within the routine what's happening and then I can add all the other layer names that need changing in the routine, by copying the relevant code for all other layer names. Hope this makes some sence. Regards Quote
Lee Mac Posted December 20, 2008 Posted December 20, 2008 This may relate slightly to: http://www.cadtutor.net/forum/showthread.php?t=30508 See if that helps slightly. Quote
Lee Mac Posted December 20, 2008 Posted December 20, 2008 I'm sure there's a better way than this, but I was experimenting with mapcar.. ; w ~ layer name ; x ~ layer colour ; y ~ linetype ; z ~ lineweight (0 - 2.11) (defun laychng (w x y z) (if (not (tblsearch "Layer" w)) (progn (setvar "cmdecho" 0) (command "-layer" "m" w "c" x w "lt" y w "lw" z w "") (setvar "cmdecho" 1) ) ;_ end progn (progn (setvar "cmdecho" 0) (command "-layer" "c" x w "lt" y w "lw" z w "") (setvar "cmdecho" 1) ) ;_ end progn ) ;_ end if (princ) ) ;_ end defun (defun c:layerchanger () (mapcar 'laychng '("water_tap" "B-layer" "C-layer" "D-layer" "E-layer") ; w '("1" "2" "3" "4" "5") ; x '("HIDDEN" "HIDDEN" "HIDDEN" "HIDDEN" "HIDDEN") ; y '("0.2" "0.3" "0.8" "1.5" "2.1") ; z ) ;_ end mapcar (princ) ) ;_ end defun Quote
Henryjohn Posted December 21, 2008 Author Posted December 21, 2008 Thanks for getting back to me so quickly. Is there a way of rewriting the code so that each layer has it's own line of code to change the pen color, lineweight and line type so is would be easier to modyify a certain layer (eg layer 34) At the moment if I'm reading it right '("water_tap" "B-layer" "C-layer" "D-layer" "E-layer") ; w '("1" "2" "3" "4" "5") ; x '("HIDDEN" "HIDDEN" "HIDDEN" "HIDDEN" "HIDDEN") ; y '("0.2" "0.3" "0.8" "1.5" "2.1") ; z I would have to count along the line to the 34th position to change a single parameter. Does this mak sense? Regards Henry Quote
Lee Mac Posted December 22, 2008 Posted December 22, 2008 I understand where you are coming from, I realised it wasn't the best way to do it, but as I say, I wanted to try out mapcar Try this ; w ~ layer name ; x ~ colour ; y ~ linetype ; z ~ lineweight (defun c:test (/ *error* varlist oldvars) (defun *error* (msg) (mapcar 'setvar varlist oldvars) (if (= msg "") (princ "\nFunction Complete.") (princ "\nError or Esc Pressed.") ) ;_ end if (princ) ) ;_ end defun (setq varlist (list "CMDECHO" "CLAYER") oldvars (mapcar 'getvar varlist) ) ;_ end setq (setvar "cmdecho" 0) (defun chnglay (w x y z) (if (not (tblsearch "Layer" w)) (command "-layer" "m" w "c" x w "lt" y w "lw" z w "") (command "-layer" "c" x w "lt" y w "lw" z w "") ) ;_ end if (princ) ) ;_ end defun [color=Red][b](chnglay "water_tap" "2" "Hidden" "1.5")[/b][/color] (*error* "") (princ) ) ;_ end defun Add more lines like the highlighted example to change more layers. Quote
Henryjohn Posted December 22, 2008 Author Posted December 22, 2008 Excellent, Excellent, Excellent.....but I have one question/query. As I have about 20 layers starting with the word water (eg water_tap, water_hose, water_conn etc) Does lisp have a wildcard equivalent eg wat* Therefore instead of having 20 lines of text to change 20 layers you could have 1 line of text changing 20 layers As I would have the same properties to all layers that start with water, 1 line of text to change 20 would be ok in this instance. Hope this makes sense Quote
Lee Mac Posted December 23, 2008 Posted December 23, 2008 Try this: ; w ~ layer name ; x ~ colour ; y ~ linetype ; z ~ lineweight (defun c:test (/ *error* varlist oldvars) (defun *error* (msg) (mapcar 'setvar varlist oldvars) (if (= msg "") (princ "\nFunction Complete.") (princ "\nError or Esc Pressed.") ) ;_ end if (princ) ) ;_ end defun (setq varlist (list "CMDECHO" "CLAYER") oldvars (mapcar 'getvar varlist) ) ;_ end setq (setvar "cmdecho" 0) (defun chnglay (w x y z) (if (not (tblsearch "Layer" w)) (command "-layer" "m" w "c" x w "lt" y w "lw" z w "") (command "-layer" "c" x w "lt" y w "lw" z w "") ) ;_ end if (princ) ) ;_ end defun (defun GetLayerList () (vl-load-com) (vlax-for l (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object) ) ;_ end vla-get-ActiveDocument ) ;_ end vla-get-Layers (setq oLst (cons (vla-get-Name l) oLst) ) ; end setq ) ; end vlax-for (reverse oLst) ) ; end of GetLayerList (GetLayerList) (if (= oLst nil) (alert "No Layers Retrieved.") ) ;_ end if [b][color=Red](foreach lay oLst (if (wcmatch lay "wat*") (chnglay lay "2" "Hidden" "1.5") ) ;_ end if ) ;_ end foreach[/color][/b] (*error* "") (princ) ) ;_ end defun Add extra code like that which is highlighted for different wildcard matches. Quote
Henryjohn Posted January 1, 2009 Author Posted January 1, 2009 Thanks Lee Mac.... between your last post and your eariler post I've come up with a macro that does exactly what I want it to do. I can't wait to start getting into lisp a bit more so hopfully I can create my own basic routines. Hope you have a happy new year. I'm posting a new post soon in regards to inserting blocks. Hope you can help out again. Regards HenryJohn Quote
Lee Mac Posted January 2, 2009 Posted January 2, 2009 Your Welcome Henry, Glad you could solve your problem. 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.