新しく追加されたレイヤーを使用した挿入のカラリング

新しく追加されたレイヤーを使用した挿入のカラリング方法 (CADNET-1146)

問題: 新しく追加されたレイヤーを使用した挿入のカラリング方法 (CADNET-1146)。

ヒント: これを行うには、CadLayerTableクラスを使用して新しいレイヤーを描画に追加できるレイヤーを作成し、CadLayersListを使用して複数のレイヤーを追加することもできます。

例:

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);
}