18 Replies Latest reply on Jun 11, 2018 8:33 AM by Marco Crociani

    Macro to Update the Cutlist Properties for all Components

    Peter Kennedy

      I have a macro that will current cycle through a single cut list component when selected using:

       

      Set swApp = Application.SldWorks

      Set swModel = swApp.ActiveDoc

       

      Set swSelMgr = swModel.SelectionManager

      Set swFeat = swSelMgr.GetSelectedObject6(1, -1)

       

      What I would like to do is have the macro run through all the cutlist components and update if possible, is there a way to have the macro loop through all components that are in the cutlist?

       

      Thanks.

        • Re: Macro to Update the Cutlist Properties for all Components
          Deepak Gupta

          Peter, can you try the #TASK tool. It has inbuilt update cut list tool.

           

            • Re: Macro to Update the Cutlist Properties for all Components
              Peter Kennedy

              Are you able to make adjustments to the script? I have a current macro that runs and creates a file name for the part however I just want to add this file name to each cut list component so in our BOM the user can see what file the weldment is from. I currently add it manually each time and since I already have the macro adding the file name to the whole part custom properties I would like to try and add it to each weldment cut list property as well.

                • Re: Macro to Update the Cutlist Properties for all Components
                  Deepak Gupta

                  You can create you own scripts using #TASK OR can run your own macro.

                   

                  Share/Upload your macro and I can try to create the macro Or script for you.

                    • Re: Macro to Update the Cutlist Properties for all Components
                      Peter Kennedy

                      I've attached the macro, it's extremely basic.

                       

                      Like I mentioned above it more for when I have a mutlibody part and it adds the file name to each cutlist custom property, right now I have to select each list and run the macro where if the system could just cycle through all cutlists that would be ideal.

                       

                      Thanks for the help.

                        • Re: Macro to Update the Cutlist Properties for all Components
                          Deepak Gupta

                          Peter, try this macro. And if you need to batch run it, then you can use it with #TASK

                           

                          Option Explicit
                              Dim swApp               As SldWorks.SldWorks
                              Dim swModel             As SldWorks.ModelDoc2
                              Dim swFeat              As SldWorks.Feature
                              Dim swCustPropMgr       As SldWorks.CustomPropertyManager
                              Dim FileNumber          As String
                              
                          Sub main()
                              On Error Resume Next
                                
                              Set swApp = Application.SldWorks
                              Set swModel = swApp.ActiveDoc
                              Set swCustPropMgr = swModel.Extension.CustomPropertyManager("")
                              swCustPropMgr.Get4 "File Number", False, FileNumber, ""
                                  
                              Set swFeat = swModel.FirstFeature
                                  Do While Not swFeat Is Nothing
                                      If swFeat.GetTypeName() = "CutListFolder" Then
                                                  Set swCustPropMgr = swFeat.CustomPropertyManager
                                                  swCustPropMgr.Add3 "File Number", swCustomInfoText, FileNumber, 1
                                      End If
                                  Set swFeat = swFeat.GetNextFeature
                                  Loop
                          End Sub
                          
                            • Re: Macro to Update the Cutlist Properties for all Components
                              Peter Kennedy

                              Perfect, thank you so much that's exactly what I needed. Thanks.

                                • Re: Macro to Update the Cutlist Properties for all Components
                                  Marco Crociani

                                  Hello everybody,

                                   

                                  i use this macro, it is very useful.

                                   

                                  But now i would like to take a field already present in the cutting list (in my case I would like to use the property "sheet thickness").

                                   

                                  After I'd like to overwrite the property "Description"  with:

                                  a part of text that is always the same ("Sheetmetal") + the property "sheet thickness" of the funtion sheetmetal (that we have taken before) + a part of text that is always the same ("mm")

                                   

                                  The result I would like is:

                                  Description --> Sheetmetal 5 mm

                                   

                                  Thanks for the help.

                                    • Re: Macro to Update the Cutlist Properties for all Components
                                      Deepak Gupta

                                      You can use

                                      swCustPropMgr.Add3 "Description", swCustomInfoText, "Sheetmetal " & sheet thickness &  " mm", 1 

                                        • Re: Macro to Update the Cutlist Properties for all Components
                                          Marco Crociani

                                          there is an error on sheet thickness

                                          Expected: end instruction

                                           

                                            • Re: Macro to Update the Cutlist Properties for all Components
                                              Deepak Gupta

                                              Marco Crociani wrote:

                                               

                                              there is an error on sheet thickness

                                              Expected: end instruction

                                               

                                              You need to obtain the value of sheet thickness, assign it to a variable and replace the sheet thickness in this line

                                               

                                              swCustPropMgr.Add3 "Description", swCustomInfoText, "Sheetmetal " & sheet thickness &  " mm", 1

                                               

                                              If you are not sure how to do that then upload a file with updated value of description.

                                                • Re: Macro to Update the Cutlist Properties for all Components
                                                  Marco Crociani

                                                  This is the macro:

                                                   

                                                  Option Explicit

                                                      Dim swApp               As SldWorks.SldWorks

                                                      Dim swModel             As SldWorks.ModelDoc2

                                                      Dim swFeat              As SldWorks.Feature

                                                      Dim swCustPropMgr       As SldWorks.CustomPropertyManager

                                                      Dim FileNumber          As String

                                                      Dim CODICE              As String

                                                      Dim CODICE_FINALE       As String

                                                      Dim UM                  As String

                                                      Dim PESO                As String

                                                      Dim DESCRIZIONE         As String

                                                       

                                                  Sub main()

                                                      On Error Resume Next

                                                         

                                                      Set swApp = Application.SldWorks

                                                      Set swModel = swApp.ActiveDoc

                                                      Set swCustPropMgr = swModel.Extension.CustomPropertyManager("")

                                                      swCustPropMgr.Get4 "CODICE", False, CODICE, ""

                                                      swCustPropMgr.Get4 "CODICE_FINALE", False, CODICE_FINALE, ""

                                                      swCustPropMgr.Get4 "UM", False, UM, ""

                                                      swCustPropMgr.Get4 "PESO", False, PESO, ""

                                                      swCustPropMgr.Get4 "DESCRIZIONE", False, DESCRIZIONE, ""

                                                     

                                                      Set swFeat = swModel.FirstFeature

                                                          Do While Not swFeat Is Nothing

                                                              If swFeat.GetTypeName() = "CutListFolder" Then

                                                                          Set swCustPropMgr = swFeat.CustomPropertyManager

                                                                          swCustPropMgr.Add3 "CODICE", swCustomInfoText, "KLAM.", 1

                                                                          swCustPropMgr.Add3 "CODICE_FINALE", swCustomInfoText, "KLAM.", 1

                                                                          swCustPropMgr.Add3 "UM", swCustomInfoText, "KG", 1

                                                                          swCustPropMgr.Add3 "PESO", swCustomInfoText, Chr(34) & "SW-MASS" & Chr(34), 1

                                                                          swCustPropMgr.Add3 "DESCRIZIONE", swCustomInfoText, "Sheetmetal " & sheet thickness &  " mm", 1

                                                                         

                                                              End If

                                                          Set swFeat = swFeat.GetNextFeature

                                                          Loop

                                                  End Sub

                                                   

                                                  in the link below the file:

                                                  Dropbox - Parte5.SLDPRT

                                                   

                                                  In the image below, I highlighted the two properties (in italian: Spessore lamiera = Sheet thickness / Descrizione = Description)

                                                    • Re: Macro to Update the Cutlist Properties for all Components
                                                      Deepak Gupta

                                                      Try these codes

                                                       

                                                      Option Explicit
                                                          Dim swApp               As SldWorks.SldWorks
                                                          Dim swModel             As SldWorks.ModelDoc2
                                                          Dim swFeat              As SldWorks.Feature
                                                          Dim swCustPropMgr       As SldWorks.CustomPropertyManager
                                                          Dim FileNumber          As String
                                                          Dim CODICE              As String
                                                          Dim CODICE_FINALE       As String
                                                          Dim UM                  As String
                                                          Dim PESO                As String
                                                          Dim DESCRIZIONE         As String
                                                          Dim sThickness          As String
                                                          Dim swBodyFolder        As SldWorks.BodyFolder
                                                      Sub main()
                                                      
                                                          On Error Resume Next
                                                      
                                                      
                                                          Set swApp = Application.SldWorks
                                                          Set swModel = swApp.ActiveDoc
                                                          Set swCustPropMgr = swModel.Extension.CustomPropertyManager("")
                                                          swCustPropMgr.Get4 "CODICE", False, CODICE, ""
                                                          swCustPropMgr.Get4 "CODICE_FINALE", False, CODICE_FINALE, ""
                                                          swCustPropMgr.Get4 "UM", False, UM, ""
                                                          swCustPropMgr.Get4 "PESO", False, PESO, ""
                                                          swCustPropMgr.Get4 "DESCRIZIONE", False, DESCRIZIONE, """"
                                                          
                                                          
                                                          Set swFeat = swModel.FirstFeature
                                                              Do While Not swFeat Is Nothing
                                                                  If swFeat.GetTypeName() = "CutListFolder" Then
                                                                  Set swBodyFolder = swFeat.GetSpecificFeature2
                                                                  swBodyFolder.UpdateCutList
                                                                  
                                                                              Set swCustPropMgr = swFeat.CustomPropertyManager
                                                                              swCustPropMgr.Get4 "Sheet Metal Thickness", False, "", sThickness
                                                                             
                                                                              swCustPropMgr.Add3 "CODICE", swCustomInfoText, "KLAM.", 1
                                                                              swCustPropMgr.Add3 "CODICE_FINALE", swCustomInfoText, "KLAM.", 1
                                                                              swCustPropMgr.Add3 "UM", swCustomInfoText, "KG", 1
                                                                              swCustPropMgr.Add3 "PESO", swCustomInfoText, Chr(34) & "SW-MASS" & Chr(34), 1
                                                                              swCustPropMgr.Add3 "DESCRIZIONE", swCustomInfoText, "Sheetmetal " & sThickness & " mm", 1
                                                                  End If
                                                              Set swFeat = swFeat.GetNextFeature
                                                              Loop
                                                      
                                                      
                                                      End Sub
                                                      

                                                       

                                                      And as a side note, you can always attach file here on the forums. Check #18 of Forum Posting on how to attach files while replying to a post.

                                                        • Re: Macro to Update the Cutlist Properties for all Components
                                                          Marco Crociani

                                                          Great,

                                                          in this way, it works!!!!

                                                           

                                                          A last request, I would like you to write these properties only when the function is a Sheet metal function.

                                                          How can it be done?

                                                           

                                                          Thank you so much for your help

                                                            • Re: Macro to Update the Cutlist Properties for all Components
                                                              Deepak Gupta

                                                              The macro can check if the active part is sheet metal or not. Is this what you need?

                                                                • Re: Macro to Update the Cutlist Properties for all Components
                                                                  Marco Crociani

                                                                  I use multi-body part, the macro does a check if the function is sheetmetal then writes the properties otherwise (for example a body was created with a simple extrusion) it does nothing.

                                                                   

                                                                  sorry, maybe with an image I can explain myself better

                                                                   

                                                                  • Re: Macro to Update the Cutlist Properties for all Components
                                                                    Marco Crociani

                                                                    Hello Deepak,

                                                                     

                                                                    yes, is it possible to check if the body is a sheet metal or not??

                                                                     

                                                                    another question:

                                                                    i want to write a property called "TIPO_LAM_1"  in this way:

                                                                    IF the property "number of folds" is 0

                                                                    THEN write "PIANA"

                                                                    ELSE write "PIEGATA"

                                                                     

                                                                    is it possible?

                                                                     

                                                                    thank you very much if you can solve these 2 problems

                                                                      • Re: Macro to Update the Cutlist Properties for all Components
                                                                        Deepak Gupta

                                                                        Marco Crociani wrote:

                                                                         

                                                                        Hello Deepak,

                                                                         

                                                                        yes, is it possible to check if the body is a sheet metal or not??

                                                                        Yes you can do that using IsSheetMetal Method (IBody2)

                                                                         

                                                                        i want to write a property called "TIPO_LAM_1" in this way:

                                                                        IF the property "number of folds" is 0

                                                                        THEN write "PIANA"

                                                                        ELSE write "PIEGATA"

                                                                         

                                                                        is it possible?

                                                                        This can be done via a simple if condition after you get the property value.

                                                                          • Re: Macro to Update the Cutlist Properties for all Components
                                                                            Marco Crociani

                                                                            Excuse me but I'm very scarce

                                                                             

                                                                            This is my macro, can you write the modification?

                                                                            Thank you very very much!!

                                                                             

                                                                            Option Explicit

                                                                                Dim swApp               As SldWorks.SldWorks

                                                                                Dim swModel             As SldWorks.ModelDoc2

                                                                                Dim swFeat              As SldWorks.Feature

                                                                                Dim swCustPropMgr       As SldWorks.CustomPropertyManager

                                                                                Dim FileNumber          As String

                                                                                Dim CODICE              As String

                                                                                Dim CODICE_FINALE       As String

                                                                                Dim UM                  As String

                                                                                Dim PESO                As String

                                                                                Dim DESCRIZIONE         As String

                                                                                Dim sThickness          As String

                                                                                Dim swBodyFolder        As SldWorks.BodyFolder

                                                                             

                                                                            Sub main()

                                                                             

                                                                                On Error Resume Next

                                                                             

                                                                             

                                                                                Set swApp = Application.SldWorks

                                                                                Set swModel = swApp.ActiveDoc

                                                                                Set swCustPropMgr = swModel.Extension.CustomPropertyManager("")

                                                                                swCustPropMgr.Get4 "CODICE", False, CODICE, """"

                                                                                swCustPropMgr.Get4 "CODICE_FINALE", False, CODICE_FINALE, """"

                                                                                swCustPropMgr.Get4 "UM", False, UM, ""

                                                                                swCustPropMgr.Get4 "PESO", False, PESO, ""

                                                                                swCustPropMgr.Get4 "DESCRIZIONE", False, DESCRIZIONE, """"

                                                                                 

                                                                                 

                                                                                Set swFeat = swModel.FirstFeature

                                                                                    Do While Not swFeat Is Nothing

                                                                                        If swFeat.GetTypeName() = "CutListFolder" Then

                                                                                        Set swBodyFolder = swFeat.GetSpecificFeature2

                                                                                        swBodyFolder.UpdateCutList

                                                                                         

                                                                                                    Set swCustPropMgr = swFeat.CustomPropertyManager

                                                                                                    swCustPropMgr.Get4 "Spessore lamiera", False, "", sThickness

                                                                                                    

                                                                                                    swCustPropMgr.Add3 "CODICE", swCustomInfoText, "KLAM." & sThickness, 1

                                                                                                    swCustPropMgr.Add3 "CODICE_FINALE", swCustomInfoText, "KLAM." & sThickness, 1

                                                                                                    swCustPropMgr.Add3 "UM", swCustomInfoText, "KG", 1

                                                                                                    swCustPropMgr.Add3 "PESO", swCustomInfoText, Chr(34) & "SW-MASS" & Chr(34), 1

                                                                                                    swCustPropMgr.Add3 "DESCRIZIONE", swCustomInfoText, "Lamiera sp. " & sThickness & "mm", 1

                                                                                        End If

                                                                                    Set swFeat = swFeat.GetNextFeature

                                                                                    Loop

                                                                             

                                                                             

                                                                            End Sub