새로 추가된 레이어로 삽입물 색칠하기
Contents
[
Hide
]새로 추가된 레이어로 삽입물 색칠하기 (CADNET-1146)
문제: 새로 추가된 레이어로 삽입물 색칠하기 (CADNET-1146).
팁: 이렇게 하려면 CadLayerTable 클래스를 사용하여 새 레이어를 추가할 수 있는 레이어를 생성하고, CadLayersList를 사용하여 여러 레이어를 추가할 수도 있습니다.
예제:
초기 파일에는 “1”, “2”, “3”, “4” 및 “5"라는 이름의 5개의 삽입물이 있으며, 이들 모두 기본 0 레이어에 있습니다.
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); | |
} |