Jump to content

layer merge command line


hrehor

Recommended Posts

I am looking for a script solution to merge all layers to layer 0.

First I unlock all layers and switch to layer 0.

My srcipt looks like this:

 

(defun c:lm0 ()

(command "._LAYER" "_UNLOCK" "*" "")

(command "._LAYER" "_THAW" "*" "")

(command "._LAYER" "_ON" "*" "")

(command "._LAYER" "_ON" "0" "_UNLOCK" "0" "_THAW" "0" "S" "0" "")

(command "._LAYMRG" "N" "*" "" "N" "0")

(princ)

)

Problem is that -laymrg will not accept * to select all layers.

How can you do that?

Link to comment
Share on other sites

You may have to do something like this, where you iterate the layer collection, feeding each layer name into the LAYMRG command.

 


(vlax-for
 x
 (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))
 (command "._laymrg" "_N" (vla-get-Name x) "" "_N" "0" "_Y")
)

Link to comment
Share on other sites

You may have to do something like this, where you iterate the layer collection, feeding each layer name into the LAYMRG command.

 


(vlax-for
 x
 (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))
 (command "._laymrg" "_N" (vla-get-Name x) "" "_N" "0" "_Y")
)

 

thanks RK. it does work, of course :-)

though it acts strangely, notepad starts up, when command evoked.

i have a shortcut "n" set to launch notepad, but in this case it shouldn't start, since it is not evoked anywhere.

 

could you please give me some idea why * wouldn't work particulary in this command? I always like to get a fishing rod instead of a fish.

Link to comment
Share on other sites

could you please give me some idea why * wouldn't work particulary in this command?

I suppose because whoever wrote the code didn't allow for it.

It probably isn't allowed because * would select all layers, including the current one- you can't merge the current layer.

Link to comment
Share on other sites

It probably has to do with laymrg trying and not being able to merge 0 with 0.

Try this (untested)...

 

(setvar 'clayer "0")
(vlax-for x (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))
 (or (eq (vla-get-name x) "0")
     (command "._laymrg" "_N" (vla-get-Name x) "" "_N" "0" "_Y")
 ) ;_ or
) ;_ vlax-for

Link to comment
Share on other sites

  • 7 years later...

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