การระบายสีของการแทรกด้วยเลเยอร์ใหม่ที่เพิ่มเข้าไป
Contents
[
Hide
]วิธีการระบายสีของการแทรกด้วยเลเยอร์ใหม่ที่เพิ่มเข้าไป (CADNET-1146)
ปัญหา: วิธีการระบายสีของการแทรกด้วยเลเยอร์ใหม่ที่เพิ่มเข้าไป (CADNET-1146).
เคล็ดลับ: เพื่อทำสิ่งนี้ ใช้คลาส CadLayerTable เพื่อสร้างเลเยอร์เพื่อให้สามารถเพิ่มเลเยอร์ใหม่ลงในภาพวาดได้ คุณยังสามารถใช้ CadLayersList เพื่อเพิ่มเลเยอร์หลายๆ เลเยอร์
ตัวอย่าง:
ไฟล์ต้นฉบับประกอบด้วยการแทรก 5 ตัวที่มีชื่อว่า “1”, “2”, “3”, “4” และ “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); | |
} |