MarcoW Posted June 4, 2009 Share Posted June 4, 2009 I wanted to make a routine that: 1. checks if a linetype is loaded, if not then it should load it, if yes, then okay 2. checks if a layer exists, if not create it (with a specific colour and linetype), if yes, set it current. This is my code: (defun c:test ( / ltname layname laycol cmdold) ; functie definitie (setq ltname "center" ; defines linetypename layname "test" ; defines layername laycol 8 ; defines layer color cmdold (getvar "cmdecho") ) ; end setq (setvar "cmdecho" 0 ; no following by F2 ) ; end setvar (if (= (tblsearch "ltype" ltname) nil) (command "linetype" "l" ltname "acad.lin" "") ) (if (= (tblsearch "layer" layname)) (command "layer" "s" layname "") (command "layer" "m" layname "l" ltname "" "c" laycol "" "") ) (setvar "cmdecho" cmdold); cmdecho back to what it was (princ); Exit cleanly ); end of defun The problem is when the layer exists, it doesn't set it to current... I'm only 1 inch away from the solution I believe.... but I can't manage to do it. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 4, 2009 Share Posted June 4, 2009 I have provided a VL option if you wanted to go down that route also: [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:test [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] ltname layname laycol cmdold lay[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ltname [b][color=#ff00ff]"center"[/color][/b] layname [b][color=#ff00ff]"test"[/color][/b] laycol [b][color=#009900]8[/color][/b] cmdold [b][color=RED]([/color][/b][b][color=BLUE]getvar[/color][/b] [b][color=#ff00ff]"CMDECHO"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setvar[/color][/b] [b][color=#ff00ff]"CMDECHO"[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; Loading Linetype ~ Another option to consider:[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]tblsearch[/color][/b] [b][color=#ff00ff]"LTYPE"[/color][/b] ltname[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-load[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-Linetypes[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-ActiveDocument[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-acad-object[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] ltname [b][color=#ff00ff]"acad.lin"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; Layer Checking & Creation[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]tblsearch[/color][/b] [b][color=#ff00ff]"LAYER"[/color][/b] layname[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]command[/color][/b] [b][color=#ff00ff]"_.-layer"[/color][/b] [b][color=#ff00ff]"_M"[/color][/b] layname [b][color=#ff00ff]"_L"[/color][/b] ltname layname [b][color=#ff00ff]"_C"[/color][/b] laycol layname [b][color=#ff00ff]""[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setvar[/color][/b] [b][color=#ff00ff]"CLAYER"[/color][/b] layname[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; Another Option for Layer Creation to Consider:[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]tblsearch[/color][/b] [b][color=#ff00ff]"LAYER"[/color][/b] layname[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] lay [b][color=RED]([/color][/b][b][color=BLUE]vla-add[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-layers[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-ActiveDocument[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-acad-object[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] layname[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-put-color[/color][/b] lay laycol[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-put-linetype[/color][/b] lay ltname[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setvar[/color][/b] [b][color=#ff00ff]"CLAYER"[/color][/b] layname[b][color=RED])[/color][/b] [i][color=#990099];; Reset CMDECHO[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]setvar[/color][/b] [b][color=#ff00ff]"CMDECHO"[/color][/b] cmdold[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] Quote Link to comment Share on other sites More sharing options...
MarcoW Posted June 4, 2009 Author Share Posted June 4, 2009 Lee, It works properly allthough i don't get the code. It's too much to get in to that, so let's leave that part for what it is. This example (test.lsp) is for 1 layer, 1 linetype an 1 colour. I wonder if it can be made for multiple layers. Not in the way I do it now, thats wrong, defnitly! I copy the code 10 times and change c:test into c:test1 c:test2 etc. Then per function I modifiy the names. I wouldn't know how to do it else for test1 calls a specific layer. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 4, 2009 Share Posted June 4, 2009 The code is not that complicated to explain - I could try to answer any questions you may have about it. As for multiple layers, colours etc - Make the layer function into a sub-function, and call it with multiple arguments: (defun mklay (layname laycol ltname / lay) (vl-load-com) ;; Loading Linetype ~ Another option to consider: (if (not (tblsearch "LTYPE" ltname)) (vla-load (vla-get-Linetypes (vla-get-ActiveDocument (vlax-get-acad-object))) ltname "acad.lin")) ;; Another Option for Layer Creation to Consider: (if (not (tblsearch "LAYER" layname)) (progn (setq lay (vla-add (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object))) layname)) (vla-put-color lay laycol) (vla-put-linetype lay ltname))) (setvar "CLAYER" layname)) (defun c:test () (mapcar 'mklay '("test1" "test2" "test3") '(8 3 4) '("CENTER" "HIDDEN" "CONTINUOUS")) (princ)) This will make three layers: test1 -- colour 8 -- CENTER test2 -- colour 3 -- HIDDEN test3 -- colour 4 -- CONTINUOUS Hope this helps, Lee Quote Link to comment Share on other sites More sharing options...
TimSpangler Posted June 4, 2009 Share Posted June 4, 2009 Here is a Linetype loading sub that I use all the time, along with a helper sub. Just pass it a linetype name and it will search every .lin files in your search path and if it finds it, it gets loaded. The only thing that I want to do to it, is if a path is supplied than it loads the linetype directly. STDLIB_LOAD_LINETYPE.lsp STDLIB_FUNCTIONS.lsp Quote Link to comment Share on other sites More sharing options...
bradb Posted June 4, 2009 Share Posted June 4, 2009 Heres one that I use it purges all unused layers then create the 10 layers I use. You can modify the layer names to your liking and at the end of the dolayers command you can modify to set layer current. (setvar "clayer" "insert layer name here") I know its rokkie programing but it works for me. I use it to make sure all our drawing have the same layers since I'm the 4th draftsman here we have a lot of different drawings. Oh and thanks Lee Mac I saw something like this in one of his commands so I just made some mod's to it. (defun createlayer (NAME) (if (not (tblsearch "LAYER" NAME)) (command "-layer" "m" "CEN" "C" "6" "CEN" "L" "CENTER" "CEN" "LW" "0.18" "CEN" "") ) (if (not (tblsearch "LAYER" NAME)) (command "-layer" "m" "DIMS" "C" "1" "DIMS" "LW" "0.18" "DIMS" "") ) (if (not (tblsearch "LAYER" NAME)) (command "-layer" "m" "HAT" "C" "3" "HAT" "LW" "0.18" "HAT" "") ) (if (not (tblsearch "LAYER" NAME)) (command "-layer" "m" "HID" "C" "4" "HID" "L" "HIDDEN" "HID" "LW" "0.15" "HID" "") ) (if (not (tblsearch "LAYER" NAME)) (command "-layer" "m" "LOGO" "C" "176" "LOGO" "LW" "0.09" "" "") ) (if (not (tblsearch "LAYER" NAME)) (command "-layer" "m" "OBJ" "C" "2" "OBJ" "LW" "0.40" "OBJ" "") ) (if (not (tblsearch "LAYER" NAME)) (command "-layer" "m" "PAPER" "C" "5" "PAPER" "L" "PHANTOM" "PAPER" "P" "N" "PAPER" "") ) (if (not (tblsearch "LAYER" NAME)) (command "-layer" "m" "PHAN" "C" "6" "PHAN" "L" "PHANTOM" "PHAN" "LW" "0.18" "PHAN" "") ) (if (not (tblsearch "LAYER" NAME)) (command "-layer" "m" "TITLE" "C" "176" "TITLE" "") ) (if (not (tblsearch "LAYER" NAME)) (command "-layer" "m" "TXT" "C" "7" "" "") ) ) (defun c:dolayers () (setvar "cmdecho" 0) (purgelayers) (mapcar 'createlayer '("CEN" "DIMS" "HAT" "HID" "LOGO" "OBJ" "PAPER" "PHAN" "TITLE" "TXT")) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 4, 2009 Share Posted June 4, 2009 Heres one that I use it purges all unused layers then create the 10 layers I use. You can modify the layer names to your liking and at the end of the dolayers command you can modify to set layer current. (setvar "clayer" "insert layer name here") I know its rokkie programing but it works for me. I use it to make sure all our drawing have the same layers since I'm the 4th draftsman here we have a lot of different drawings. Oh and thanks Lee Mac I saw something like this in one of his commands so I just made some mod's to it. (defun createlayer (NAME) (if (not (tblsearch "LAYER" NAME)) (command "-layer" "m" "CEN" "C" "6" "CEN" "L" "CENTER" "CEN" "LW" "0.18" "CEN" "") ) (if (not (tblsearch "LAYER" NAME)) (command "-layer" "m" "DIMS" "C" "1" "DIMS" "LW" "0.18" "DIMS" "") ) (if (not (tblsearch "LAYER" NAME)) (command "-layer" "m" "HAT" "C" "3" "HAT" "LW" "0.18" "HAT" "") ) (if (not (tblsearch "LAYER" NAME)) (command "-layer" "m" "HID" "C" "4" "HID" "L" "HIDDEN" "HID" "LW" "0.15" "HID" "") ) (if (not (tblsearch "LAYER" NAME)) (command "-layer" "m" "LOGO" "C" "176" "LOGO" "LW" "0.09" "" "") ) (if (not (tblsearch "LAYER" NAME)) (command "-layer" "m" "OBJ" "C" "2" "OBJ" "LW" "0.40" "OBJ" "") ) (if (not (tblsearch "LAYER" NAME)) (command "-layer" "m" "PAPER" "C" "5" "PAPER" "L" "PHANTOM" "PAPER" "P" "N" "PAPER" "") ) (if (not (tblsearch "LAYER" NAME)) (command "-layer" "m" "PHAN" "C" "6" "PHAN" "L" "PHANTOM" "PHAN" "LW" "0.18" "PHAN" "") ) (if (not (tblsearch "LAYER" NAME)) (command "-layer" "m" "TITLE" "C" "176" "TITLE" "") ) (if (not (tblsearch "LAYER" NAME)) (command "-layer" "m" "TXT" "C" "7" "" "") ) ) (defun c:dolayers () (setvar "cmdecho" 0) (purgelayers) (mapcar 'createlayer '("CEN" "DIMS" "HAT" "HID" "LOGO" "OBJ" "PAPER" "PHAN" "TITLE" "TXT")) ) Bradb, the way you have called the sub-function, each statement is independent of the argument supplied. I.e. Every IF statement will return T for every single layer that doesnt exist. Quote Link to comment Share on other sites More sharing options...
bradb Posted June 4, 2009 Share Posted June 4, 2009 Bradb, the way you have called the sub-function, each statement is independent of the argument supplied. I.e. Every IF statement will return T for every single layer that doesnt exist. Ah is that because I purged all layers away prior to create layer. I originally wanted it to search for layers then rename them. Ex. search for OBJECT and OBJ. And OBJECT rename to OBJ. And if OBJ then nothing will happen, But if neither exist then create OBJ. Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted June 4, 2009 Share Posted June 4, 2009 You should do just one tablesearch with an argument and use conditionals to make the layers. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 4, 2009 Share Posted June 4, 2009 No, it is because you are supplying every IF statement with the same argument. This is much better (and much faster): [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] MkLay [b][color=RED]([/color][/b]Nme Col lTyp lWgt Plt [b][color=BLUE]/[/color][/b] lay[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] lay [b][color=RED]([/color][/b][b][color=BLUE]vla-add[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-layers[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-ActiveDocument[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-acad-object[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] Nme[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] Col [b][color=RED]([/color][/b][b][color=BLUE]vla-put-Color[/color][/b] lay Col[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] lTyp [b][color=RED]([/color][/b][b][color=BLUE]vla-put-Linetype[/color][/b] lay lTyp[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] lWgt [b][color=RED]([/color][/b][b][color=BLUE]vla-put-LineWeight[/color][/b] lay lWgt[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] Plt[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-put-Plottable[/color][/b] lay [b][color=Blue]:vlax-false[/color][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:DoLayers [b][color=RED]([/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]purgelayers[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b]MkLay [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b] [b][color=#ff00ff]"CEN"[/color][/b] [b][color=#ff00ff]"DIMS"[/color][/b] [b][color=#ff00ff]"HAT"[/color][/b] [b][color=#ff00ff]"HID"[/color][/b] [b][color=#ff00ff]"LOGO"[/color][/b] [b][color=#ff00ff]"OBJ"[/color][/b] [b][color=#ff00ff]"PAPER"[/color][/b] [b][color=#ff00ff]"PHAN"[/color][/b] [b][color=#ff00ff]"TITLE"[/color][/b] [b][color=#ff00ff]"TXT"[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; Name[/color][/i] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b] [b][color=#009900]6[/color][/b] [b][color=#009900]1[/color][/b] [b][color=#009900]3[/color][/b] [b][color=#009900]4[/color][/b] [b][color=#009900]176[/color][/b] [b][color=#009900]2[/color][/b] [b][color=#009900]5[/color][/b] [b][color=#009900]6[/color][/b] [b][color=#009900]176[/color][/b] [b][color=#009900]7[/color][/b] [b][color=RED])[/color][/b] [i][color=#990099]; Colours[/color][/i] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#ff00ff]"CENTER"[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=#ff00ff]"HIDDEN"[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=#ff00ff]"PHANTOM"[/color][/b] [b][color=#ff00ff]"PHANTOM"[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=RED])[/color][/b] [i][color=#990099]; LineType[/color][/i] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b] [b][color=#009999]0.18[/color][/b] [b][color=#009999]0.18[/color][/b] [b][color=#009999]0.18[/color][/b] [b][color=#009999]0.15[/color][/b] [b][color=#009999]0.09[/color][/b] [b][color=#009999]0.40[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=#009999]0.18[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=RED])[/color][/b] [i][color=#990099]; LineWeight[/color][/i] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; Plottable (T or nil)[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] I'm not sure what your "purgelayers" function does, but maybe I could improve that also Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 4, 2009 Share Posted June 4, 2009 Oh, and remember that the above posted code does not check for whether the Linetype is loaded. Something to bear in mind. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 4, 2009 Share Posted June 4, 2009 This will load linetypes that aren't loaded [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] MkLay [b][color=RED]([/color][/b]Nme Col lTyp lWgt Plt [b][color=BLUE]/[/color][/b] lay[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] lay [b][color=RED]([/color][/b][b][color=BLUE]vla-add[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-layers[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-ActiveDocument[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-acad-object[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] Nme[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] Col [b][color=RED]([/color][/b][b][color=BLUE]vla-put-Color[/color][/b] lay Col[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] lTyp [b][color=RED]([/color][/b]lTload lTyp[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-put-Linetype[/color][/b] lay lTyp[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] lWgt [b][color=RED]([/color][/b][b][color=BLUE]vla-put-LineWeight[/color][/b] lay lWgt[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] Plt[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-put-Plottable[/color][/b] lay :vlax-false[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] lTload [b][color=RED]([/color][/b]lTyp[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]or[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]tblsearch[/color][/b] [b][color=#ff00ff]"LTYPE"[/color][/b] lTyp[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-load[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-Linetypes[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-ActiveDocument[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-acad-object[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] lTyp [b][color=#ff00ff]"acad.lin"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:DoLayers [b][color=RED]([/color][/b][b][color=RED])[/color][/b] [b][color=#990099][color=Red]([/color][/color][/b][color=#990099][color=black]purgelayers[/color][/color][b][color=#990099][color=Red])[/color][/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b]MkLay [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b] [b][color=#ff00ff]"CEN"[/color][/b] [b][color=#ff00ff]"DIMS"[/color][/b] [b][color=#ff00ff]"HAT"[/color][/b] [b][color=#ff00ff]"HID"[/color][/b] [b][color=#ff00ff]"LOGO"[/color][/b] [b][color=#ff00ff]"OBJ"[/color][/b] [b][color=#ff00ff]"PAPER"[/color][/b] [b][color=#ff00ff]"PHAN"[/color][/b] [b][color=#ff00ff]"TITLE"[/color][/b] [b][color=#ff00ff]"TXT"[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; Name[/color][/i] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b] [b][color=#009900]6[/color][/b] [b][color=#009900]1[/color][/b] [b][color=#009900]3[/color][/b] [b][color=#009900]4[/color][/b] [b][color=#009900]176[/color][/b] [b][color=#009900]2[/color][/b] [b][color=#009900]5[/color][/b] [b][color=#009900]6[/color][/b] [b][color=#009900]176[/color][/b] [b][color=#009900]7[/color][/b] [b][color=RED])[/color][/b] [i][color=#990099]; Colours[/color][/i] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#ff00ff]"CENTER"[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=#ff00ff]"HIDDEN"[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=#ff00ff]"PHANTOM"[/color][/b] [b][color=#ff00ff]"PHANTOM"[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=RED])[/color][/b] [i][color=#990099]; LineType[/color][/i] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b] [b][color=#009999]0.18[/color][/b] [b][color=#009999]0.18[/color][/b] [b][color=#009999]0.18[/color][/b] [b][color=#009999]0.15[/color][/b] [b][color=#009999]0.09[/color][/b] [b][color=#009999]0.40[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=#009999]0.18[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=RED])[/color][/b] [i][color=#990099]; LineWeight[/color][/i] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; Plottable (T or nil)[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] Quote Link to comment Share on other sites More sharing options...
bradb Posted June 4, 2009 Share Posted June 4, 2009 (defun purgelayers () (command "-purge" "LA" "" "N") ) This is the purgelayers did realize I didn't copy it before. Basicly I want to purge all layers that are not the layer names supplied in the lisp Quote Link to comment Share on other sites More sharing options...
bradb Posted June 4, 2009 Share Posted June 4, 2009 Lee ran yours the only thing it is not picking up the lineweights. All layer settings are set execpt the linewieght set a 0.00 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 4, 2009 Share Posted June 4, 2009 Lee ran yours the only thing it is not picking up the lineweights. All layer settings are set execpt the linewieght set a 0.00 Will check it - Did you notice the speed difference however? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 4, 2009 Share Posted June 4, 2009 OK, this should work: [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] MkLay [b][color=RED]([/color][/b]Nme Col lTyp lWgt Plt [b][color=BLUE]/[/color][/b] lay[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] lay [b][color=RED]([/color][/b][b][color=BLUE]vla-add[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-layers[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-ActiveDocument[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-acad-object[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] Nme[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] Col [b][color=RED]([/color][/b][b][color=BLUE]vla-put-Color[/color][/b] lay Col[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] lTyp [b][color=RED]([/color][/b]lTload lTyp[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-put-Linetype[/color][/b] lay lTyp[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] lWgt [b][color=RED]([/color][/b][b][color=BLUE]vla-put-LineWeight[/color][/b] lay [b][color=RED]([/color][/b][b][color=BLUE]eval[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]read[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#ff00ff]"acLnWt"[/color][/b] lWgt[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] Plt[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-put-Plottable[/color][/b] lay :vlax-false[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] lTload [b][color=RED]([/color][/b]lTyp[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]or[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]tblsearch[/color][/b] [b][color=#ff00ff]"LTYPE"[/color][/b] lTyp[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-load[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-Linetypes[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-ActiveDocument[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-acad-object[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] lTyp [b][color=#ff00ff]"acad.lin"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=BLUE]t[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:DoLayers [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] cm[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] cm [b][color=RED]([/color][/b][b][color=BLUE]getvar[/color][/b] [b][color=#ff00ff]"CMDECHO"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setvar[/color][/b] [b][color=#ff00ff]"CMDECHO"[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-cmdf[/color][/b] [b][color=#ff00ff]"_.-purge"[/color][/b] [b][color=#ff00ff]"_LA"[/color][/b] [b][color=#ff00ff]"*"[/color][/b] [b][color=#ff00ff]"_N"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b]MkLay [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b] [b][color=#ff00ff]"CEN"[/color][/b] [b][color=#ff00ff]"DIMS"[/color][/b] [b][color=#ff00ff]"HAT"[/color][/b] [b][color=#ff00ff]"HID"[/color][/b] [b][color=#ff00ff]"LOGO"[/color][/b] [b][color=#ff00ff]"OBJ"[/color][/b] [b][color=#ff00ff]"PAPER"[/color][/b] [b][color=#ff00ff]"PHAN"[/color][/b] [b][color=#ff00ff]"TITLE"[/color][/b] [b][color=#ff00ff]"TXT"[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; Name [str][/color][/i] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b] [b][color=#009900]6[/color][/b] [b][color=#009900]1[/color][/b] [b][color=#009900]3[/color][/b] [b][color=#009900]4[/color][/b] [b][color=#009900]176[/color][/b] [b][color=#009900]2[/color][/b] [b][color=#009900]5[/color][/b] [b][color=#009900]6[/color][/b] [b][color=#009900]176[/color][/b] [b][color=#009900]7[/color][/b] [b][color=RED])[/color][/b] [i][color=#990099]; Colours [int][/color][/i] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#ff00ff]"CENTER"[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=#ff00ff]"HIDDEN"[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=#ff00ff]"PHANTOM"[/color][/b] [b][color=#ff00ff]"PHANTOM"[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=RED])[/color][/b] [i][color=#990099]; LineType [str][/color][/i] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b] [b][color=#ff00ff]"018"[/color][/b] [b][color=#ff00ff]"018"[/color][/b] [b][color=#ff00ff]"018"[/color][/b] [b][color=#ff00ff]"015"[/color][/b] [b][color=#ff00ff]"009"[/color][/b] [b][color=#ff00ff]"040"[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=#ff00ff]"018"[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=RED])[/color][/b] [i][color=#990099]; LineWeight [str] 0.18 = "018"[/color][/i] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]nil[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=BLUE]T[/color][/b] [b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; Plottable (T or nil)[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]setvar[/color][/b] [b][color=#ff00ff]"CMDECHO"[/color][/b] cm[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] Quote Link to comment Share on other sites More sharing options...
MarcoW Posted June 5, 2009 Author Share Posted June 5, 2009 Lee, this is the solution in my case. I want to create a specific layer when inserting specific blocks, ie. inserting a block called "box" in a layer "boxes", linetype center, layer set to non plot, I use a macro inside menu: ^C^Ccreatelayer;Center;m_boxes;3;n; This is the lisp that starts up when a drawing is opened: (defun c:createlayer (/ ltname layname laycol cmdold lay) (vl-load-com) (setq ltname (getstring "\nPlease enter the name of the linetype: ") layname (getstring "\nPlease enter the name of the layer: ") laycol (getint "\nPlease enter the colour of the layer: ") layplot (getstring "\nDo you want the layer to be <Plot> or <Non plot>: ") cmdold (getvar "CMDECHO")) (setvar "CMDECHO" 0) ;; Loading Linetype ~ Another option to consider: (if (not (tblsearch "LTYPE" ltname)) (vla-load (vla-get-Linetypes (vla-get-ActiveDocument (vlax-get-acad-object))) ltname "acad.lin")) ;; Layer Checking & Creation (if (not (tblsearch "LAYER" layname)) (command "_.-layer" "_M" layname "_L" ltname layname "_C" laycol layname "_P" layplot "" "") (setvar "CLAYER" layname)) ;; Another Option for Layer Creation to Consider: (if (not (tblsearch "LAYER" layname)) (progn (setq lay (vla-add (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object))) layname)) (vla-put-color lay laycol) (vla-put-linetype lay ltname))) (setvar "CLAYER" layname) ;; Reset CMDECHO (setvar "CMDECHO" cmdold) (princ)) So now I specify the layer in a macro, that gives me much flexibility for whenever there is a new kind of block to insert, I createlayer... But all credits to yuo lee, without your help I wouldn't be able to do so. Quote Link to comment Share on other sites More sharing options...
bradb Posted June 5, 2009 Share Posted June 5, 2009 Will check it - Did you notice the speed difference however? yeah Lee alot faster thanks Oh and what is the vl-load-com and the vla's you are using? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 5, 2009 Share Posted June 5, 2009 Oh and what is the vl-load-com and the vla's you are using? They are Visual LISP methods - AfraLISP has a lot of information on them Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 5, 2009 Share Posted June 5, 2009 (defun c:createlayer (/ ltname layname laycol cmdold lay) (vl-load-com) (setq ltname (getstring "\nPlease enter the name of the linetype: ") layname (getstring "\nPlease enter the name of the layer: ") laycol (getint "\nPlease enter the colour of the layer: ") layplot (getstring "\nDo you want the layer to be <Plot> or <Non plot>: ") cmdold (getvar "CMDECHO")) (setvar "CMDECHO" 0) ;; Loading Linetype ~ Another option to consider: (if (not (tblsearch "LTYPE" ltname)) (vla-load (vla-get-Linetypes (vla-get-ActiveDocument (vlax-get-acad-object))) ltname "acad.lin")) [color=Blue] [b] ;; Layer Checking & Creation (if (not (tblsearch "LAYER" layname)) (command "_.-layer" "_M" layname "_L" ltname layname "_C" laycol layname "_P" layplot "" "")[/b][/color] (setvar "CLAYER" layname)) ;[color=Red][b]; Another Option for Layer Creation to Consider: (if (not (tblsearch "LAYER" layname)) (progn (setq lay (vla-add (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object))) layname)) (vla-put-color lay laycol) (vla-put-linetype lay ltname)))[/b][/color] (setvar "CLAYER" layname) ;; Reset CMDECHO (setvar "CMDECHO" cmdold) (princ)) So now I specify the layer in a macro, that gives me much flexibility for whenever there is a new kind of block to insert, I createlayer... But all credits to yuo lee, without your help I wouldn't be able to do so. Thanks Marco, But bear in mind that with your code, you have got two sections that do the same thing. - You might want to consider removing one. 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.