Hi All,
Recently, I found some information from the nozzle in the equipment. For example, I found the Nozzle tag from the equipment. However, I can't select it to zoom in on the nozzle with this tag. Could someone help me fix this code or provide suggestions?
Thank you !
This is my code
private static List<ObjectId> GetObjectsWithNozzleComponentTag(string nozzleComponentTag)
{
List<ObjectId> objectIds = new List<ObjectId>();
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord;
foreach (ObjectId objId in btr)
{
DBObject dbObj = tr.GetObject(objId, OpenMode.ForRead);
if (dbObj != null && dbObj is BlockReference blockRef)
{
using (EquipmentHelper eqHelper = new EquipmentHelper())
{
var equipInfor = eqHelper.RetrieveEquipmentFromInstance(blockRef.ObjectId);
if (equipInfor != null && equipInfor is EquipmentType eqType)
{
var nozzles = eqType.Nozzles;
if (nozzles != null)
{
foreach (var nozzle in nozzles)
{
var tagProperty = nozzle.PortProperties.FirstOrDefault(prop => prop.Name == "Tag");
if (tagProperty != null && tagProperty.Value == nozzleComponentTag)
{
objectIds.Add(objId);
break;
}
}
}
}
}
}
}
tr.Commit();
}
return objectIds;
}