Jump to content

Recreate layers


flowerrobot

Recommended Posts

If i have layers already created, my lisp falls on deaf ears basicly, It dosnt re-wright the entity

As many of my colluges use these layers, But their all set to white :| and just change the colour, aka red line of the yellow layer along with a dim "D

(p.s plz do not comment about the gay layers, I have to work with them all day :( )

(defun C:lay (/ layerlist count nme col lt plt)
(setvar "cmdecho" 0)
(setq layerlist
 (list
  (list "white" "7" "CONTINUOUS")
  (list "red" "1" "CONTINUOUS")
  (list "blue" "5" "CONTINUOUS")
  (list "green" "4" "CONTINUOUS")
  (list "grey" "8" "CONTINUOUS")
  (list "magenta" "6" "CONTINUOUS")
  (list "cyan" "4" "CONTINUOUS")
  (list "dim" "4" "CONTINUOUS")
  (list "hidden" "7" "hidden")
  (list "center" "7" "center")
  (list "Phantom" "8" "phantom")
  (list "text" "2" "CONTINUOUS")
  (list "noplot" "8" "phantom")
  (list "yellow" "6" "CONTINUOUS")
 )
)
(setq count 0)
(while (nth count layerlist)
 (setq nme (car (nth count layerlist)))
 (setq col (atoi (cadr (nth count layerlist))))
 (setq lt (caddr (nth count layerlist)))
 (setq count (1+ count))
   (if (= nme "noplot")
    (setq plt 0)
    (setq plt 1)
 )
 (and (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 plt)
       (cons 370 0)
  )
 )
 )
)
(setvar "cmdecho" 1)
(princ)
)

Link to comment
Share on other sites

  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • flowerrobot

    8

  • Lee Mac

    6

  • Commandobill

    5

  • Freerefill

    1

Top Posters In This Topic

A few suggestions...

 

First, you can write a lisp to take all lines/polylines that have certain property (say, colour or linetype) and change them to the proper layer. I use this technique at work, and it's extremely helpful, especially when you need to freeze or isolate layers. It's also quite easy to write in LISP.

 

Second, your code is good. If your problem is that nothing is being over-written, you can try writing an addition to your code that uses the command "laydel" to get rid of layers before you re-write them.

 

If you really want to go the extra mile,

(vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object)))

That should start you off.

 

Hope some of that helps ^.^

Link to comment
Share on other sites

I understand it's not very clean but try this.

 

(defun C:lay (/ laylst laynm exlay nme)
 (setvar "cmdecho" 0)
 (setq exlay (list (cdr (assoc 2 (tblnext "Layer" t)))))
 (while (setq laynm (tblnext "Layer"))
   (setq exlay (append (list (cdr (assoc 2 laynm)))exlay))
   )
   
 (setq laylst
    (list
      (list "white" 7 "CONTINUOUS")
      (list "red" 1 "CONTINUOUS")
      (list "blue" 5 "CONTINUOUS")
      (list "green" 4 "CONTINUOUS")
      (list "grey" 8 "CONTINUOUS")
      (list "magenta" 6 "CONTINUOUS")
      (list "cyan" 4 "CONTINUOUS")
      (list "dim" 4 "CONTINUOUS")
      (list "hidden" 7 "hidden")
      (list "center" 7 "center")
      (list "Phantom" 8 "phantom")
      (list "text" 2 "CONTINUOUS")
      (list "noplot" 8 "phantom")
      (list "yellow" 6 "CONTINUOUS")
      )
   )
 ;***********************Borrowed from Lee Mac*************************
 (mapcar
   '(lambda (z)
      (if (not (tblsearch "LTYPE" (caddr z)))
   (vla-load
     (vla-get-Linetypes
       (vla-get-ActiveDocument
         (vlax-get-acad-object))) (caddr z) "acad.lin"))) laylst)
 ;*********************************************************************
 (mapcar
   '(lambda (z)
     (if (member (setq nme (car z)) exlay)
   (progn
     (vla-put-linetype (setq layen (vlax-ename->vla-object (tblobjname "Layer" nme))) (caddr z))
     (vla-put-colorindex (vla-get-truecolor layen) (cadr z)))
   (progn
     (entmake
       (list
         (cons 0 "LAYER")
         (cons 100 "AcDbSymbolTableRecord")
         (cons 100 "AcDbLayerTableRecord")
         (cons 2 Nme)
         (cons 70 0)
         (cons 62 (cadr z))
         (cons 6 (caddr z))
         (cons 290 1)
         (cons 370 0)))))) laylst)
 (vla-put-plottable (vlax-ename->vla-object (tblobjname "Layer" "noplot")) :vlax-false)
 )

 

