Accessing Sheetset Manager from VBA in Access

Accessing Sheetset Manager from VBA in Access

SMMJRC90
Contributor Contributor
588 Views
7 Replies
Message 1 of 8

Accessing Sheetset Manager from VBA in Access

SMMJRC90
Contributor
Contributor

I have a VBA project in MS Access and I would like to access the AutoCAD SSM from that project. When running the code below, I get an error saying "trouble loading application" at the line where I try to set the objSheetSetManager using acadApp.GetInterfaceObject Method

 

(Set objSheetSetManager = acadApp.GetInterfaceObject("AcSmSheetSetMgr.Application"))

 

I am able to gain access to the SSM if I run code from within the AutoCAD VBA IDE so I know AcSMComponents is installed. Does anyone have any experience accessing the SSM from outside of AutoCAD?

 

Dim acadApp As AcadApplication
Dim objSheetSetManager As Object
Dim objSheetSetDB As Object
Dim sheetsetname As String

' Attempt to hook into an existing AutoCAD application
On Error Resume Next
Set acadApp = GetObject(, "AutoCAD.Application")

' If AutoCAD is not running, start it
If acadApp Is Nothing Then
Set acadApp = CreateObject("AutoCAD.Application")
End If
On Error GoTo 0

If acadApp Is Nothing Then
MsgBox "AutoCAD is not installed or failed to start!", vbCritical
Exit Sub
End If


' Attempt to access the Sheet Set Manager interface
Set objSheetSetManager = acadApp.GetInterfaceObject("AcSmSheetSetMgr.Application")

0 Likes
589 Views
7 Replies
Replies (7)
Message 2 of 8

Ed__Jobe
Mentor
Mentor

First, I would recommend reading this thread. Second, any time you feel the need to use On Error Resume Next, I highly suggest enclosing it is it's own sub/function. This is a good indicator that you have a separate task that should be separate. To set AcadApplication variable, use this function. 

Public Function GetAcad(Optional ver As String) As AcadApplication
    ' support multiple acad versions.
    'Sample ver for AutoCAD 2023 ' ".24.2"
    On Error Resume Next
    Dim acApp As AcadApplication
    Dim clsid As String
    clsid = "AutoCAD.Application"
    If Not ver = "" Then
        clsid = clsid & ver
    End If
    Set acApp = GetObject(, clsid)
    If acApp Is Nothing Then
        Set acApp = CreateObject(clsid)
    End If
    Set GetAcad = acApp
End Function

 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 8

SMMJRC90
Contributor
Contributor

Ed,

 

I agree that getting the AutoCAD object should be a separate function, in fact I do have a function that does that, I included that portion because I wanted to break my code down into something small to post, I have not had issues getting acadApp to populate. My issue is getting the .getinterfaceobject method to return a sheetsetmanager object. 

Steve 

0 Likes
Message 4 of 8

Ed__Jobe
Mentor
Mentor

I don't have time right now to try an idea I have, but in the meantime, see this post and read the rest of the thread. You need to understand how SSM works. You don't use getInterface. You create a New instance of the class and then open a database (i.e. dst). The problem is trying to do it outside of AutoCAD. This thread at theSwamp deals with creating an app that bypasses the SSM and reads the dst directly.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 8

norman.yuan
Mentor
Mentor

