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