Get Active Sheet Set Properties

Get Active Sheet Set Properties

drobertsY4GL3
Enthusiast Enthusiast
2,158 Views
7 Replies
Message 1 of 8

Get Active Sheet Set Properties

drobertsY4GL3
Enthusiast
Enthusiast

In a similar post, the sheet set IAcSMComponent  was cast to an AcSmSheet to access the sheet set properties GetName() GetNumber() etc. In my case it returns a NullReferenceException. I suspect this is because  the component "Deck" is a subset.

How can I get access to the sheets inside of "Deck" to get the sheet set properties?

 

SheetSetSnippet.PNG

 public void GetSheetSetProperties()
        {
            var sheetSetManager = new AcSmSheetSetMgr();
            var databaseEnum = sheetSetManager.GetDatabaseEnumerator();
            // Get the first database in list.
            AcSmDatabase database = databaseEnum.Next();
            database.LockDb(database);
            // Get the sheet set in the database.
            AcSmSheetSet sheetSet = database.GetSheetSet();       
            var sheetEnum = sheetSet.GetSheetEnumerator();

            // This gets the main component named "Deck" in the example tree.
            var component = sheetEnum.Next();


            #region DoesNotWork
            // Cast component to dummy sheet to get properties.
            var dummySheet = component as AcSmSheet;

            // Creates: System.NullReferenceException: 'Object reference not set to an instance of an object.'
            string ssName = dummySheet.GetName();
            string ssNumber = dummySheet.GetNumber();
            #endregion

            // TODO: Get the actual sheets i.e. the sheets under "Deck"

        }

Thank you.

0 Likes
Accepted solutions (1)
2,159 Views
7 Replies
Replies (7)
Message 2 of 8

JTBWorld
Advisor
Advisor

See https://blog.jtbworld.com/2005/01/sheet-set-manager-api-code-sample-for.html for how the logic is. 


Jimmy Bergmark
JTB World - Software development and consulting for CAD and license usage reports
https://jtbworld.com

0 Likes
Message 3 of 8

drobertsY4GL3
Enthusiast
Enthusiast
Accepted solution

Thanks Jimmy.

 

Looking at you're example, my suspicion was right. I needed to drill down to the AcSmSubset to get the actual sheet properties. What I was really trying to access however was the sheet set project info and thought perhaps I could use the sheets to do it. Is there another way?

 

Below is the working code for getting subset sheets:

 public void GetSheetSetProperties()
        {
            var sheetSetManager = new AcSmSheetSetMgr();
            var databaseEnum = sheetSetManager.GetDatabaseEnumerator();
            // Get the first database in list.
            AcSmDatabase database = databaseEnum.Next();
            //database.LockDb(database);
            // Get the sheet set in the database.
            AcSmSheetSet sheetSet = database.GetSheetSet();       
            var sheetEnum = sheetSet.GetSheetEnumerator();
            var sheet = new AcSmSheet();
            string sheetSetName = "";
            string sheetSetNumber = "";
            bool sheetFound = false;

            // Get sheet from component or subcomponents.
            var component = sheetEnum.Next();
            while (component != null && sheetFound != true)
            {
                if (component.GetTypeName() == "AcSmSheet")
                {
                    sheet = component as AcSmSheet;
                    sheetFound = true;
                }
                
                else if (component.GetTypeName() == "AcSmSubset")
                {
                    var subset = component as AcSmSubset;
                    var subComponent = subset.GetSheetEnumerator().Next();
                    while (subComponent != null && sheetFound != true)
                    {                  
                            if (subComponent.GetTypeName() == "AcSmSheet")
                            {
                                sheet = subComponent as AcSmSheet;
                                sheetFound = true;                             
                                sheetSetName = sheet.GetName();
                                sheetSetNumber = sheet.GetNumber();
                            }

                        subComponent = subset.GetSheetEnumerator().Next();
                    }
                }

                component = sheetEnum.Next();
            }    
        }

 

 

 

0 Likes
Message 4 of 8

JTBWorld
Advisor
Advisor
0 Likes
Message 5 of 8

drobertsY4GL3
Enthusiast
Enthusiast

Thank you for the posts.

They work great for accessing custom properties.

How does one access the "regular" properties? In particular I am after the ones in the Project Control Section i.e. project number, project name.

 

Custom Property snippet:

 string propName = "";
            AcSmCustomPropertyValue propValue;
            
            // Get custom propery enumerator from sheet set.
            var propEnum = sheetSet.GetCustomPropertyBag().GetPropertyEnumerator();
            propEnum.Next(out propName, out propValue);
            while (propName != null)
            {
                propEnum.Next(out propName, out propValue);
            }

 

0 Likes
Message 6 of 8

JTBWorld
Advisor
Advisor

Look at the documentation here http://help.autodesk.com/view/OARX/2020/ENU/?guid=GUID-56F608AE-CEB3-471E-8A64-8C909B989F24 and specifically http://help.autodesk.com/view/OARX/2020/ENU/?guid=GUID-D28ACEC0-BA5A-4568-B05F-7B60EBD08AF7


Jimmy Bergmark
JTB World - Software development and consulting for CAD and license usage reports
https://jtbworld.com

0 Likes
Message 7 of 8

drobertsY4GL3
Enthusiast
Enthusiast

Thank you again Jimmy.

You've been extraordinarily patient and of great help!

0 Likes
Message 8 of 8

drobertsY4GL3
Enthusiast
Enthusiast

The root of the problem I discovered is that the methods I needed are missing.

Please see the breakout post below:

https://forums.autodesk.com/t5/net/missing-acsmsheetset-getprojectname-acsmsheetset/td-p/9815753 

 

Thank you.

0 Likes