Get Configuration Information Example (VB.NET)
This example shows how to
get configuration-related information from a part or assembly document.
'----------------------------------------------------------------------------
' Preconditions:
' 1. Read the SolidWorks Document Manager API Getting Started topic
' and ensure that the required DLLs have been registered.
' 2. Copy and paste this code into a VB.NET console application
' in Microsoft Visual Studio.
' 3. Add Solidworks.Interop.swdocumentmgr.dll to the references
' of the project:
' a. Right-click the solution in Solution Explorer.
' b. Select Add Reference.
' c. Click the Browse tab.
' d. Select:
' <SolidWorks_install_dir>\api\redist\Solidworks.Interop.swdocumentmgr.dll
' 4. Substitute <your_license_code> with your SolidWorks
' Document Manager license key.
' 5. Ensure that the specified part exists.
' 6. Open an Immediate window.
'
' Postconditions: Inspect the Immediate window for configuration
information.
'----------------------------------------------------------------------------
Imports
SolidWorks.Interop.swdocumentmgr
Imports
System
Imports
System.Diagnostics
Module
Module1
Sub
ProcessDocCustomProperties(ByVal
swDoc As
SwDMDocument15)
Dim
vCustPropNameArr As
Object
Dim
vCustPropName As
Object
Dim
sCustPropStr As
String
Dim
nPropType As
Long
vCustPropNameArr = swDoc.GetCustomPropertyNames
: If
IsNothing(vCustPropNameArr) Then
Exit
Sub
Debug.Print(" Custom
Properties:")
For
Each
vCustPropName In
vCustPropNameArr
sCustPropStr = swDoc.GetCustomProperty(vCustPropName,
nPropType)
Debug.Print(" "
& vCustPropName & " <"
& nPropType & "> = "
& sCustPropStr)
Next
Debug.Print("")
End
Sub
Sub
ProcessConfigCustomProperties(ByVal
swCfg As
SwDMConfiguration13)
Dim
vCustPropNameArr As
Object
Dim
vCustPropName As
Object
Dim
sCustPropStr As
String
Dim
nPropType As
Long
vCustPropNameArr = swCfg.GetCustomPropertyNames
If
IsNothing(vCustPropNameArr) Then
Exit
Sub
Debug.Print(" Custom
Properties:")
For
Each
vCustPropName In
vCustPropNameArr
sCustPropStr = swCfg.GetCustomProperty(vCustPropName,
nPropType)
Debug.Print(" "
& vCustPropName & " <"
& nPropType & "> = "
& sCustPropStr)
Next
Debug.Print("")
End
Sub
Sub
main()
Const
sLicenseKey As
String
= "<your_license_code>"
'Specify license key
Const
sDocFileName As
String
= "<SolidWorks_install_dir>\samples\tutorial\weldments\weldment_box2.sldprt" 'Specify
document
Dim
swClassFact As
SwDMClassFactory
Dim
swDocMgr As
SwDMApplication3
Dim
swDoc As
SwDMDocument15
Dim
swCfgMgr As
SwDMConfigurationMgr
Dim
vCfgNameArr As
Object
Dim
vCfgName As
Object
Dim
swCfg As
SwDMConfiguration13
Dim
nDocType As
Long
Dim
nRetVal As
Long
'
Determine type of SolidWorks file based on file extension
If
InStr(LCase(sDocFileName), "sldprt")
> 0 Then
nDocType =
SwDmDocumentType.swDmDocumentPart
ElseIf
InStr(LCase(sDocFileName), "sldasm")
> 0 Then
nDocType =
SwDmDocumentType.swDmDocumentAssembly
ElseIf
InStr(LCase(sDocFileName), "slddrw")
> 0 Then
nDocType =
SwDmDocumentType.swDmDocumentDrawing
Else
'
Not a SolidWorks file
nDocType =
SwDmDocumentType.swDmDocumentUnknown
' So cannot open
Exit
Sub
End
If
'
Because drawing documents do not have configurations,
'
only continue running the macro if the document
'
is a part or assembly document
If
(nDocType <> SwDmDocumentType.swDmDocumentDrawing)
Then
swClassFact = CreateObject("SwDocumentMgr.SwDMClassFactory")
swDocMgr = swClassFact.GetApplication(sLicenseKey)
swDoc = swDocMgr.GetDocument(sDocFileName, nDocType,
False,
nRetVal)
swCfgMgr = swDoc.ConfigurationManager
Debug.Print("File = "
& swDoc.FullName)
Debug.Print(" ActiveCfgName =
" & swCfgMgr.GetActiveConfigurationName)
Debug.Print("")
Debug.Print(" Version =
" & swDoc.GetVersion)
Debug.Print(" Author
= " & swDoc.Author)
Debug.Print(" Comments
= " & swDoc.Comments)
Debug.Print(" CreationDate
= " & swDoc.CreationDate)
Debug.Print(" Keywords
= " & swDoc.Keywords)
Debug.Print(" LastSavedBy =
" & swDoc.LastSavedBy)
Debug.Print(" LastSavedDate =
" & swDoc.LastSavedDate)
Debug.Print(" Subject =
" & swDoc.Subject)
Debug.Print(" Title =
" & swDoc.Title)
Debug.Print(" LastUpdateStamp =
" & swDoc.GetLastUpdateStamp)
Debug.Print(" IsDetachedDrawing =
" & swDoc.IsDetachedDrawing)
Debug.Print("")
ProcessDocCustomProperties(swDoc)
vCfgNameArr = swCfgMgr.GetConfigurationNames
For
Each
vCfgName In
vCfgNameArr
swCfg = swCfgMgr.GetConfigurationByName(vCfgName)
Debug.Print(" "
& vCfgName)
Debug.Print(" Description =
" & swCfg.Description)
Debug.Print(" ParentCfgName =
" & swCfg.GetParentConfigurationName)
Debug.Print(" LastUpdateStamp =
" & swCfg.GetLastUpdateStamp)
Debug.Print(" Type
as defined in swDmConfigurationType = "
& swCfg.type)
Debug.Print("")
ProcessConfigCustomProperties(swCfg)
Next
End
If
End
Sub
End
Module