AutoCAD P&ID
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Symbol style used / graphical symbol / .net interface
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Any luminaries out there know how you can get access to the symbol style that is currently used for an asset (e.g. a valve) in AutoCAD P&ID?
When you create an asset type in the P&ID Class definitions interface (e.g. a Valve) you have to assign a 'symbol' to the item so that, when you select it from something like a palette, it is inserted. However, you can have multiple symbols for each Class Definition. This prevents having to have a different class definition (i.e. Valve) in your palette for every variation of that type of valve (e.g. Jacketed, Close Bored, Non-Return, etc.). If you have 10 different types of valves, and you do, if you have a different class defintion for each variation, you'll wind up with 60 or more items in your tool palette for each variation.
While that is problem enough, because Autodesk, in all of their wisdom, doesn't have the substitution palette working on the interface, it is actually impractical to select one of 60 items on your tool palette, because on any monitor worth using, the symbols are so small, that you can't read them. You have to wait for the tool-tips to work. So... doesn't work.
I want to solve this problem by querying the drawing through a .NET program that will determine the symbol that is currently being utilized by each asset. But the actual symbol currently being used by an asset is not accessible from any interface that I can see. It is not recorded in the database, and it is not recorded in the .NET interface of the asset. You can see it on the properties palette. It's shown under the 'Styles' heading with the property 'Graphical style', along with every other property that goes to describe the asset. But it's the only property that isn't shown anywhere else.
So where is it recorded? Does anyone know of a way that you can determine what graphical symbol is being used by an asset without using the AutoCAD properties interface? How do you access it from the .NET interface?
Solved! Go to Solution.
Re: Symbol style used / graphical symbol / .net interface
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Anyone?
Re: Symbol style used / graphical symbol / .net interface
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Asset.StyleId
you can read more in the documentation
Check out my blog http://lazcad.com
Re: Symbol style used / graphical symbol / .net interface
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
That's what I thought too. It would make sense. Even in the documentation, it indicates that the asset links to a blocktable record. But when I try to cast the StyleID to a BlockTableRecord, it doesn't work.
There would seem to be some intermediate object that needs to have the styleid cast to it, and that then presumably, contains the BlockTableRecord object. I just can't find what that is.
Basically, this doesn't work...
BlockTableRecord oabtr = (BlockTableRecord)tr.GetObject(oa.StyleId, OpenMode.ForRead);
... where tr is the transaction, and oa is the Asset object.
Do you have any idea what the intermediate object is?
Re: Symbol style used / graphical symbol / .net interface
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
The documentation also has the following code...
//C# using Autodesk.ProcessPower.Styles Database db = AcadApp.DocumentManager.MdiActiveDocument.Database; Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; ObjectId entId = ed.GetEntity("Pick an ASSET: ").ObjectId; Autodesk.AutoCAD.DatabaseServices.TransactionManag er tm = db.TransactionManager; using (Transaction tr = tm.StartTransaction()) { Asset asset = (Asset)tm.GetObject(entId, OpenMode.ForRead, false); if (asset == null) return; Style style = (Style)tm.GetObject(asset.StyleId, OpenMode.ForRead); string sMsg = "\nStyle: " + style.Name; sMsg += "\n " + style.ClassName; sMsg += "\n " + style.Description; sMsg += "\n " + style.SymbolName; ed.WriteMessage(sMsg); }
... but do you have any idea which .dll contains the Style type? I have an AssetStyle object, but that's a variable, not a type.
Re: Symbol style used / graphical symbol / .net interface
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
PnPCommonDbxMgd.dll
Check out my blog http://lazcad.com
Re: Symbol style used / graphical symbol / .net interface
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
You, my dear sir, are a beautiful beautiful man. I can now use the symbol styles the way that I need to, and simply extract them later on. I'll build the interface that takes these values and match them up with the assets in the database later.
Here is the code if anyone is interested....
[Autodesk.AutoCAD.Runtime.CommandMethod("ListAsset Styles")]
public void ListAssetStyles()
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.D ocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord .ModelSpace], OpenMode.ForWrite);
BlockTableRecordEnumerator btre = btr.GetEnumerator();
while (btre.MoveNext()) {
Entity oEnt = (Entity)tr.GetObject(btre.Current, OpenMode.ForRead);
if (oEnt.ToString() == "Autodesk.ProcessPower.PnIDObjects.Asset") {
Asset oa = (Asset)tr.GetObject(btre.Current, OpenMode.ForRead);
Style oas = (Style)tr.GetObject(oa.StyleId, OpenMode.ForRead);
ed.WriteMessage(oa.TagValue + " - " + oas.SymbolName + "\n");
}
}
}
}
Re: Symbol style used / graphical symbol / .net interface
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Asset has a BlockTableRecord property that has the ObjectId to the block definition. Normally it is assigned when the asset is given a StyleId since the block name is specified with the style. However, the BlockTableRecord property is available to override the block in the style. This override mechanism is used with the PIDCONVERT command.
[CommandMethod("LISTSTYLE", CommandFlags.Modal)]
public static void ListStyle()
{
Editor oEditor = AcadApp.DocumentManager.MdiActiveDocument.Editor;
PromptEntityOptions oPromptOptions = new PromptEntityOptions("Select an object");
PromptEntityResult oPromptResult = oEditor.GetEntity(oPromptOptions);
if (oPromptResult.Status != PromptStatus.OK)
{
return;
}
Database oDB = AcadApp.DocumentManager.MdiActiveDocument.Database ;
TransactionManager oTxMgr = oDB.TransactionManager;
using (Transaction oTx = oTxMgr.StartTransaction())
{
DBObject obj = oTx.GetObject(oPromptResult.ObjectId, OpenMode.ForRead);
Asset oAsset = obj as Asset;
/* Get the style's object id
*/
ObjectId styleId = oAsset.StyleId;
if (!styleId.IsNull)
{
/* Display the style's name
*/
Style oStyle = (Style)oTx.GetObject(styleId, OpenMode.ForRead);
string strMsg = "\n" + oStyle.Name;
oEditor.WriteMessage(strMsg);
/* If it is an asset style then display the block name
*/
AssetStyle oAssetStyle = oStyle as AssetStyle;
if (oAssetStyle != null)
{
ObjectId btrId = oAssetStyle.BlockTableRecord;
BlockTableRecord oBTR = (BlockTableRecord) oTx.GetObject(btrId, OpenMode.ForRead);
strMsg = "\n" + oBTR.Name;
oEditor.WriteMessage(strMsg);
}
}
oTx.Commit();
}
}

Jorge Lopez
Software Architect
Autodesk Plant Solutions
Autodesk, Inc.
