7 Replies Latest reply on Jun 29, 2014 5:34 AM by Deepak Gupta

    How to get the Value / Text Expression?

    Yong Ning

      03.jpg

       

      Help me

      Hope get Value / Text Expression ------- "SW-Mass@@a4@b.SLDASM"

       

      Value / Text Expression →  "SW-Mass@@a4@b.SLDASM"

       

      ************************

       

      follow code   → don't get Value/Text Expression→ "SW-Mass@@a4@b.SLDASM"

      GetCustomProperties(vPropName, vPropValue, vPropType)→mm <30> = 45.00

      → result is

      vPropName → mm

      vPropValue → 45.00

      vPropType  → 30

       

       

      *****************************************

      Option Explicit

       

      Public Enum swCustomInfoType_e

          swCustomInfoUnknown = 0

          swCustomInfoText = 30       '  VT_LPSTR

          swCustomInfoDate = 64       '  VT_FILETIME

          swCustomInfoNumber = 3      '  VT_I4

          swCustomInfoYesOrNo = 11    '  VT_BOOL

      End Enum

       

      Sub main()

       

          Dim swApp                   As SldWorks.SldWorks

          Dim swModel                 As SldWorks.ModelDoc2

          Dim swConfig                As SldWorks.Configuration

          Dim vConfName               As Variant

          Dim vPropName               As Variant

          Dim vPropValue              As Variant

          Dim vPropType               As Variant

          Dim nNumProp                As Long

          Dim i                       As Long

          Dim j                       As Long

          Dim bRet                    As Boolean

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

       

          Debug.Print "File = " + swModel.GetPathName

       

          vConfName = swModel.GetConfigurationNames

          For i = 0 To UBound(vConfName)

              Set swConfig = swModel.GetConfigurationByName(vConfName(i))

       

              nNumProp = swConfig.GetCustomProperties(vPropName, vPropValue, vPropType)

       

              Debug.Print "  Config       = " & vConfName(i)

              For j = 0 To nNumProp - 1

                  Debug.Print "    " & vPropName(j) & " <" & vPropType(j) & "> = " & vPropValue(j)

              Next j

              Debug.Print "  ---------------------------"

          Next i

      End Sub

      ***************

      Private Sub Main2()

       

          Dim SwApp As SldWorks.SldWorks, SwModel As SldWorks.ModelDoc2

          Dim vConfigNameArr, vConfigName

          Dim Str, ii, PrtAsm, Conf

          Set SwApp = Application.SldWorks

          Set SwModel = SwApp.ActiveDoc

          vConfigNameArr = SwModel.GetConfigurationNames

          ''

          For ii = 0 To UBound(vConfigNameArr)

              vConfigName = vConfigNameArr(ii)

              With SwModel

                 .ShowConfiguration vConfigName

                 Str = "SW-Mass@@" & vConfigName & "@" & SwModel.GetTitle

                 .AddCustomInfo3 vConfigName, "mm", 30, "12"

                 .CustomInfo2(vConfigName, "mm") = """" & Str & """"

              End With

          Next ii

      End Sub

        • Re: How to get the Value / Text Expression?
          Deepak Gupta

          Your codes worked fine for me for getting the value/text expression.

           

          For your second code, in order to add the correct expression and get the desired output value, use these codes:

           

          Sub main2()

              Dim swApp                  As SldWorks.SldWorks

              Dim swModel                As SldWorks.ModelDoc2

              Dim sModelName             As String

              Dim vConfigName            As Variant

              Dim sConfigName            As String

              Dim str                    As String

              Dim i                      As Long

           

              Set swApp = CreateObject("SldWorks.Application")

              Set swModel = swApp.ActiveDoc

           

              sModelName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)

           

              vConfigName = swModel.GetConfigurationNames

               For i = 0 To UBound(vConfigName)

                  sConfigName = vConfigName(i)

           

                  str = Chr(34) & "SW-Mass@@" & sConfigName & "@" & sModelName & Chr(34)

                  swModel.AddCustomInfo3 sConfigName, "mm", 30, str

              Next i

          End Sub

           

          If the files extension for known files are set to hidden, then SwModel.GetTitle won't yield the extension and hence the expressions fails.