7 Replies Latest reply on Apr 5, 2017 11:24 AM by Deepak Gupta

    Combine 2 macros

    zaher taleb

      Hi all,

      how can i Combine 2 macros?

      thanks

        • Re: Combine 2 macros
          Deepak Gupta

          Yes you can but depends on what their functions are and what you need.

           

          Share your macros here and someone would guide you through.

            • Re: Combine 2 macros
              zaher taleb

              i have attached it

              the first maro is "check" the second macro is "Force rebuild and save"

              thanks

                • Re: Combine 2 macros
                  Deepak Gupta

                  Check this would help

                   

                  Option Explicit

                      Dim swApp               As SldWorks.SldWorks

                      Dim swModel             As SldWorks.ModelDoc2

                   

                  Sub main()

                   

                  Set swApp = Application.SldWorks

                  Set swModel = swApp.ActiveDoc

                   

                  If swModel.CustomInfo("Rohteil") = "" Then

                      MsgBox ("please enter value")

                  Else   

                  'Force rebuild

                      swModel.ForceRebuild3 True

                  'Re-draw graphics window

                      swModel.GraphicsRedraw

                  'Save active document

                      swModel.Save       

                  End If

                           

                  End Sub

              • Re: Combine 2 macros
                Joseph McCabe

                I have a similar situation,  I am trying to re-write / combine 3 macros 

                The first is to transverse through an assembly and any sub-assemblies, fixing in place all assemblies and components :

                     it's this one from Wayne Matus

                 

                Option Explicit

                Dim swApp As SldWorks.SldWorks

                Sub main()

                    Dim swModel As ModelDoc2

                    Dim swAssy As AssemblyDoc

                    Set swApp = Application.SldWorks

                    Set swModel = swApp.ActiveDoc

                    Set swAssy = swModel

                    TransverseComponents swAssy

                    swApp.SendMsgToUser "Done!"

                End Sub

                Sub TransverseComponents(swAssy As AssemblyDoc)

                    Dim vComponents As Variant

                    Dim i As Integer

                    Dim swComponent As Component2

                    Dim swModel As ModelDoc2

                    Dim swAssembly As AssemblyDoc   

                    vComponents = swAssy.GetComponents(True)

                    For i = 0 To UBound(vComponents)

                        Set swComponent = vComponents(i)

                        Set swModel = swComponent.GetModelDoc2

                        Debug.Print swComponent.Name2

                        swComponent.Select4 False, Nothing, False

                        swAssy.FixComponent

                        If swModel.GetType = swDocASSEMBLY Then

                            Set swAssembly = swModel

                            TransverseComponents swAssembly

                        End If

                          Next i

                End Sub

                 

                That works great.  I want to suppress all the mates at the same time though, rather than have them all just turn inactive.

                So I was looking at the following 2 examples of how I might be able to do that. 

                 

                2011 SOLIDWORKS API Help - Suppress Feature Example (VBA)

                2011 SOLIDWORKS API Help - Get Mates Example (VBA)

                 

                I attempted to edit, then call-in the "get mates" macro, which then called-in an edited version of the "suppress feature" macro.  I've discovered that doesn't seem to work like I thought it would, and I have no idea how re-write it into a single macro that does what I need. (I'd show my work but i'm too embarrassed to share.)

                 

                I want to start at the top level assembly, fix all the sub-assemblies and components, their internal sub-assemblies and components, potentially several layers deep, just like Wayne's macro does, then suppress all the mates.

                 

                To prevent myself from "moving the goal posts"; If possible, I'd also love to turn all of my equation driven dimensions into numerical entries, and then make all dimensions read/write instead of read-only.  Since most equations are in sub-assemblies controlling their internal parts, when the selected from the top level, they're read-only but I'd like to be able to direct edit the dimension text from that top level.  At this point in our work, the equations/functions/etc have already served their use and are obsolete.  It would also work just fine if I could simply make the dims editable and where necessary, overwrite the equations as needed.

                 

                I can go into great detail of the why, including posting some example models etc, how we use them, and the next stage after running the macros if anyone is interested or the info helps creating a viable solution.  I deemed this post wordy enough already.

                 

                thanks for any suggestions, and all assistance .

                joe

                  • Re: Combine 2 macros
                    Deepak Gupta

                    Joseph McCabe wrote:

                     

                    I can go into great detail of the why, including posting some example models etc, how we use them, and the next stage after running the macros if anyone is interested or the info helps creating a viable solution. I deemed this post wordy enough already.

                     

                    Joe, I would suggest you to start a new post and put the requirements with an example stating that how this could be useful. This way others can also put in ideas/thoughts and can understand the usefulness of the method.

                     

                    Further I would also suggest to go with standalone or add-in for a faster processing rather than a macro.

                      • Re: Combine 2 macros
                        Joseph McCabe

                        Thank you Deepak for your suggestion, I will certainly do that.  It will take me a few days to put together some examples of a model starting point state, and then another of where I want to get to, along with why we need / like to work this way.  There certainly could a better method to how we use Solidworks here and I'm completely open to looking at other work flow options.  Your suggestion for considering a stand alone or add-in package is something that I thought of but have not seen an appropriate solution.  If there is something already out there tailored for my industry (architectural millwork), I haven't found it yet.

                         

                        The post will be lengthy to adequately describe our needs but I don't see a way around that, especially since I want to find the best method for us.

                         

                        I also have a call in discuss this with my VAR (CATI) to see if they can help.

                         

                        In other thoughts, I do have a number of macros I've cobbled together that do work nicely.  Is there a place to share those with the community?  Should I simply start a new post and share them that way?  Some are tied back to excel files to import data, others are only for operations within Solidworks.

                          • Re: Combine 2 macros
                            Deepak Gupta

                            I've seen not any thing like that but it should be do able. I'll see if I can get some time over weekend.

                            Joseph McCabe wrote:

                             

                            In other thoughts, I do have a number of macros I've cobbled together that do work nicely. Is there a place to share those with the community? Should I simply start a new post and share them that way? Some are tied back to excel files to import data, others are only for operations within Solidworks.

                            Thanks for your great thoughts in sharing them. I would suggest you to post them under API section, each with a new post and also on the 3D ContentCentral website.