2 Replies Latest reply on May 13, 2014 9:57 AM by Mark Coville

    Export Cut-List Via Macro

    Mark Coville



      I need to export a cut-list of a weldment to excel for import into an ERP system. I want to do this from the top level assembly since it would be easier to do it one shot. Would it be possible/faster/easier to traverse the assem then traverse every part for cut-list feature then export properties to excel or insert indented BOM then hide/delete rows that are not cut-list items then export to excel? Any ideas?



      Mark Coville

        • Re: Export Cut-List Via Macro
          Artem Taturevych

          Hello Mark,

          If you need to do this often I would definitely suggest macro otherwise it may not worth it. If you have programming skills you can combine several macros already available like this from Keith: http://www.cadsharp.com/macros/get-weldment-profile-and-cut-list-custom-properties-vba/


          as well as those can be useful:






          If you want a professional service to develop a macro for you please contact IC3D Development Team for a quote: http://ic3d.com.au/contact-us/


          Regards, Artem Taturevych | Snr. Developer | IC3D ANZ


          IC3DSteel – New Steel Solution for SolidWorks

          translationXpert – SolidWorks files language translator

          LinkedIn - SolidWorks API Group

            • Re: Export Cut-List Via Macro
              Mark Coville

              Hello Artem,


              Below is what I have managed to scrap together so far. I am having an issue with sheet metal parts, if there is multiple configurations it returns the last saved configuration. Is there a way to get the cut-list properties of the current config?




              Dim swApp               As SldWorks.SldWorks
              Dim swModel             As SldWorks.ModelDoc2
              Dim swASC               As SldWorks.AdvancedSelectionCriteria
              Dim swAssy              As SldWorks.AssemblyDoc
              Dim boolstatus          As Boolean
              Dim xlApp               As Excel.Application
              Dim xlWorkbook          As Excel.Workbook
              Dim swConfig            As String
              Dim ErpResVal           As String
              Dim LengthResVal        As String
              Dim BBAreaResVal        As String
              Dim FamilyResVal        As String
              Dim ValOut              As String
              Dim ConversionUnit      As String
              Dim QtyEntered          As String
              Dim swComp              As SldWorks.Component2
              Dim swSelMgr            As SldWorks.SelectionMgr
              Dim i                   As Integer
              Dim ExcelPath           As String
              Dim swCPM               As SldWorks.CustomPropertyManager
              Dim BodyFolder          As SldWorks.BodyFolder
              Dim swPart              As SldWorks.PartDoc
              Dim swFeature           As SldWorks.Feature
              Dim CutFolder           As SldWorks.BodyFolder
              Dim CutListQty          As Integer
              Dim nRetval             As Long

              Sub main()

              Set swApp = Application.SldWorks
              Set swModel = swApp.ActiveDoc
              Set swAssy = swModel
              nRetval = swAssy.ResolveAllLightWeightComponents(False)
              ExcelPath = ""

              Set xlApp = CreateObject("Excel.Application")
              xlApp.Visible = True
              Set xlWorkbook = xlApp.Workbooks.Open(ExcelPath)
              j = 1
              With xlWorkbook.Worksheets(1)
                  Set swASC = swAssy.GetAdvancedSelection
                  boolstatus = swASC.LoadCriteria()


                  Set swSelMgr = swModel.SelectionManager
                      For i = 1 To swSelMgr.GetSelectedObjectCount
                          Set swComp = swSelMgr.GetSelectedObject(i)
                              Set swModel = swComp.GetModelDoc2
                              swConfig = swComp.ReferencedConfiguration
                              Set swPart = swModel
                              Set swFeature = swPart.FirstFeature
                              Do While Not swFeature Is Nothing
                              If "SolidBodyFolder" = swFeature.GetTypeName2 Then
                              Set BodyFolder = swFeature.GetSpecificFeature2
                              boolstatus = BodyFolder.SetAutomaticCutList(True)
                              boolstatus = BodyFolder.UpdateCutList()
                              End If
                                  If swFeature.GetTypeName2 = "CutListFolder" Then
                                      Set BodyFolder = swFeature.GetSpecificFeature2()
                                      CutListQty = BodyFolder.GetBodyCount
                                      Set swCPM = swFeature.CustomPropertyManager
                                      boolstatus = swCPM.Get4("ErpFamily", False, ValOut, FamilyResVal)
                                      boolstatus = swCPM.Get4("ErpNumber", False, ValOut, ErpResVal)
                                      boolstatus = swCPM.Get4("LENGTH", False, ValOut, LengthResVal)
                                      boolstatus = swCPM.Get4("Bounding Box Area", False, ValOut, BBAreaResVal)
                                      LengthResVal = Replace(LengthResVal, """", "")
                                      BBAreaResVal = Replace(BBAreaResVal, """", "")
                                          If FamilyResVal = "01" Then
                                              QtyEntered = LengthResVal
                                              ConversionUnit = "IN"
                                          End If
                                          If FamilyResVal = "02" Then
                                              QtyEntered = BBAreaResVal
                                              ConversionUnit = "PO2"
                                          End If
                                          If CutListQty = "0" Then
                                              Do Until CutListQty = 0
                                                  .Cells(j + 1, 1) = filename
                                                  .Cells(j + 1, 2) = ErpResVal
                                                  .Cells(j + 1, 3) = QtyEntered
                                                  .Cells(j + 1, 4) = ConversionUnit
                                                  j = j + 1
                                                  CutListQty = CutListQty - 1
                                          End If
                                      End If
                                      Set swFeature = swFeature.GetNextFeature()
                          Next i
              End With
              swApp.SendMsgToUser ("DONE")
              Call ClearData
              End Sub

              Private Sub ClearData()
              Set xlWorkbook = Nothing
              Set xlApp = Nothing
              Set swComp = Nothing
              Set swApp = Nothing
              Set swModel = Nothing
              Set swAssy = Nothing
              Set swSelMgr = Nothing
              End Sub