ACAD 2018/VBA/Start Tab

ACAD 2018/VBA/Start Tab

Anonymous
Not applicable
1,561 Views
4 Replies
Message 1 of 5

ACAD 2018/VBA/Start Tab

Anonymous
Not applicable

I have a VBA routine that fires on AcadDocument.Activate. It runs just fine on drawing tabs except when selecting the Start Tab. When it hits this statement ThisDrawing.GetVariable("cprofile") it throws this error: "Failed to get the Document object". I suspect this tab is not a true Document Object but I cant find an object/method to test for the Start Tab.

Any suggestions?

 

Ray C.

0 Likes
Accepted solutions (1)
1,562 Views
4 Replies
Replies (4)
Message 2 of 5

Ed__Jobe
Mentor
Mentor
Accepted solution

There's not a whole lot you can do in the zero document state. My solution is to use structured error handling to catch and handle the errors. That alone won't get you cprofile in all situations, but I included it because I don't know what else you are doing in zero doc state. To get the current profile, don't use the Get variable method, which belongs to the Document object, use the AcadApplication.Preferences.Profile object.

 

In a regular module that instantiates the class module:

Dim x As New clsEvents 'events stored here

Public Sub AutoRun()
    On Error GoTo Err_Control
    Set x.app = AcadApplication
    If AcadApplication.Documents.Count >= 0 Then Set x.Doc = ThisDrawing

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, , "AutoRun"
        Err.Clear
        Resume Exit_Here
    End Select
End Sub

The class module:

Option Explicit

Public WithEvents app As AcadApplication
Public WithEvents Doc As AcadDocument



Private Sub app_AppActivate()
    
    On Error GoTo Err_Control
DisplayProfile:
'MsgBox Doc.GetVariable("cprofile")
MsgBox app.Preferences.Profiles.ActiveProfile Exit_Here: Exit Sub Err_Control: Select Case Err.Number Case 91 'ThisDrawing object not available Err.Clear Resume Exit_Here Case -2145320900 'Failed to get the Document object Err.Clear Resume Exit_Here Case Else MsgBox Err.Number & ", " & Err.Description, , "App.Activate" 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 3 of 5

Anonymous
Not applicable

So that tab represents the Zero Doc state. That helps a bunch. I will capture the error and get past it.

Thanks a bunch

 

Ray C.

0 Likes
Message 4 of 5

Ed__Jobe
Mentor
Mentor

I don't know that I would say it "represents" zero doc state. It's just the only layout available in zero doc state. In .NET you can create other layouts that aren't connected to a document.

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 5

Anonymous
Not applicable

Understood. Too bad there is not a Tab Object that could be captured to test if it associated to a document.

Anyway, I'm good. the error catch seems to be doing the trick. 

Thanks again.

0 Likes