Merge layers to one

Merge layers to one

Anonymous
Not applicable
5,054 Views
6 Replies
Message 1 of 7

Merge layers to one

Anonymous
Not applicable

Hi,

 

I need help on fixing this lisp where I need to merge any existing layers DIM* to a new layer DIM-N. Then those layer would be removed as it should with the Layer merge command.

Somehow it's not doing it here. Sorry this lisp was not wirtten in a professional manner. Eg. if I don't have DIM5, I don't need to create it, just skip DIM5. All I need is DIM-N only, the rest of DIM* be deleted.

 

Thanks

 

  Code:

(defun c:LMR (/ ss)
(command "-layer" "S" "0" "")
  (if (not (tblsearch "LAYER" "DIM-N")) (command ".LAYER" "N" "DIM-N" ""))
  (if (not (tblsearch "LAYER" "DIM1")) (command ".LAYER" "N" "DIM1" ""))
  (if (not (tblsearch "LAYER" "DIM2")) (command ".LAYER" "N" "DIM2" ""))
  (if (not (tblsearch "LAYER" "DIM5")) (command ".LAYER" "N" "DIM5" ""))
  (if (not (tblsearch "LAYER" "DIM10")) (command ".LAYER" "N" "DIM10" ""))
  (if (not (tblsearch "LAYER" "DIM20")) (command ".LAYER" "N" "DIM20" ""))
  (if (not (tblsearch "LAYER" "DIM50")) (command ".LAYER" "N" "DIM50" ""))
  (if (not (tblsearch "LAYER" "DIM100")) (command ".LAYER" "N" "DIM100" ""))
;
  (command ".-laymrg" "n" "DIM1" "" "n" "DIM-N")
  (command ".-laymrg" "n" "DIM2" "" "n" "DIM-N")
  (command ".-laymrg" "n" "DIM5" "" "n" "DIM-N")
  (command ".-laymrg" "n" "DIM10" "" "n" "DIM-N")
  (command ".-laymrg" "n" "DIM20" "" "n" "DIM-N")
  (command ".-laymrg" "n" "DIM50" "" "n" "DIM-N")
  (command ".-laymrg" "n" "DIM100" "" "n" "DIM-N")
(princ "\nLayers merged...") (princ)
)
0 Likes
Accepted solutions (2)
5,055 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

You certainly don't need to create layer just because you have it in the list to merge...

Just make sure that destintation layer exists.

 

(defun c:LMR nil
  
  (command "_.-LAYER" "_M" "DIM-N" "")

  (command "_.LAYMRG")
  (foreach e '("DIM1" "DIM2" "DIM5" "DIM10" "DIM20" "DIM50" "DIM100")
    (if (tblsearch "LAYER" e)
      (command "_Name" e)))
  (command "" "_N" "DIM-N" "_Y")

  (command "_.-PURGE" "_La" "DIM1,DIM2,DIM5,DIM10,DIM20,DIM50,DIM100" "_N")
  (princ)
)
Message 3 of 7

Anonymous
Not applicable
Accepted solution

Thanks BeekeeCZ. It works great. We added more things to it.

0 Likes
Message 4 of 7

gustavobernardi
Advocate
Advocate

Does it work when I store the name of the layer previosly?

I tried this way:

 

(defun c:convertlayersvelhos()
(setvar 'CLAYER "0")
(setq LVelho "Arquitetônico - Paredes");; define the old name
(setq LNovo "ARQ - Paredes Alvenaria");;define the new name
(if(tblsearch "layer" LVelho)(command "._-layer" "R" LVelho LNovo ""))
(command "Laymrg") (foreach e '(LVelho) (if (tblsearch "LAYER" e)(command "_Name" e)))(command "" "_N" LNovo "_Y")
(command "_.-PURGE" "_La" LVelho "_N")
(princ)
)

If it is possible I think that it will be easier for a several pair of layers (the code will be shorter).

 

0 Likes
Message 5 of 7

ВeekeeCZ
Consultant
Consultant

@gustavobernardi wrote:

Does it work when I store the name of the layer previosly?

I tried this way:

 

(defun c:convertlayersvelhos()
(setvar 'CLAYER "0")
(setq LVelho "Arquitetônico - Paredes");; define the old name
(setq LNovo "ARQ - Paredes Alvenaria");;define the new name
(if(tblsearch "layer" LVelho)(command "._-layer" "R" LVelho LNovo ""))
(command "Laymrg") (foreach e '(LVelho) (if (tblsearch "LAYER" e)(command "_Name" e)))(command "" "_N" LNovo "_Y")
(command "_.-PURGE" "_La" LVelho "_N")
(princ)
)

If it is possible I think that it will be easier for a several pair of layers (the code will be shorter).

 


 

Sure. Still need a help on this one? It somehow slipped thru my hands...

0 Likes
Message 6 of 7

diepkhoi90
Contributor
Contributor

Application Error: 0 :- bad argument type: stringp LVELHOADS request error

what could I do now mate! I tried your lisp and it show up this message.

0 Likes
Message 7 of 7

Kent1Cooper
Consultant
Consultant

@diepkhoi90 wrote:

Application Error: 0 :- bad argument type: stringp LVELHOADS request error

what could I do now mate! I tried your lisp and it show up this message.


I think this is a problem:

(foreach e '(LVelho) (if ....

 A "quoted list" with the apostrophe prefix cannot contain anything that requires evaluation, like a variable name, which is what LVelho is [containing a Layer name].  I think that needs to be:

(foreach e (list LVelho) (if 

 But even that doesn't make much sense to me, because (foreach) is meant for stepping through a list of things and doing something with each thing in it.  So there's little point in using it on a list with only one thing in it.  Also, the name in that variable should no longer be a Layer, since just above that, the Layer was Renamed, so I'm not sure of the intent.

 

But anyway, if you make that change, does it at least eliminate the error?

Kent Cooper, AIA
0 Likes