8 Replies Latest reply on Sep 14, 2018 4:29 PM by Marcos Rodríguez

    Break toolbox property for all items into an assembly

    Marcos Rodríguez

      Hello,

       

      I've decided to post this macro, because many people has  got the same issue. There is an app. sldsetdocprop.exe that makes the same job, but it's not always installed.

       

      So there are 3 macros attached.

      • Macro-18: works in assemblies: it detects if a part is Toolbox and change it to non toolbox. If any is supressed it'd be skipped.
      • Macro-17:  does the same as Macro-18, but don't repeat if a part is instaced several times.
      • Other works individualy only in 1 part at a time. But allows you to revert the property.

       

      Enjoy and please acknowledge if you like!

       

       

      Message was edited by: Marcos Rodríguez Uploaded with updated to handle suppressed components

        • Re: Break toolbox property for all items into an assembly
          Deepak Gupta

          Great macros Marcos RodríguezMarcosThank You for sharing them.

           

          BTW the assembly I was trying it on had lot of suppressed parts/assemblies and this macro failed. So can you please improve the assembly macro by adding conditions for suppressed parts and macro should run on unique parts only as with getcomponents method, you would get the complete list of parts i.e. each instance of the same part. As fasteners are generally added in more quantity, it might be good idea to process unique parts only.

            • Re: Break toolbox property for all items into an assembly
              Marcos Rodríguez

              Hi Deepak,

               

              Thanks for the acknowledge, I will take a look to what happens when part/assemblies are suppresed, thanks for the review.

               

              I didn't understand very well the second bit. The macro gets all the components of an asssembly to all levels, and then it changes the property if it's a part and if it's a toolbox. Doesn't matter how many times the part is isntanced, the toolbox flag will be killed.

               

              Regards.

               

              Who gave ou the "Correct Answer"?

                • Re: Break toolbox property for all items into an assembly
                  Deepak Gupta

                  Marcos Rodríguez wrote:

                   

                  Thanks for the acknowledge, I will take a look to what happens when part/assemblies are suppressed, thanks for the review.

                  Thanks, we look forward to the updated macro.

                   

                  The macro gets all the components of an assembly to all levels, and then it changes the property if it's a part and if it's a toolbox. Doesn't matter how many times the part is isntanced, the toolbox flag will be killed.

                  The current method you've in the macro would loop thru each instance of the part (whether it has been processed earlier by the macro or not). For e.g. if same part is used 100 times in the assembly, then macro would check that part 100 times instead of checking it only once. This can decrease the performance. So instead you can use collection to make sure that each part is processed only one irrespective of how many times it has been used in the assembly.

                    • Re: Break toolbox property for all items into an assembly
                      Marcos Rodríguez

                      Hi Deepak,

                       

                      Ok, thanks for the explanation. What do you mean by colletions? I had made another way to trasverse through the assembly but I thought this was more simple.

                       

                      Regards.

                        • Re: Break toolbox property for all items into an assembly
                          Deepak Gupta

                          Marcos Rodríguez wrote:

                           

                          Ok, thanks for the explanation. What do you mean by collections?

                          Check this link to get idea on collections: The Ultimate Guide To Collections in Excel VBA

                            • Re: Break toolbox property for all items into an assembly
                              Marcos Rodríguez

                              Hi Deepak,

                               

                              I've just checked now within an assembly with lot of Toolbox fixings, and it doesn't repeat same component twice.

                               

                              I've uploaded 2 macros now, Macro-17 & 18.

                               

                              No one of them loop through all the instances of the same component, unless I'm completely wrong.

                               

                              Macro-17 is much more simple.

                               

                              Thanks for the tip of Collections, I didn't remind they existed, and can be very useful.

                               

                               

                              Cheers

                                • Re: Break toolbox property for all items into an assembly
                                  Deepak Gupta

                                  Marcos Rodríguez wrote:

                                   

                                  I've just checked now within an assembly with lot of Toolbox fixings, and it doesn't repeat same component twice.

                                   

                                  No one of them loop through all the instances of the same component, unless I'm completely wrong.

                                  Try these codes with an assembly having multiple instance of same file and check the immediate window.

                                   

                                  Option Explicit
                                      Dim swApp As SldWorks.SldWorks
                                      Dim swModel As SldWorks.ModelDoc2
                                      Dim swAssy As SldWorks.AssemblyDoc
                                      Dim swComp As SldWorks.Component2
                                      Dim vComponents As Variant
                                      Dim vComponent As Variant
                                  Sub Main()
                                      
                                      Set swApp = Application.SldWorks
                                      Set swModel = swApp.ActiveDoc
                                          
                                      If swModel Is Nothing Then
                                          MsgBox "No document loaded.", vbCritical
                                          End
                                      ElseIf swModel.GetType = 2 Then 'swDocASSEMBLY
                                          Set swAssy = swApp.ActiveDoc
                                          vComponents = swAssy.GetComponents(False)
                                  
                                  
                                          For Each vComponent In vComponents
                                              Set swComp = vComponent
                                              Debug.Print swComp.GetPathName
                                          Next
                                      End If
                                      
                                  End Sub
                                  
                                    • Re: Break toolbox property for all items into an assembly
                                      Marcos Rodríguez

                                      Deepak,

                                       

                                      The reason why my macro doesn't repeat again through the same component, it's because it only operates when the part has the toolbox flag.

                                       

                                      So, the first time it finds a part that is a toolbox it kills it, so it won't try to kill it again. The time consuming of check that's is part is minimal as long as it doesn't do anything with the part.

                                       

                                      Otherwise, you've got the other macro-17, that filters all parts by its name. It you think processing time is a big issue.

                                       

                                      Cheers!!