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

    Export Cut-List Via Macro

    Mark Coville

      Hello,

       

      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?

       

      Thanks,

      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:

           

          http://help.solidworks.com/2013/English/api/sldworksapi/get_custom_properties_for_cut-list_item_example_vb.htm

          http://help.solidworks.com/2013/English/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.iassemblydoc~getcomponents.html

          http://help.solidworks.com/2013/English/api/sldworksapi/Traverse_Assembly_at_Component_and_Feature_Level_Example_VB.htm

           

          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()

                  swASC.Select

                  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
                                          Else
                                              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
                                              Loop
                                          End If
                                      End If
                                      Set swFeature = swFeature.GetNextFeature()
                                  Loop
                          Next i
              End With
              swApp.SendMsgToUser ("DONE")
              Call ClearData
              End
              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