AutoCAD P&ID General Discussion

AutoCAD P&ID General Discussion

Reply
Contributor
anthonyperks8274
Posts: 25
Registered: ‎01-30-2011
Message 1 of 8 (651 Views)
Accepted Solution

Symbol style used / graphical symbol / .net interface

651 Views, 7 Replies
04-30-2012 09:02 PM

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?

PnPCommonDbxMgd.dll

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();
}
}

 

 

styles1.jpg

styles2.jpg

Contributor
anthonyperks8274
Posts: 25
Registered: ‎01-30-2011
Message 2 of 8 (618 Views)

Re: Symbol style used / graphical symbol / .net interface

05-02-2012 06:03 PM in reply to: anthonyperks8274

Anyone?

*Expert Elite*
Rave.Tam
Posts: 204
Registered: ‎05-19-2011
Message 3 of 8 (610 Views)

Re: Symbol style used / graphical symbol / .net interface

05-03-2012 01:45 AM in reply to: anthonyperks8274

Asset.StyleId

 

you can read more in the documentation

If my post answers your question, please click the "Accept as Solution" button.

Check out my blog http://lazcad.com
Contributor
anthonyperks8274
Posts: 25
Registered: ‎01-30-2011
Message 4 of 8 (596 Views)

Re: Symbol style used / graphical symbol / .net interface

05-03-2012 04:45 PM in reply to: Rave.Tam

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?

Contributor
anthonyperks8274
Posts: 25
Registered: ‎01-30-2011
Message 5 of 8 (595 Views)

Re: Symbol style used / graphical symbol / .net interface

05-03-2012 04:56 PM in reply to: anthonyperks8274

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.TransactionManager 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.

 

 

*Expert Elite*
Rave.Tam
Posts: 204
Registered: ‎05-19-2011
Message 6 of 8 (590 Views)

Re: Symbol style used / graphical symbol / .net interface

05-03-2012 06:02 PM in reply to: anthonyperks8274

PnPCommonDbxMgd.dll

If my post answers your question, please click the "Accept as Solution" button.

Check out my blog http://lazcad.com
Contributor
anthonyperks8274
Posts: 25
Registered: ‎01-30-2011
Message 7 of 8 (584 Views)

Re: Symbol style used / graphical symbol / .net interface

05-03-2012 06:48 PM in reply to: Rave.Tam

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("ListAssetStyles")]
        public void ListAssetStyles()
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.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");
                    }
                }
            }
        }

 

 

 

Employee
lopezjo
Posts: 102
Registered: ‎07-26-2007
Message 8 of 8 (566 Views)

Re: Symbol style used / graphical symbol / .net interface

05-04-2012 08:38 AM in reply to: anthonyperks8274

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();
    }
}

 

 

styles1.jpg

styles2.jpg



Jorge Lopez
Software Architect
Autodesk Plant Solutions
Autodesk, Inc.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

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

New AutoCAD P&ID Category!

The AutoCAD P&ID forum has moved into it's very own category page, and can no longer be found within the Additional Product Forums.

Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!