Issue
サーフェスの外形エッジやパス形状をオブジェクトとして再作成することは出来ますか?
Solution
サーフェスの外形エッジやパス形状はサーフェスのサブエンティティ(FullSubentityPath)から形状を模倣して再作成することが出来ます。
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityOptions peo = new PromptEntityOptions("\nサーフェスを選択:");
peo.SetRejectMessage("\nサーフェスを選択してください...");
peo.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Surface), false);
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
return;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
ObjectId objId = per.ObjectId;
Entity ent = tr.GetObject(objId, OpenMode.ForWrite) as Entity;
ObjectId[] entId = new ObjectId[] { ent.ObjectId };
IntPtr pSubentityIdPE = ent.QueryX(AssocPersSubentityIdPE.GetClass(typeof(AssocPersSubentityIdPE)));
if (pSubentityIdPE == IntPtr.Zero)
return;
AssocPersSubentityIdPE subentityIdPE = AssocPersSubentityIdPE.Create(pSubentityIdPE, false) as AssocPersSubentityIdPE;
SubentityId[] edgeIds = subentityIdPE.GetAllSubentities(ent, SubentityType.Edge);
objId = SymbolUtilityServices.GetBlockModelSpaceId(db);
BlockTableRecord btr = tr.GetObject(objId, OpenMode.ForWrite) as BlockTableRecord;
foreach (SubentityId subentId in edgeIds)
{
FullSubentityPath path = new FullSubentityPath(entId, subentId);
Entity edge = ent.GetSubentity(path);
if (edge != null)
{
edge.ColorIndex = 3;
edge.LineWeight = LineWeight.LineWeight100;
btr.AppendEntity(edge);
tr.AddNewlyCreatedDBObject(edge, true);
}
}
tr.Commit();
}