.NET

.NET

Reply
Active Contributor
110000474593
Posts: 29
Registered: ‎09-24-2012
Message 1 of 4 (321 Views)
Accepted Solution

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

321 Views, 3 Replies
05-23-2013 01:13 PM

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

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.

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 2 of 4 (313 Views)

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

05-23-2013 03:48 PM in reply to: 110000474593

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.

Active Contributor
110000474593
Posts: 29
Registered: ‎09-24-2012
Message 3 of 4 (292 Views)

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

05-23-2013 11:28 PM in reply to: DiningPhilosopher

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"?

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 4 of 4 (283 Views)

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

05-24-2013 04:27 AM in reply to: 110000474593

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.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.