.NET

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

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

259 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

Valued Mentor
Posts: 370
Registered: ‎05-06-2012
Message 2 of 4 (251 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
Posts: 29
Registered: ‎09-24-2012
Message 3 of 4 (230 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
Posts: 370
Registered: ‎05-06-2012
Message 4 of 4 (221 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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community