Question
以下のサンプルコードの様に、AutoCAD .net APIで作成した球体のソリッドで、GUIのプロパティ表示「ジオメトリ」に中心座標や半径が表示されない。
「ジオメトリ」が表示されるようにするにはどうしたらよいでしょうか。
Document dc = Application.DocumentManager.MdiActiveDocument;
Database db = dc.Database;
Editor ed = dc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable acBlkTbl;
acBlkTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord acBlkTblRec;
acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
double rd, x, y, z;
string sLayer;
short lyColor;
rd = 1.0;
x = 0.0;
y = 0.0;
z = 0.0;
using (Solid3d sphere = new Solid3d())
{
sphere.CreateSphere(rd);
Point3d location = new Point3d(x, y, z);
sphere.TransformBy(Matrix3d.Displacement(location - Point3d.Origin));
acBlkTblRec.AppendEntity(sphere);
tr.AddNewlyCreatedDBObject(sphere, true);
}
tr.Commit();
}
Answer
APIから作成した球の場合には、タイププロパティ(GUIではAutoCADのコマンドから作成した球のプロパティを参照するとジオメトリの項目に表示されるソリッドタイプ)が設定されていないことが、GUIにジオメトリの項目が表示されない原因です。
このタイププロパティはAutoCADのコマンドから球や円柱等のプリミティブなソリッド形状を作成した場合にのみ設定され、Object ARX .net、ActiveX 等のAPIから3Dソリッドを作成した場合にはこのプロパティは設定されません。
回避方法としては、以下のサンプルコードの様に.netのコードからEditor.Command()メソッドを用いて、Shpereコマンドを実行する方法となります。
Document dc = Application.DocumentManager.MdiActiveDocument;
Database db = dc.Database;
Editor ed = dc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable acBlkTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
acLyrTbl = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
double rd, x, y, z;
rd = 1.0;
x = 0.0;
y = 0.0;
z = 0.0;
Point3d location = new Point3d(locX, locY, locZ);
ed.Command("_.sphere", location, rd, "");
Solid3d sphere = tr.GetObject(ed.SelectLast().Value.GetObjectIds()[0], OpenMode.ForWrite) as Solid3d;
tr.Commit();
}
記事全体を表示