Get Document Information Example (VBA)
This example shows how to get the title and
document type of the active document.
'---------------------------------------------
Sub ModelInfo( )
' Define variable used to hold the SldWorks
object
Dim swApp As
Object
' Define variable used to hold the ModelDoc
object
Dim Model As
Object
Dim TopName
As String
' Constant enumerators
Const swDocPART
= 1
Const swDocASSEMBLY
= 2
Const swDocDRAWING
= 3
' Create or attach to SolidWorks session.
Because you are grabbing the active document, this example requires that
SolidWorks be running and have a document already loaded.
Set swApp =
CreateObject("SldWorks.Application")
Set Model =
swApp.ActiveDoc
' Check to see if a document is loaded
If Model Is
Nothing Then
Exit Sub
End if
If (Model.GetType <> swDocDRAWING) Then
swApp.SendMsgToUser ("This is not a drawing")
Else
Let TopName
= Model.GetTitle
End If
End Sub