How can we access the System Definition of a Pipe or Duct or Fitting using the AutoCAD MEP .NET API?
Each of these entities expose the SystemId which can be used to access the System Definition that these entities are assigned to. Once we have access to the System Definition of the, say, Duct, we can directly access the Name, Label Name, etc.
[Autodesk.AutoCAD.Runtime.CommandMethod(
"DuctSD", CommandFlags.Modal)]
public void DuctSD()
{
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans =
db.TransactionManager.StartTransaction())
{
PromptEntityOptions peo =
new PromptEntityOptions("Pick Duct");
peo.SetRejectMessage("\nObject must be of type Duct.");
peo.AddAllowedClass(typeof(Duct), true);
Autodesk.AutoCAD.EditorInput.Editor ed =
Autodesk.AutoCAD.ApplicationServices
.Application.DocumentManager.MdiActiveDocument.Editor;
PromptEntityResult per = ed.GetEntity(peo);
Duct duct =
trans.GetObject(per.ObjectId, OpenMode.ForRead)
as Duct;
SystemDefinition dsd = (SystemDefinition)
db.TransactionManager.GetObject(
duct.SystemId, OpenMode.ForRead, false);
System.Windows.Forms.MessageBox.Show(
"Name: " + dsd.Name);
System.Windows.Forms.MessageBox.Show(
"Label Name : " + dsd.LabelName);
System.Windows.Forms.MessageBox.Show(
"Alternate Name: " + dsd.AlternateName);
trans.Commit();
}
}