1 Reply Latest reply on Mar 19, 2014 4:06 PM by Keith Rice

    Export Weldment "Cut List" To A Text File

    Darren Smith

      Can anybody help????

       

      If I have a weldment (SDLPRT), see the attached part taken from "SolidWorks Samples".

       

      Can I use a API macro to automatically export a "cut list" to a text file that can be opened with notepad.exe?

       

      I need the "Part Description", "Length" and "Quantity"

       

      Any help would be very much appreciated!!!!

       

      Many thanks in advance.

       

      Darren

        • Re: Export Weldment "Cut List" To A Text File
          Keith Rice

          Darren,

           

          This code will get all cut list custom properties:

           

          ====

           

          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2

          Dim swFeat As SldWorks.Feature

          Dim swCustPropMgr As SldWorks.CustomPropertyManager

          Dim vPropNames As Variant, vPropTypes As Variant, vPropValues As Variant

          Dim i As Integer

           

          Sub main()

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Set swFeat = swModel.FirstFeature

              While Not swFeat Is Nothing

                  If swFeat.GetTypeName2 = "CutListFolder" Then

                      Set swCustPropMgr = swFeat.CustomPropertyManager

                      swCustPropMgr.GetAll vPropNames, vPropTypes, vPropValues

                      If IsEmpty(vPropNames) = False Then

                          For i = 0 To UBound(vPropNames)

                              Debug.Print swFeat.Name

                              Debug.Print "    Property name: " & vPropNames(i)

                              Debug.Print "    Property types: " & vPropTypes(i)

                              Debug.Print "    Property values: " & vPropValues(i)

                          Next i

                      End If

                  End If

                  Set swFeat = swFeat.GetNextFeature

              Wend

          End Sub

           

          ====

           

          You can modify it as you need to extract particular custom properties. If you want to get the evaluated values then you'll need to use ICustomPropertyManager::Get3 or something like that rather than GetAll, which only gets unevaluated values.

           

          To export to a text file:

          • In VBA you can use the FileSystemObject. Just google "filesystemobject create text file" and you'll find lots of examples.
          • In .NET you can use StreamWriter. Check this out.

           

          Keith

          SolidWorks API Video Tutorials