Coloring of inserts with new added layers
Contents
[
Hide
]How to coloring of inserts with new added layers (CADNET-1146)
Issue: How to coloring of inserts with new added layers (CADNET-1146).
Tips: To do this, use the CadLayerTable class to create a layer to be able to add a new layer to the drawing, you can also use CadLayersList to add multiple layers.
Example:
The initial file contains 5 inserts with names “1”, “2”, “3”, “4’ and “5” and all of them are in the default 0 layer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (CadImage cadImage = (CadImage)Image.Load(GetPath(fileName))) | |
{ | |
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); | |
rasterizationOptions.DrawType = CadDrawTypeMode.UseObjectColor; | |
CadLayersList newList = cadImage.Layers; | |
CadLayerTable redLayer = new CadLayerTable(); | |
redLayer.Name = "REDLAYER"; | |
redLayer.ColorId = 1; // ID of red color | |
redLayer.ObjectHandle = "REDLAYER"; | |
CadLayerTable greenLayer = new CadLayerTable(); | |
greenLayer.Name = "GREENLAYER"; | |
greenLayer.ObjectHandle = "GREENLAYER"; | |
greenLayer.ColorId = 3; // ID of green color | |
newList.AddRange(new CadLayerTable[] {redLayer, greenLayer}); | |
cadImage.Layers = newList; | |
foreach (CadBaseEntity entity in cadImage.Entities) | |
{ | |
if (entity.TypeName == CadEntityTypeName.INSERT) | |
{ | |
CadInsertObject insert = (CadInsertObject)entity; | |
// the required block to change color for is identified by name | |
if (insert.Name == "3") | |
{ | |
insert.LayerName = "REDLAYER"; | |
} | |
if (insert.Name == "2") | |
{ | |
insert.LayerName = "GREENLAYER"; | |
} | |
} | |
} | |
PdfOptions pdfOptions = new PdfOptions(); | |
pdfOptions.VectorRasterizationOptions = rasterizationOptions; | |
cadImage.Save(outPath, pdfOptions); | |
} |