Get Configuration Information Example (VB.NET)
This example shows how to use the SOLIDWORKS Document Manager API to get
configuration-related information for an external part document whose custom
properties were transferred from the original part document.
' --------------------------------------------------------------------------------
' Preconditions:
' 1. Read the SOLIDWORKS Document Manager API Getting Started topic
' and ensure that the required DLLs are registered.
' 2. Copy and paste this module into a VB.NET console application in Microsoft
' Visual Studio.
' 3. Add the Solidworks.Interop.swdocumentmgr.dll reference to the project:
' a. Right-click the solution in the Solution Explorer.
' b. Click Add Reference.
' c. Click Browse.
' d. Click
install_dir\api\redist\CLR2\Solidworks.Interop.swdocumentmgr.dll.
' e. Click Add.
' f. Click OK.
' 4. In the code, substitute your_license_key with your SOLIDWORKS Document
' Manager license key.
' 5. Press F5 to run the program.
'
' Postconditions:
' 1. Examine the Immediate Window.
' 2. Verify that both fromparent+ prefaced and non-prefaced custom property
' values are shown.
'---------------------------------------------------------------------------------
Imports SolidWorks.Interop.swdocumentmgr
Module Module1
Sub ProcessDocCustomProperties(ByVal swDoc As SwDMDocument17)
Dim vCustPropNameArr As Object
Dim vCustPropName As Object
Dim sCustPropStr As String
Dim sCustPropStrWOPrefix As String
Dim nPropType As Long
vCustPropNameArr = swDoc.GetCustomPropertyNames : If IsNothing(vCustPropNameArr) Then Exit Sub
Debug.Print(" Document Custom Properties:")
For Each vCustPropName In vCustPropNameArr
sCustPropStr = swDoc.GetCustomProperty(vCustPropName, nPropType)
Debug.Print(" Prefaced = " & vCustPropName & " <" & nPropType & "> = " & sCustPropStr)
sCustPropStrWOPrefix = swDoc.GetCustomProperty2(vCustPropName, nPropType)
Debug.Print(" Not Prefaced = " & vCustPropName & " <" & nPropType & "> = " & sCustPropStrWOPrefix)
Debug.Print("")
Next
Debug.Print("")
End Sub
Sub ProcessConfigCustomProperties(ByVal swCfg As SwDMConfiguration14)
Dim vCustPropNameArr As Object
Dim vCustPropName As Object
Dim sCustPropStr As String
Dim sCustPropStrWOPrefix As String
Dim nPropType As Long
vCustPropNameArr = swCfg.GetCustomPropertyNames
If IsNothing(vCustPropNameArr) Then Exit Sub
Debug.Print(" Configuration Custom Properties:")
For Each vCustPropName In vCustPropNameArr
sCustPropStr = swCfg.GetCustomProperty(vCustPropName, nPropType)
Debug.Print(" Prefaced = " & vCustPropName & " <" & nPropType & "> = " & sCustPropStr)
sCustPropStrWOPrefix = swCfg.GetCustomProperty2(vCustPropName, nPropType)
Debug.Print(" Not Prefaced = " & vCustPropName & " <" & nPropType & "> = " & sCustPropStrWOPrefix)
Debug.Print("")
Next
Debug.Print("")
End Sub
Sub main()
Const sLicenseKey As String = "your_license_key"
Const sDocFileName As String = "C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2017\tutorial\api\ExternalReferencedPart.sldprt"
Dim swClassFact As SwDMClassFactory
Dim swDocMgr As SwDMApplication
Dim swDoc As SwDMDocument19
Dim swCfgMgr As SwDMConfigurationMgr
Dim vCfgNameArr As Object
Dim vCfgName As Object
Dim swCfg As SwDMConfiguration14
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 project 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) : Debug.Assert(SwDmDocumentOpenError.swDmDocumentOpenErrorNone = 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 (string)
= " & swDoc.CreationDate)
Debug.Print(" CreationDate (numeric)
= " & swDoc.CreationDate2)
Debug.Print(" Keywords = " & swDoc.Keywords)
Debug.Print(" LastSavedBy = " & swDoc.LastSavedBy)
Debug.Print(" LastSavedDate (string)
= " & swDoc.LastSavedDate)
Debug.Print(" LastSavedDate (numeric) = " & swDoc.LastSavedDate2)
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("")
ProcessConfigCustomProperties(swCfg)
Next
End If
End Sub
End Module