AutoCAD Plant 3D Forum
Welcome to Autodesk’s AutoCAD Plant 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Plant 3D topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How can I get objects with a nozzle tag?

0 REPLIES 0
Reply
Message 1 of 1
traiduong014969
133 Views, 0 Replies

How can I get objects with a nozzle tag?

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;
}

 

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report