Edit: I used some code from Lee mac and I wanted to give credit where credit was due.

Link to comment
Share on other sites

(p.s plz do not comment about the gay layers, I have to work with them all day :( )

 

OK... but why is layer "green" blue and layer "yellow" magenta? lol :lol:

 

It's ok I dont generally question other people standards.

Link to comment
Share on other sites

Is this towards me?

 

No, sorry Bill, not towards you - I was reffering to the code as originally posted by Flowerrobot, as the layer entmake looked strikingly similar...

Link to comment
Share on other sites

A few suggestions...

 

First, you can write a lisp to take all lines/polylines that have certain property (say, colour or linetype) and change them to the proper layer.

 

uses the command "laydel" to get rid of layers before you re-write them.

 

 

From what i understand your saying, Seems quite a big, Because i their will be things on that layer, I can not delete it. This means i would have to change all items on layer "x" place it on "y", Then delete layer "x" recreate it, Then move that selection back to layer "x", Then do this for all layers.

 

To me Seems over the top, A little.

 

 

Commandobill

 

Sorry my friend, Recieves the same error i get.

But i do like the way you incorpriated the linetype file into it. That was on my to do list.

 

Did you use the code from this thread?

Yes it was the inspriation.

I was using a hole lot of

(command ".layer" "m" "white" "c" "7" "white" "l" "CONTINUOUS" "white" \)

Mmmm Sub they have there place, i didnt think it was needed tho.

 

(defun C:lay (/ layerlist count nme col lt)
   (setvar "cmdecho" 0)
   (setq layerlist
       (list
           (list "white" "7" "CONTINUOUS")
           (list "red" "1" "CONTINUOUS")
           (list "blue" "5" "CONTINUOUS")
           (list "green" "4" "CONTINUOUS")
           (list "grey" "8" "CONTINUOUS")
           (list "magenta" "6" "CONTINUOUS")
           (list "cyan" "4" "CONTINUOUS")
           (list "dim" "4" "CONTINUOUS")
           (list "hidden" "7" "hidden")
           (list "center" "7" "center")
           (list "Phantom" "8" "phantom")
           (list "text" "2" "CONTINUOUS")
           (list "noplot" "8" "phantom")
           (list "yellow" "6" "CONTINUOUS")
       )
   )
   (defun layercreate (nme col lt / plt)
       (if (= nme "noplot")
             (setq plt 0)
             (setq plt 1)
       )
       (and 
           (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 plt)
                 (cons 370 0)
               )
           )
       )
   )
   (setq count 0)
   (while (nth count layerlist)
       (layercreate (car (nth count layerlist)) (atoi (cadr (nth count layerlist))) (caddr (nth count layerlist)))
       (setq count (1+ count))
   )
   (setvar "cmdecho" 1)
   (princ)
)

What about "entmod"???

Can that change layer's and thing that arnt selected by a selection set

 

 

Thanks guys for all your help!

Link to comment
Share on other sites

It depends if you want to make the layers or modify existing layers, look at the thread hyperlink I post in my earlier post.

 

It will created all the layers in the list supplied using a sub-function.

 

When performing the same operation on lots of data, a sub-function called with arguments is definitely worthwhile. Notice that the code that you pulled the entmake section from also uses it as a subfunction.

Link to comment
Share on other sites

It depends if you want to make the layers or modify existing layers, look at the thread hyperlink I post in my earlier post.

 

Will have a look, Was thinking doing a check see if the layer exists if so modify it, if not do what i have got above

 

When performing the same operation on lots of data, a sub-function called with arguments is definitely worthwhile.

 

They are good when the code is repeated more than once, other than ia a while/repeat.

 

And also great in generic code where it can be used any where, eg get all attributes from items.

 

put attributes back

 

Search on item

 

etc.

 

But just because things can be done that way dosnt always mean they shoud.

 

 

thanks for you help

 

Will have a look at how you did the entmod to the layers

 

