Jump to content

Layer Swap


costadina

Recommended Posts

Hi All. I'm new to this forum. I am looking for any suggestions where I can find some code to do a layer swap in Autocad.

This is the situation: We have many drawings drawn to our companies layer standards. Now we have a new job and the customer has their own layer standards we must conform to.

 

For example, we have Layer 1 called Electrical, Line Type continuous, Color Yellow.

Customer has Layer 1 called Mechanical, Line Type Hidden, Color Green.

 

Does anyone have any suggestions where I can find some code to crunch through drawing sets and automatically change the layers? Magazine, book, website, whatever.

 

Also, this code must be able to change Layers embedded in blocks as well.

 

I am familiar with VBA having done VBA programming in Excel, so I would prefer VBA code, but of course, I'll take what I can find.

 

Just trying to avoid having to develop the code myself. Thanks in advance.

Link to comment
Share on other sites

Just trying to avoid having to develop the code myself. Thanks in advance.

So you want someone to do the work for you?

 

Try the Laytrans command

Link to comment
Share on other sites

So you want someone to do the work for you?

 

Try the Laytrans command

 

 

Im pretty sure he just meant he was hoping it was already written...

 

laytrans should do what you are looking for though

Link to comment
Share on other sites

i swear i read something by bill kramer (HTH), and he had written something very similar to that. i think he even called it Layer Swap, but i could be imagining things. they're right, laytrans will do what you are wanting though.

Link to comment
Share on other sites

I've used this a lot over the years on simple model space only, no xrefs drawings. A drawback can be if the linetype for the new layer does not exist or isn't in acad.lin, then it will fail during the LAYER command. It is case senitive ( in older releases didn't matter )

[b][color=BLACK]([/color][/b]defun c:cnvlayer [b][color=FUCHSIA]([/color][/b]/ ll tdef ln ss fe fd ld[b][color=FUCHSIA])[/color][/b]

[color=#8b4513];;;  FORMAT    OLD     NEW     CLR   LTYPE[/color]
 [b][color=FUCHSIA]([/color][/b]setq ll '[b][color=NAVY]([/color][/b][b][color=MAROON]([/color][/b][color=#2f4f4f]"1D"[/color]    [color=#2f4f4f]"PLAN"[/color]    2   [color=#2f4f4f]"CONTINUOUS"[/color][b][color=MAROON])[/color][/b]
            [b][color=MAROON]([/color][/b][color=#2f4f4f]"2D"[/color]    [color=#2f4f4f]"DETAIL"[/color]  6   [color=#2f4f4f]"PHANTOM"[/color][b][color=MAROON])[/color][/b]
            [b][color=MAROON]([/color][/b][color=#2f4f4f]"3D"[/color]    [color=#2f4f4f]"MODEL"[/color]   8   [color=#2f4f4f]"CONTINUOUS"[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]foreach l ll
   [b][color=NAVY]([/color][/b]command [color=#2f4f4f]"_.LAYER"[/color][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]tblsearch [color=#2f4f4f]"LAYER"[/color] [b][color=BLUE]([/color][/b]nth 1 l[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
          [b][color=MAROON]([/color][/b]command [color=#2f4f4f]"_M"[/color] [b][color=GREEN]([/color][/b]nth 1 l[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]command [color=#2f4f4f]"_C"[/color]  [b][color=MAROON]([/color][/b]nth 2 l[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]nth 1 l[b][color=MAROON])[/color][/b]
               [color=#2f4f4f]"_LT"[/color] [b][color=MAROON]([/color][/b]nth 3 l[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]nth 1 l[b][color=MAROON])[/color][/b]
               [color=#2f4f4f]""[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]setq tdef [b][color=MAROON]([/color][/b]tblnext [color=#2f4f4f]"LAYER"[/color] [b][color=GREEN]([/color][/b]not tdef[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]setq ln [b][color=MAROON]([/color][/b]cdr [b][color=GREEN]([/color][/b]assoc 2 tdef[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]and [b][color=MAROON]([/color][/b]setq ss [b][color=GREEN]([/color][/b]ssget [color=#2f4f4f]"X"[/color] [b][color=BLUE]([/color][/b]list [b][color=RED]([/color][/b]cons 8 ln[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]assoc ln ll[b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]command [color=#2f4f4f]"_.CHPROP"[/color] ss [color=#2f4f4f]""[/color] [color=#2f4f4f]"_LA"[/color] [b][color=GREEN]([/color][/b]nth 1 [b][color=BLUE]([/color][/b]assoc ln ll[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [color=#2f4f4f]""[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]setq tdef [b][color=MAROON]([/color][/b]tblnext [color=#2f4f4f]"BLOCK"[/color] [b][color=GREEN]([/color][/b]not tdef[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]setq fe [b][color=MAROON]([/color][/b]cdr [b][color=GREEN]([/color][/b]assoc -2 tdef[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]entmake tdef[b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]while fe
             [b][color=MAROON]([/color][/b]setq fd [b][color=GREEN]([/color][/b]entget fe[b][color=GREEN])[/color][/b]
                   ln [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 8 fd[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
               [b][color=MAROON]([/color][/b]and [b][color=GREEN]([/color][/b]setq ld [b][color=BLUE]([/color][/b]assoc ln ll[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]setq fd [b][color=BLUE]([/color][/b]subst [b][color=RED]([/color][/b]cons 8 [b][color=PURPLE]([/color][/b]nth 1 ld[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]assoc 8 fd[b][color=RED])[/color][/b] fd[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
            [b][color=MAROON]([/color][/b]entmake fd[b][color=MAROON])[/color][/b]
            [b][color=MAROON]([/color][/b]setq fe [b][color=GREEN]([/color][/b]entnext fe[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]entmake [b][color=MAROON]([/color][/b]list [b][color=GREEN]([/color][/b]cons 0 [color=#2f4f4f]"ENDBLK"[/color][b][color=GREEN])[/color][/b][b][color=GREEN]([/color][/b]cons 8 [color=#2f4f4f]"0"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

-David

Link to comment
Share on other sites

When I get back in the office next week I will try all your suggestions.

 

David, thanks for posting the code. Since I am unfamiliar with Lisp, could you describe your variables (ll tdef ln ss fe fd ld) so I can better understand the program.

Link to comment
Share on other sites

They're actually pretty simple

 

ll = users_layer_list

 

tdef = table_definition

 

ln = layer_name

 

ss - selection_set

 

fe - first_block_nested_entity_ename

 

fd - fe_dxf_definition

 

ld - layer_definition

 

ll is the only 1 you would need to modify to your needs. The rest are autonomous in the program. -David

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...