-
Notifications
You must be signed in to change notification settings - Fork 407
can we merge two layer to one #423
Comments
Set the current layer to any layer that will not be removed. |
thanks, I write a function。 move a dxfObject to layerOfTarget. I have successfully tested。 Do you have more suggestions.
|
Here you have an example of how this is done. The case of changing layers is the easiest one since only entities can belong to a layer, other table objects like a linetype can belong not only to entities but also to layers, dimension styles, multiline styles, ... DxfDocument doc = new DxfDocument();
Layer layer1 = new Layer("Layer1")
{
Color = AciColor.Red
};
Layer layer2 = new Layer("Layer2")
{
Color = AciColor.Blue
};
Line line1 = new Line(new Vector2(-1, -1), new Vector2(1, 1))
{
Layer = layer1
};
Line line2 = new Line(new Vector2(-1, 1), new Vector2(1, -1))
{
Layer = layer2
};
doc.Entities.Add(line1);
doc.Entities.Add(line2);
doc.Save("OriginalDrawing.dxf");
// use the document we created or load one of your choice
DxfDocument dxf = DxfDocument.Load("OriginalDrawing.dxf");
// combine entities in "Layer1" with entities in "Layer2"
// get a copy of the list of all objects referenced by "Layer2"
List<DxfObject> refsLayer2 = dxf.Layers.GetReferences("Layer2");
// destination layer
Layer destLayer = dxf.Layers["Layer1"];
// assign entities in "Layer2" to "Layer1"
foreach (DxfObject o in refsLayer2)
{
if (o is EntityObject entity)
{
entity.Layer = destLayer;
}
}
// optionally we can delete "Layer2",
// this method will return false if the layer cannot be removed
// this is only possible when the number of references is zero
bool removed = dxf.Layers.Remove("Layer2");
// save the modified drawing
dxf.Save("ModifiedDrawing.dxf"); |
I have two layers .I want merge them to one .
The text was updated successfully, but these errors were encountered: