Merge layers

Merge layers

R.Gerritsen4967
Advocate Advocate
2,157 Views
3 Replies
Message 1 of 4

Merge layers

R.Gerritsen4967
Advocate
Advocate

I need to merge some layers in a drawing,  so I can write a .NET program to first move all objects from one layer to another and then delete the first layer. But I'm not sure if this is the right way to approach this.

 

In the layer properties manager in AutoCAD there is a command 'Merge selected layer(s) to...'. This command does exactly what I need without me thinking about all the possible checks that need to be performed to avoid crashing AutoCAD.

 

I already tried to find some merge property of the layertablerecord or something in the layertable, but I can't find anything usefull.

 

Is it possible to use this command using VB.NET?

 

0 Likes
Accepted solutions (1)
2,158 Views
3 Replies
Replies (3)
Message 2 of 4

_gile
Consultant
Consultant
Accepted solution

Hi,

 

You can call AutoCAD commands from .NET using Document.SendStringToExecute() method (which runs asynchronously) or, since AutoCAD 2015, Editor.Command() which runs synchronously (for prior version Tony Tanzillo shared a wrapper for the non public RunCommand() method).

 

Anyway, moving entities from one layer to another should do the trick, just check the layers aren't locked and iterate all the block table records from block table in case some entity on the source layer owns to a block definition.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 4

R.Gerritsen4967
Advocate
Advocate

Hello @_gile,

 

Thanks for your quick answer!

 

It seems I was thinking way to complicated!Smiley Very Happy

The editor.Command() is a really nice option. This is what I came up with.

 

VB.NET

   Public Sub Mergelayers(layertomerge As String, mergetolayer As String)

        Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
        ed.Command("LAYMRG", "n", layertomerge, "", "n", mergetolayer, "y")

    End Sub
Message 4 of 4

David_Prontnicki
Collaborator
Collaborator

@_gile 

 

Do you know if this is the only way to merge layers via .net? I am not of fan of the command line output while merging layers, and no system variables; i.e. cmdecho, etc will suppress them. I would like to do it pragmatically if possible. The reason is while merging, the command line may pause on the question "Merge Layers?" Y/N and the user may think that they have to press a key and I don't want to confuse them.

 

Thank you,

0 Likes