6 Replies Latest reply on Sep 27, 2016 9:53 AM by Mario Zahren

    Newbie problem - how to get "description" property

    Nick Tanner

      Hi folks,

      This is a very low level problem, but it seems almost impossible to search for as almost everything seems to contain the word "Description". I've found numerous ways of extracting custom properties and feature properties, but not the boring old "Description" value. Help!


      I'm attempting to modify the generic "Save as PDF" macro so that it creates a PDF file name using "Solidworks filename - Description.pdf" in the original directory.

      But I can't find the code equivalent of NewFilePath = PathNoExtention + Part.GetDescription & "pdf" (I know this is wrong)


      So what's the simple way of doing this?

        • Re: Newbie problem - how to get "description" property
          William Cruz

          I don’t understand your question completely so this is a shot in the dark. If you are referring to a “Description” value under “Property Name” in the document properties, then you should follow the following link to get that info:

          Get / Set:



          If this isn’t what you need, maybe try rephrasing the question.

            • Re: Newbie problem - how to get "description" property
              Nick Tanner

              Hi William,

              I'm running visual basic, and yes, I am having trouble with wording this post!

              Basically I want to add the $PRP:"Description" value to the filename of a PDF. Just using "Description" in a macro doesn't seem to return anything.

                • Re: Newbie problem - how to get "description" property
                  Mario Zahren

                  Hi Nick,

                  try this:

                  Set swApp = GetObject(, "SldWorks.Application")

                  Set Part = swApp.ActiveDoc

                  ModType = swApp.ActiveDoc.GetType


                  If Not Part Is Nothing Then

                      InfoCount = Part.GetCustomInfoCount2("")            ' how many cust. Prop. in active Dok?

                      InfoNames = Part.GetCustomInfoNames2("")            ' read all cust. Props in Variant...


                          For K = 0 To InfoCount - 1                     


                              If InfoNames(K) = "Sprachcode" Then


                              Retval = Part.DeleteCustomInfo2("", InfoNames(K))    ' delete some cust. Props

                              End If

                          Next K


                          Retval = Part.AddCustomInfo3("", "Sprachcode", swCustomInfoText, sLNG) ' write cust. Prop.

                          Retval = Part.AddCustomInfo3("", "Dateiname", swCustomInfoText, "$PRP:" & Chr(34) & "SW-Dateiname(File Name)" & Chr(34))  ' write cust. Prop. too

                          Revision = Part.GetCustomInfoValue("", "Revision") ' read cust. Prop.

                  End If



                    • Re: Newbie problem - how to get "description" property
                      Nick Tanner

                      Hi Mario,

                      I'm not familiar with those commands, but is that code to populate custom properties?


                      I've found this code in the API help documentation which creates variables val and valout with the contents of the Description field. Next step is to attempt shoe-horning it into my existing macro

                      Option Explicit
                      Dim swApp As SldWorks.SldWorks
                      Dim swModel As ModelDoc2
                      Dim swModelDocExt As ModelDocExtension
                      Dim swCustProp As CustomPropertyManager
                      Dim val As String
                      Dim valout As String
                      Dim bool As Boolean
                      Sub main()
                      Set swApp = Application.SldWorks
                      Set swModel = swApp.ActiveDoc
                      Set swModelDocExt = swModel.Extension
                      ' Get the custom property data
                      Set swCustProp = swModelDocExt.CustomPropertyManager("")
                      bool = swCustProp.Get4("Description", False, val, valout)

                      End Sub
                        • Re: Newbie problem - how to get "description" property
                          Mario Zahren


                          please create a new macro, replace the code with this example-code and start debbuging (F8):



                          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 vConfigNameArr                  As Variant

                              Dim vConfigName                     As Variant

                              Dim vCustInfoNameArr                As Variant

                              Dim vCustInfoName                   As Variant

                              Dim bRet                            As Boolean

                              Set swApp = Application.SldWorks

                              Set swModel = swApp.ActiveDoc


                              Debug.Print "File = " & swModel.GetPathName


                              vConfigNameArr = swModel.GetConfigurationNames


                              ' Is empty if a drawing becasue configurations not supported on drawings

                              If IsEmpty(vConfigNameArr) Then

                                  ReDim vConfigNameArr(0)

                                  vConfigNameArr(0) = ""


                                  ' Add a blank string for the nonconfiguration-specific custom properties

                                  ReDim Preserve vConfigNameArr(UBound(vConfigNameArr) + 1)

                              End If


                              For Each vConfigName In vConfigNameArr

                                  Debug.Print "  " & vConfigName


                                  vCustInfoNameArr = swModel.GetCustomInfoNames2(vConfigName)

                                  If Not IsEmpty(vCustInfoNameArr) Then

                                      For Each vCustInfoName In vCustInfoNameArr

                                          Debug.Print "    " & vCustInfoName

                                          Debug.Print "      Type     = " & swModel.GetCustomInfoType3(vConfigName, vCustInfoName)

                                          Debug.Print "      Value    = " & swModel.GetCustomInfoValue(vConfigName, vCustInfoName)

                                          Debug.Print "      Text     = " & swModel.CustomInfo2(vConfigName, vCustInfoName)


                                  End If

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


                          End Sub


                          During debugging you can see how to get the Property values by configuration.

                          Hope it helps.



                  • Re: Newbie problem - how to get "description" property
                    Nick Tanner


                    Description = Part.GetCustomInfoValue("", "DESCRIPTION")


                    That's all I was looking for. Thanks for giving it a go.