• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    AutoCAD P&ID

    Reply
    Contributor
    anthonyperks8274
    Posts: 25
    Registered: ‎01-30-2011
    Accepted Solution

    Symbol style used / graphical symbol / .net interface

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

    Please use plain text.
    Contributor
    anthonyperks8274
    Posts: 25
    Registered: ‎01-30-2011

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

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

    Anyone?

    Please use plain text.
    Distinguished Contributor
    Rave.Tam
    Posts: 144
    Registered: ‎05-19-2011

    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
    Please use plain text.
    Contributor
    anthonyperks8274
    Posts: 25
    Registered: ‎01-30-2011

    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?

    Please use plain text.
    Contributor
    anthonyperks8274
    Posts: 25
    Registered: ‎01-30-2011

    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.

     

     

    Please use plain text.
    Distinguished Contributor
    Rave.Tam
    Posts: 144
    Registered: ‎05-19-2011

    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
    Please use plain text.
    Contributor
    anthonyperks8274
    Posts: 25
    Registered: ‎01-30-2011

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

     

     

     

    Please use plain text.
    Employee
    Posts: 100
    Registered: ‎07-26-2007

    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.

    Please use plain text.