VB.NET Sheet set program confusion

VB.NET Sheet set program confusion

ajehresmann
Contributor Contributor
401 Views
0 Replies
Message 1 of 1

VB.NET Sheet set program confusion

ajehresmann
Contributor
Contributor

I'm trying to write a plugin that will renumber a sheetset dst using vba.net and the ARX SDK but
I'm having trouble figuring out how to use the sheet set objects from the ARX API I think I'm using but I'm not really sure what it is that I'm using because the only documentation I saw with sheet set type objects in it was for ActiveX but I downloaded the ARK SDK and reference that API in my code I think so I'm not sure if this is exactly the right forum to post to but hopefully all this wall text makes sense and I'm in the right place.


So basically I want to loop through the dst and renumber each sheet using an incrementing integer and the AcSmSheet objects' SetNumber() method that I read it has in the ARX documentation but I don't understand how to use an enumerator to go through the sheetset to find the sheet objects in it and when I do find a sheet it doesn't seem to have a SetNumber() method. I think I just don't understand how the objects are structured like what is inside a sheet set object and sheet set database and why/how you have to use enumerators to access it's contents/components or why a sheet object doesn't seem to have the method I thought it would.  And I've been trying to read documentation to get a better understanding of how that all works but it's been pretty opaque in regards to sheet sets in particular so I'd really appreciate any guidance that could be given on to use the ARX SDK with VB.NET to work with sheet sets or any suggestions on better ways of implementing my project.

 

Imports System.IO
Imports ACSMCOMPONENTS24Lib
Imports Autodesk.AutoCAD.LayerManager.LayerFilter
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Windows

Public Class Class1
    <CommandMethod("Renum")>
    Public Sub Main()
        MsgBox("Step 1")

        ' Get a reference to the Sheet Set Manager object
        Dim sheetSetManager As IAcSmSheetSetMgr
        sheetSetManager = New AcSmSheetSetMgr

        ' Open a Sheet Set file
        Dim sheetSetDatabase As AcSmDatabase
        sheetSetDatabase = sheetSetManager.OpenDatabase("C:\Users\Alexander\Desktop\ssm project\sheet set test.dst", False)
        MsgBox(sheetSetDatabase.ToString + " sheet set db")
        MsgBox("Step 2")

        Dim sheetSet As AcSmSheetSet
        sheetSet = sheetSetDatabase.GetSheetSet()

        ' Get the objects in the sheet set
        Dim enumerator As IAcSmEnumPersist
        enumerator = sheetSetDatabase.GetEnumerator()

        ' Get the first object/item in the Enumerator
        Dim item As IAcSmPersist
        item = enumerator.Next()
        MsgBox(item.GetTypeName() + " item type name")
        MsgBox("Step 3")

        'tried using a property enumerator to loop through the properties of a sheet
        'Dim enumeratorProperty As IAcSmEnumProperty
        'enumeratorProperty = item.GetDatabase().GetSheetSet().GetCustomPropertyBag().GetPropertyEnumerator().Next

        Dim enumeratorSheet As IAcSmPersist
        enumeratorSheet = item.GetDatabase().GetSheetSet().GetSheetEnumerator.Next()
        'MsgBox(enumeratorSheet.GetTypeName() + " = sheet enumerator")
        'enumeratorSheet.SetNumber() ' AcSmSheet object should have a setnumber method why doesnt it work?

        ' Step through all the objects in the sheet set
        'Do While item IsNot Nothing
        Do While enumeratorSheet IsNot Nothing
            'Dim sheet As IAcSmSheet = Nothing ' initialize a null sheet
            Dim i As Integer = 1
            MsgBox("Step 4")

            MsgBox(enumeratorSheet.GetTypeName() + " sheet enumerator")

            If enumeratorSheet.GetTypeName() = "AcSmSheet" Then ' item is a sheet so now what? need to gets its properties, how? another enumerator to loop through the sheet properties for name type? or canjust setname on the sheet object? 
                'i += 1
                'sheet = item
                'sheet.SetNumber(CStr(i)) 'cast/convert string to integer
                'item.GetDatabase().GetSheetSet().GetCustomPropertyBag().GetPropertyEnumerator().Next()


                MsgBox("Step 5")

            End If

            ' Get the next Sheet
            'item = enumerator.Next()
            enumeratorSheet = item.GetDatabase().GetSheetSet().GetSheetEnumerator.Next() ' this isnt going to the next sheet, getting stuck?
            MsgBox("Step 6")
        Loop

        'MsgBox("Sheet set could not be opened for write.")

        ' close the sheet set
        sheetSetManager.Close(sheetSetDatabase)
        MsgBox("Step 7")
    End Sub

End Class

Apologies that my code is a mess but I'm just trying to figure out how everything works by toying around.
And visual studio won't let me debug my program because I don't have a driver file in the project solution I think so I've just been using print out messages to see how it's executing.


The flow of the program I think should go something like:
I create a a sheetset database object and make it open my dst file.
then I use the Getsheetset method to create a sheet set object
then I use an enumerator to loop the sheet objects in the sheet set object, changing the number of the sheets using the setNumber() method.
then I close the sheet set database.

 

But because I don't know how everything works I've done a bunch of possibly redundant or just incorrect things some of which I've commented out just to try and figure out how things work like creating a database enumerator and enumerating over both the sheet set database and the sheet set object. And the do while loop gets stuck between step 4 and 6 which I think is caused by the sheet enumerator not moving onto the next sheet in the set and for some reason it just crashes after step one when I ran it on another computer. But I can correct the logic of the code pretty easily once I figure out how all the ARX objects are structured and how to use their methods to work with them.

 

Sorry if that's unclear or too much information I just wanted to be as descriptive as possible what I'm trying to do and what I think my problems are.

 

Thank you very much.

0 Likes
402 Views
0 Replies
Replies (0)