6 Replies Latest reply on Feb 15, 2013 6:17 PM by Artem Taturevych

    Does anybody know how to acces ConfigurationSpecificCustomProperties with the DocumentManagerAPI ?

    Checkcheck Master

      Hi there !

       

      Does anybody know how to access ConfigurationSpecificCustomProperties with the DocumentManagerAPI ?

       

       

      Greetings !

        • Re: Does anybody know how to acces ConfigurationSpecificCustomProperties with the DocumentManagerAPI ?
          Artem Taturevych

          Hi,

           

          Use these methods:

           

          SwDMConfiguration::GetCustomPropertyNames.

          SwDMConfiguration::AddCustomProperty.

          SwDMConfiguration::GetCustomPropertyCount.

          SwDMConfiguration::GetCustomProperty.

          SwDMConfiguration::GetCustomPropertyCount.

           

          where the SwDMConfiguration retrieved from ISwDMDocument::ConfigurationManager->ISwDMConfigurationMgr::GetConfigurationByName

           

          Check this example which shows how to traverse configurations and custom properties via DM API:

           

          http://help.solidworks.com/2012/English/api/swdocmgrapi/get_configuration_information_example_vbnet.htm

          __________________________

          Regards,

          Artem Taturevych

          Application Engineer at Intercad

          http://intercad.com.au/

          Tel: +61 2 9454 4444

            • Re: Does anybody know how to acces ConfigurationSpecificCustomProperties with the DocumentManagerAPI ?
              Checkcheck Master

              Thanks Artem for your reaction,

               

              I can't get it running to retrieve the ConfigSpecificCustomProperties.

              Tried a lot of things but don't get it...

              Can you please explain me how to set up this in VBA code ?

               

              Thanks in advance.

               

               

               

              Greetings !

                • Re: Does anybody know how to acces ConfigurationSpecificCustomProperties with the DocumentManagerAPI ?
                  Artem Taturevych

                  Here is the vba code. You should add the reference to DM dll to your macro (SwDocumentMgr <Version> Type Library)

                   

                  Sub main()

                   

                      Const sLicenseKey As String = "<YOUR KEY>" 'Specify license key

                      Const sDocFileName As String = "C:\Part1.sldprt"  'Specify document

                   

                      Dim swClassFact As SwDMClassFactory

                      Dim swDocMgr As SwDMApplication3

                      Dim swDoc As SwDMDocument15

                      Dim swCfgMgr As SwDMConfigurationMgr

                      Dim vCfgNameArr As Variant

                      Dim vCfgName As String

                      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

                   

                      If (nDocType <> SwDmDocumentType.swDmDocumentDrawing) Then

                   

                          Set swClassFact = CreateObject("SwDocumentMgr.SwDMClassFactory")

                          Set swDocMgr = swClassFact.GetApplication(sLicenseKey)

                          Set swDoc = swDocMgr.GetDocument(sDocFileName, nDocType, False, nRetVal)

                          Set swCfgMgr = swDoc.ConfigurationManager

                     

                          vCfgNameArr = swCfgMgr.GetConfigurationNames

                   

                          Dim i As Integer

                          For i = 0 To UBound(vCfgNameArr)

                             

                              vCfgName = vCfgNameArr(i)

                              Set swCfg = swCfgMgr.GetConfigurationByName(vCfgName)

                   

                              ProcessConfigCustomProperties swCfg

                             

                          Next

                         

                          swDoc.CloseDoc

                         

                      End If

                   

                  End Sub

                   

                  Sub ProcessConfigCustomProperties(ByVal swCfg As SwDMConfiguration13)

                   

                      Dim vCustPropNameArr As Variant

                      Dim vCustPropName As String

                      Dim sCustPropStr As String

                      Dim nPropType As Long

                     

                      vCustPropNameArr = swCfg.GetCustomPropertyNames

                     

                      Debug.Print swCfg.Name2

                     

                      If IsEmpty(vCustPropNameArr) Then Exit Sub

                   

                          Dim i As Integer

                          For i = 0 To UBound(vCustPropNameArr)

                              vCustPropName = vCustPropNameArr(i)

                              sCustPropStr = swCfg.GetCustomProperty(vCustPropName, nPropType)

                              Debug.Print ("-" & vCustPropName & " <" & nPropType & "> = " & sCustPropStr)

                          Next

                   

                          Debug.Print ("")

                   

                  End Sub