DVDM Posted June 11, 2009 Share Posted June 11, 2009 Hi all, I have made a little routine that will create a set of layers. What I would like to do now though, is to somehow add a loop with a counter so I can go all the way up to 99. I could probably cut and paste my way out of this one instead, but something tells me that's not exactly the smartest way to go about doing this routine. Also, adding a counter will allow me to control the amount of layers I want to create, or even add a prompt asking how many layers I want to create. Can anyone show me how this can be done? Thanks (defun C:TEST () (command "layer" "new" "LAYER-01-PRT,LAYER-02-PRT,LAYER-03-PRT" "color" "4" "LAYER*-PRT" "") (command "layer" "new" "LAYER-01-CEN,LAYER-02-CEN,LAYER-03-CEN" "color" "1" "LAYER*-CEN" "ltype" "CENTER2" "LAYER*-CEN" "") (command "layer" "new" "LAYER-01-DIM,LAYER-02-DIM,LAYER-03-DIM" "color" "1" "LAYER*-DIM" "") (command "layer" "new" "LAYER-01-HID,LAYER-02-HID,LAYER-03-HID" "color" "6" "LAYER*-HID" "ltype" "HIDDEN2" "LAYER*-HID" "") ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 11, 2009 Share Posted June 11, 2009 Pretty easy to do in lisp just need to create a string answer here is a start not complete code (setq x (getint "\n Enter number of layers")) (command "layer" "New") ;start laynew (repeat x (setq num (rtos x 2 0)) (setq newlay (strcat "layer-" num "-prt")) (command newlay) ) ; end repeat x times (command "") ; end lay new you could do smart things like a defun for the repeated code but copy and paste is probably easier first go Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 11, 2009 Share Posted June 11, 2009 If I were you, I would definitely use an ENTMAKE method to create the layers - it'll be about 100x faster... (defun c:test (/ x len i j) (initget 7) (setq x (getint "\nHow Many: ") len (strlen (itoa x)) i 1) (repeat x (setq j (itoa i)) (while (< (strlen j) len) (setq j (strcat "0" j))) (Make_Lay (strcat "LAYER-" j "-PRT") 4 "CONTINUOUS") (Make_Lay (strcat "LAYER-" j "-CEN") 1 "CENTER2") (Make_Lay (strcat "LAYER-" j "-DIM") 1 "CONTINUOUS") (Make_Lay (strcat "LAYER-" j "-HID") 6 "HIDDEN2") (setq i (1+ i))) (princ)) (defun Make_Lay (Nme Col Lt) (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 Nme) (cons 70 0) (cons 62 Col) (cons 6 Lt) (cons 290 1) (cons 370 0)))) Quote Link to comment Share on other sites More sharing options...
DVDM Posted June 15, 2009 Author Share Posted June 15, 2009 Thanks BIGAL & Lee Mac. Lee Mac, that code is indeed lightning quick. First time I tried it (entering 99) I thought it failed because nothing happened, until I saw that all layers were there. It works great! While I can still get my head around the first routine, the second one (Make_Lay) gets a bit mysterious to me, but I can use this as a basis for several different layer creation routines. One question though. We set up our layers using Lineweight: Default, but the layers created using this routine are at 0.00mm. While it's easy to change all layers to Default in the layer pallette, I was wondering if this can be changed in the Make_Lay routine? Either way, thanks for your help, it's a very useful piece of code Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 15, 2009 Share Posted June 15, 2009 Try this, I have also explained each line for you (defun c:test (/ x len i j) ;; Define function and Localise Variables (initget 7) ; Prevents -ve & 0 and user hitting Enter (setq x (getint "\nHow Many: ") ; Get Number of Layers len (strlen (itoa x)) ; Get String Length of Layer number i 1) ; Inititate Counter (repeat x ; Repeat the following (setq j (itoa i)) ; Convert the Counter to a String (while (< (strlen j) len) ; While the string is shorter than the length of the No. of layers... (setq j (strcat "0" j))) ;; Pad it with zeros. ;; {INVOKE MAKE_LAY} (Make_Lay (strcat "LAYER-" j "-PRT") 4 "CONTINUOUS") (Make_Lay (strcat "LAYER-" j "-CEN") 1 "CENTER2") (Make_Lay (strcat "LAYER-" j "-DIM") 1 "CONTINUOUS") (Make_Lay (strcat "LAYER-" j "-HID") 6 "HIDDEN2") ;; ---------------- (setq i (1+ i)) ; Increment Counter ) ; End Repeat (princ) ; Exit Cleanly ) ; End Function (defun Make_Lay (Nme Col Lt) (entmake (list (cons 0 "LAYER") ; Entity Type (cons 100 "AcDbSymbolTableRecord") ; Subclass Markers (cons 100 "AcDbLayerTableRecord") ; Subclass Markers (cons 2 Nme) ; Layer Name (cons 70 0) ; Layer Flags (Locked/Frozen etc) (cons 62 Col) ; Layer Colour (cons 6 Lt) ; Layer Linetype (cons 290 1) ; Layer to Plot (0 = No, 1 = Yes) (cons 370 -3) ; Lineweight enum ) ; End list ) ; end entmake ) ; end function Quote Link to comment Share on other sites More sharing options...
DVDM Posted June 22, 2009 Author Share Posted June 22, 2009 Thanks Lee Mac, that works perfect. (cons 0 "LAYER") ; Entity Type (cons 100 "AcDbSymbolTableRecord") ; Subclass Markers (cons 100 "AcDbLayerTableRecord") ; Subclass Markers (cons 2 Nme) ; Layer Name (cons 70 0) ; Layer Flags (Locked/Frozen etc) (cons 62 Col) ; Layer Colour (cons 6 Lt) ; Layer Linetype (cons 290 1) ; Layer to Plot (0 = No, 1 = Yes) (cons 370 -3) ; Lineweight enum This bit of code, is there a list of these numbers and values anywhere, documenting what it all means? I wouldn't have figured out in a million years that the '-3' would have given me Default lineweights Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 22, 2009 Share Posted June 22, 2009 I didn't look it up, I just set a layer in CAD to Default lineweight and quickly wrote some code to "work it backwards" to see what the enum was. But for reference, see here. Lee Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 22, 2009 Share Posted June 22, 2009 When I mention "work it backwards" I mean, retrieve the DXF table for the entity, using code similar to these: [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:en [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] ent[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ent [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entsel[/color][/b] [b][color=#ff00ff]"\nSelect Object: "[/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]progn[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]foreach[/color][/b] n [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] ent[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]print[/color][/b] n[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]textscr[/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]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:layen [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] lay tdef[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]snvalid[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]Setq[/color][/b] lay [b][color=RED]([/color][/b][b][color=BLUE]getstring[/color][/b] [b][color=BLUE]t[/color][/b] [b][color=#ff00ff]"\nSpecify Layer: "[/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]setq[/color][/b] tdef [b][color=RED]([/color][/b][b][color=BLUE]tblsearch[/color][/b] [b][color=#ff00ff]"LAYER"[/color][/b] lay[b][color=RED])[/color][/b][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]princ[/color][/b] [b][color=#ff00ff]"\n-- Table Definition --\n"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]foreach[/color][/b] x tdef [b][color=RED]([/color][/b][b][color=BLUE]print[/color][/b] x[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n\n-- LAYER Object -- \n"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]foreach[/color][/b] x [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]tblobjname[/color][/b] [b][color=#ff00ff]"LAYER"[/color][/b] lay[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]print[/color][/b] x[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]textscr[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n<< Layer not Found >>"[/color][/b][b][color=RED])[/color][/b][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] [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:blken [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] blk tdef[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]snvalid[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] blk [b][color=RED]([/color][/b][b][color=BLUE]getstring[/color][/b] [b][color=BLUE]t[/color][/b] [b][color=#ff00ff]"\nSpecify Block Name: "[/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]setq[/color][/b] tdef [b][color=RED]([/color][/b][b][color=BLUE]tblsearch[/color][/b] [b][color=#ff00ff]"BLOCK"[/color][/b] blk[b][color=RED])[/color][/b][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]princ[/color][/b] [b][color=#ff00ff]"\n-- Table Definition --\n"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]foreach[/color][/b] x tdef [b][color=RED]([/color][/b][b][color=BLUE]print[/color][/b] x[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n\n-- BLOCK Object -- \n"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]foreach[/color][/b] x [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]tblobjname[/color][/b] [b][color=#ff00ff]"BLOCK"[/color][/b] blk[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]print[/color][/b] x[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]textscr[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n<< Block not Found >>"[/color][/b][b][color=RED])[/color][/b][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] The above should help clarify things 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.