Warm Regards

Flower

Link to comment
Share on other sites

For some reason my entmod will not work....

What am i missing?

 

(defun C:lay (/ layerlist count nme col lt plt)
(setvar "cmdecho" 0)
(setq layerlist
 (list
  (list "white" "7" "CONTINUOUS")
  (list "red" "1" "CONTINUOUS")
  (list "blue" "5" "CONTINUOUS")
  (list "green" "4" "CONTINUOUS")
  (list "grey" "8" "CONTINUOUS")
  (list "magenta" "6" "CONTINUOUS")
  (list "cyan" "4" "CONTINUOUS")
  (list "dim" "4" "CONTINUOUS")
  (list "hidden" "7" "hidden")
  (list "center" "7" "center")
  (list "Phantom" "8" "phantom")
  (list "text" "2" "CONTINUOUS")
  (list "noplot" "8" "phantom")
  (list "yellow" "6" "CONTINUOUS")
 )
)
(defun layercreate (nme col lt)
 (if (= nme "noplot")
    (setq plt 0)
    (setq plt 1)
 )
 (and 
  (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 plt)
     (cons 370 0)
   )
  )
 )
)
(defun layeroverride (nme col lt)
 (if (= nme "noplot")
  (setq plt 0)
  (setq plt 1)
 )
 (entmod
  (list
    (cons 0 "LAYER")
    (cons 100 "AcDbSymbolTableRecord")
    (cons 100 "AcDbLayerTableRecord")
    (cons 2 Nme)
    (cons 70 0)
    (cons 62 Col)
    (cons 6 Lt)
    (cons 290 plt)
    (cons 370 0)
  ) 
 )
)
(setq count 0)
(while (nth count layerlist)
 (if (tblsearch "LAYER" (car (nth count layerlist)))
  (layeroverride (car (nth count layerlist)) (atoi (cadr (nth count layerlist))) (caddr (nth count layerlist)))
  (layercreate (car (nth count layerlist)) (atoi (cadr (nth count layerlist))) (caddr (nth count layerlist)))
 )
 (setq count (1+ count))
)
(setvar "cmdecho" 1)
(princ)
)

Link to comment
Share on other sites

 

 

Commandobill

 

Sorry my friend, Recieves the same error i get.

But i do like the way you incorpriated the linetype file into it. That was on my to do list.

 

What error are you getting? I tested it a few times on my computer and it ran like a champ. If you could tell me what it is doing wrong I could adjust it to work.

Link to comment
Share on other sites

But just because things can be done that way dosnt always mean they shoud.

 

Of course, its your program - I'm just trying to get you into good programming practice - but do it any way you want to.

Link to comment
Share on other sites

This should perform as needed Flowerrobot, just populate the table to meet your layer standard:

 

[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] lays 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] lays [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]
       lay [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]tblsearch[/color][/b] [b][color=#ff00ff]"LAYER"[/color][/b] Nme[b][color=RED])[/color][/b]
                  [b][color=RED]([/color][/b][b][color=BLUE]vla-item[/color][/b] lays Nme[b][color=RED])[/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=BLUE]vla-add[/color][/b] lays Nme[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] 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 [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] 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=BLUE]/[/color][/b] [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]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]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

Link to comment
Share on other sites

Of course, its your program - I'm just trying to get you into good programming practice - but do it any way you want to.

 

Ohh dont get me wrong, i welcome any input.

 

Im just saying (for another exampe)

 

THeir is no point using a "cond" when the "if" statement covers it (as it either yes or no question.)

Link to comment
Share on other sites

This should perform as needed Flowerrobot, just populate the table to meet your layer standard:

 

 

Thanks for that, Had a look threw it and found what i need.

 

"vla-put-LineWeight"

"vla-put-Linetype"

"vla-put-Color"

"vla-put-Plottable lay :vlax-false"

 

Not saying my code is better, nor worse

 

Just like how my list of layers to create are set (easiyer to edit)

 

Thanks heaps!

 

Flower

Link to comment
Share on other sites

What error are you getting? I tested it a few times on my computer and it ran like a champ. If you could tell me what it is doing wrong I could adjust it to work.

 

Sorry an error as in, Not over-righting the current layer.

It worked great if not layer are set. Really like how u incorpiated the linetype check into it

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...