The Prog ID used in GetInterfaceObject() method, should be "AcSmComponents.AcSmSheetSetMgr.2x" (2x depending on AutoCAD version, not "AcSmSheetSetMgr.Application", I believe.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 6 of 8

Ed__Jobe
Mentor
Mentor

I tried a test in xl but was unable to create an ssm object outside of AutoCAD. You might have more success using .NET. i was working on a class that wraps the ssm and simplifies some tasks. It's based on an early project by @ambrosl that was presented at AU many years ago. I believe such a class could expose a ssm object. But perhaps the better route would be to use the method I linked to at theSwamp and access the dst directly instead of going through acad.

Public Sub Test()
    On Error GoTo Err_Control
    
    Dim acad As AcadApplication
    Set acad = AcadApplication  'Use in AutoCAD)
    Set acad = GetAcad()        'Use outside AutoCAD

    Dim ssm As New AcSmSheetSetMgr  'Use in AutoCAD
    'Dim ssm As AcSmSheetSetMgr  'Use outside AutoCAD
    'Use in outside AutoCAD
    'Tried to create ssm in acad context but it didn't work
'    Set ssm = acad.GetInterfaceObject("AcSmComponents.AcSmSheetSetMgr.25")
    Dim db As New AcSmDatabase
    
    Dim str1 As String
    str1 = "C:\users\???\Downloads\test1.dst"
    Set db = ssm.OpenDatabase(str1)
    
    Dim dbEnum As IAcSmEnumPersist
    Set dbEnum = db.GetEnumerator
    Dim item As IAcSmPersist
    Set item = dbEnum.Next
'    Dim shEnum As IAcSmEnumComponent
'    Dim csPr As AcSmSheetSet
'    Dim shValue As IAcSmComponent
'    Dim objs() As Object
'    Dim retObjs As Object
'
'
'
'    'On Error Resume Next
'    While Not item Is Nothing
'        If item.GetTypeName = "AcSmSheetSet" Then
'        Set csPr = item
'        Set shEnum = csPr.GetSheetEnumerator
'        Set shValue = shEnum.Next
'        While Not shValue Is Nothing
'            'On Error Resume Next
'            Set retObjs = shValue.GetDirectlyOwnedObjects(objs)
'            Set shValue = shEnum.Next
'        Wend
'        End If
'    Set item = dbEnum.Next
'    Wend


Exit_Here:
   Exit Sub
Err_Control:
   Select Case Err.Number
      'Add your Case selections here
   'Case Is = 1000
      'Handle error
      'Err.Clear
      'Resume Exit_Here
   Case Else
      MsgBox Err.Number & ", " & Err.Description, , "Test"
      Err.Clear
      Resume Exit_Here
   End Select
End Sub

 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 7 of 8

SMMJRC90
Contributor
Contributor

I tried several combinations that I found online (AcSmComponents.AcSMSheetSetMgr.2x, ect...) none of them worked. I have decided to call this code directly in the AutoCAD environment to eliminate this hurdle. I am able to get some basic interaction with the SSM but have been getting a run time error

 

"Automation error, the owner of the PerUser subscription is not logged on to the system specified"

 

I have checked an I am logged into the system as me. and the "fully qualified file path" is a network location and is not user dependent. The error occurs when I try to call .SetName. If I comment that line out, it runs fine. I know that I do not have error handling implemented. this is very early development and I am just trying to prove that I can get this to work before building it out completely with perfect coding practices. 

 

 

Below is the code that I am running within AutoCAD VBA

 

Sub OpenSheetSet()
   Dim objSSM As AcSmSheetSetMgr
   Dim objDB As AcSmDatabase
   Dim objSheetSet As AcSmSheetSet
   Dim objSheet As AcSmSheet

   Set objSSM = New AcSmSheetSetMgr
   Set objSSM = CreateObject("AcSmComponents.AcSmSheetSetMgr.24")
   Debug.Print "attempting to open"
   Set objDB = objSSM.OpenDatabase("fully qualified file path", True)
   Set objSheetSet = objDB.GetSheetSet
   Debug.Print "sheet set name: " & objSheetSet.GetName
   objSheetSet.SetName "Changed the Name"
   Debug.Print "sheet set name: " & objSheetSet.GetName

End Sub

 

Moderator Edit: Put code in code window.

0 Likes
Message 8 of 8

Ed__Jobe
Mentor
Mentor

First, all you need to do is create a new instance of ssm with the New keyword. You don't need the following line:

Set objSSM = CreateObject("AcSmComponents.AcSmSheetSetMgr.24")

 

If you read the inline comments in my code, you will see that I mentioned that you only use this version when creating an instance from outside the current thread, which as I spoke of elsewhere, doesn't work.

 

Second, I showed you in my last post how to open a sheetset and enumerate the sheets. 

Create a new ssm

Create a new db

set the db = ssm.Opendatabase

 

Finally, Jimmy Bergmark sells a SheetSet property editor. It can access shetsets outside of AutoCAD. He also does custom programming. If you contact him, maybe he has a COM api that will work with VBA.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes