.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Acad P&ID - Iterate through all model spaces of project drawings

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
110000474593
709 Views, 3 Replies

Acad P&ID - Iterate through all model spaces of project drawings

Hello everyone,

 

I hope someone can help me with this. I'm writing a self made command for Autocad P&ID 2014 in C#. With this method, I want to search for a tag in my project and draw a circle around it. At the moment, I can give in my self made command, named 'GETTAG', give in a tagvalue in the editor and then my self made command searches for this tag in the modelspace of the 'MdiActiveDocument'. If the tag is found, a circle is drawn around the tag. This is achieved by searching the BlockTableRecord of the ModelSpace of the current drawing.

 

editor = AcadApp.DocumentManager.MdiActiveDocument.Editor;
DB = AcadApp.DocumentManager.MdiActiveDocument.Database;

 

trans.TransactionManager transActionManager = DB.TransactionManager;
            using (Transaction transAction = transActionManager.StartTransaction())
            {
                BlockTable blockTable = (BlockTable)transAction.GetObject(DB.BlockTableId, OpenMode.ForRead);
                BlockTableRecord blockTableRecord = (BlockTableRecord)transAction.GetObject(blockTable["*Model_Space"], OpenMode.ForRead);

                // An P&Id object is a Linesegment or an Asset
                BlockTableRecordEnumerator iter = blockTableRecord.GetEnumerator();
                while (iter.MoveNext())
                {
                    DBObject dbObject = transAction.GetObject(iter.Current, OpenMode.ForRead);

                    LineSegment lineSegm = dbObject as LineSegment;
                    if (lineSegm != null)
                    {
                        if (lineSegm.TagValue == tagName)
                        {
                            strMsg = "\nLinesegment with tagvalue: " + lineSegm.TagValue + " is from class: " + lineSegm.ClassName;
                            editor.WriteMessage(strMsg);
                        }
                    }

                    Asset asset = dbObject as Asset;
                    if (asset != null)
                    {
                        if (asset.TagValue == tagName)
                        {
                            strMsg = "\nAsset with tagvalue: " + asset.TagValue + " is from class: " + asset.ClassName;
                            editor.WriteMessage(strMsg);
                        }
                    }
                }

 

But what if I give in a tagvalue, that is placed on a other drawing then the active drawing? Then my method has to check every drawing which belong to the project and then, if the tag is found, my method has to open this drawing and then draw a circle around the tag.

 

My big question is, how do I iterate trough all the drawings of my project (whitout opening the drawings) and search for the correct tag? Can I acces the modelspaces of the drawings without opening the drawings (with Documentmanager.Open())

 

If someone can help me, please let me know.

 

Regards

3 REPLIES 3
Message 2 of 4

Database.ReadDwgFile() allows you to open an access DWG files without having to open them in the AutoCAD editor.

 

You would have to use that to search for something in a file that isn't open in the editor.

Message 3 of 4

Ok, many thanks for your reply. I'll try if this works. On which database should I execute the method "ReadDwgFile()"? The database of the active drawing? Or do I have to create an variable of the type "Database"?

Message 4 of 4

You have to create a Database using the constructor (new Database(), and use the correct parameters for reading in a file, and you must ensure that the Database is disposed when you are done using it.

 

Search here for 'ReadDwgFile()' and you should find some examples.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost