View Full Version : Merge Layers
mhs50000
2008-01-05, 12:37 AM
I'm looking for some help on merging layers. Trying to write something that will merge layers based on their prefix. I'm aware of the -laymrg command but looking for something that can be run prior to posting to a web based map. Anyone have any suggestions? Thanks in advance.
ccowgill
2008-01-07, 12:28 PM
so to be more specific, you are looking for a program that will quickly merge specific layers based on prefix and save the drawing as a copy for use in posting to the web (allowing you to make changes to the original and "repost")?
does the following pseudo code sound like what you need (or sound like it will even work)?
;create selectionset based on layer name
;find number of items in selectionset
;while current number is less than selectionset number
;convert each object to vla
;use vla-put to change the layer it exists on
;increment object number
;saveas another drawing
mhs50000
2008-01-07, 02:49 PM
Your synopsis of my requirements is dead on. Just trying to minimize our layers for easier management in MapGuide. The pseudo code looks pretty close but I don't know that I would have a need for numbering the selection set. I'm guessing you have this code already?
ccowgill
2008-01-08, 12:32 PM
Your synopsis of my requirements is dead on. Just trying to minimize our layers for easier management in MapGuide. The pseudo code looks pretty close but I don't know that I would have a need for numbering the selection set. I'm guessing you have this code already?
no, I dont have the code, so I will write one, the numbering of the selectionset makes it easier to step through each item, try this code (not tested):
(defun c:mapguidelaymrg
(/ layerset layersetno count layerset1 layersetvla)
(setq layerset (ssget "_X")) ;create selectionset
(if (/= layerset nil)
(progn
(setq layersetno
(sslength layerset) ;find number of items in selectionset
count 0
) ;_ end of setq
(while (< count layersetno) ;while current number is less than selectionset number
(setq layerset1 (ssname layerset count)
layersetvla (vlax-ename->vla-object layerset1)
;convert each object to vla
) ;_ end of setq
(cond
((wcmatch (vla-get-layer layersetvla) "xyz*")
(setq mapguidelay "xyz")
)
((wcmatch (vla-get-layer layersetvla) "abc*")
(setq mapguidelay "abc")
)
) ;_ end of cond
(if (/= mapguidelay nil)
(vla-put-layer layersetvla mapguidelay)
;use vla-put to change the layer it exists on
) ;_ end of if
(setq count (1+ count) ;increment object number
mapguidelay nil
) ;_ end of setq
) ;_ end of while
(setvar "filedia" 0)
(command ".save" "c:\\mapguidepath.dwg")
(setvar "filedia" 1)
) ;_ end of progn
(prompt "\nThis drawing contains no objects\n")
) ;_ end of if
) ;_ end of defun
you will need to imput your layer names, try it out and post back if it actually worked, I dont have any drawings that I can test it on, our names are pretty unique for each layer. However I can tell you that you will need to make sure that whatever layer you are merging to exists in the drawing, otherwise the program will error out, some layer checking can be added to assure this doesnt happen, but the list of layers you use would be required to complete the program.
mhs50000
2008-01-08, 04:22 PM
That worked. Thank you very much! I just added a purge at the end to eliminate the old layers. Thanks again!!!
irneb
2008-01-14, 04:09 AM
You could also use the Layer Merge command: in 2008 Format --> Layer tools --> Layer Merge (it used to be an Express Tool).
In Lisp you could step through the list of layers, and perform the following on each incorrect layer:
(command "-laymrg" "Name" layold "" "Name" laynew "" "Yes")
Using the LAYMRG command it will merge all specified layers & purge them. Even if they're used inside a block. Whereas if you simply step through a selection set, changing each entity to a different layer would only work if any & all entities within blocks are on layer 0.
mhs50000
2008-01-14, 02:40 PM
The layer merge tool is a good one, layer translate (laytrns) works good too. However I was looking for something automated that runs inside of another routine. The idea was to post a drawing to a server and the routine will grab anything inside a "folder" and modify it to our standards. Layer merge won't use wildcards.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.