質問
AutoCAD Plant3D .net API でデータマネージャで表示されているガスケットのプロパティ情報を取得したい。
回答
ガスケット(≒ コネクタ)の場合、Connector.AllSubPartsからサブパーツ数を取得し、DataLinksManager.MakeAcPpObjectId()をsubIndexを指定してrowIdを取得後にDataLinksManager.GetAllProperties()を実行することでプロパティを取得することが可能となります。
以下は、選択したガスケットのプロパティ情報を取得するC#のサンプルコードとなります。
[CommandMethod("GetPipingProperties")]
public void GetPipingProperties()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptEntityResult res = ed.GetEntity("Pick Object obtain properties : ");
if (res.Status == PromptStatus.OK)
{
ObjectId objectId = res.ObjectId;
PlantProject currentProj = PlantApplication.CurrentProject;
PipingProject pipingProj = (PipingProject)currentProj.ProjectParts["Piping"];
DataLinksManager dlm = pipingProj.DataLinksManager;
int rowId = dlm.FindAcPpRowId(res.ObjectId);
List<KeyValuePair<string, string>> properties;
properties = dlm.GetAllProperties(rowId, true);
for (int i = 0; i < properties.Count; i++)
ed.WriteMessage("\nProperty name:" + properties[i].Key +
" = " + properties[i].Value);
Database trDatabase = objectId.Database;
using (Transaction tr = trDatabase.TransactionManager.StartTransaction())
{
Connector connector = tr.GetObject(objectId, OpenMode.ForRead, false, true) as Connector;
if (connector != null)
{
SubPartCollection subPartCollection = connector.AllSubParts;
int index = 1;
foreach (object connectorSubPart in subPartCollection)
{
int acPcRowId = dlm.FindAcPpRowId(dlm.MakeAcPpObjectId(objectId, index));
List<KeyValuePair<string, string>> subProps = dlm.GetAllProperties(acPcRowId, true);
if (subProps != null)
{
foreach(var subProp in subProps)
ed.WriteMessage("\nProperty name:" + subProp.Key +
" = " + subProp.Value);
}
index++;
}
}
}
}
}
記事全体を表示