13 Replies Latest reply on Jul 6, 2017 8:18 AM by Nick Middleton

    playing back recorded macro fails...

    Nick Middleton

      I am trying to create a macro button that will modify precision on both normal angle and also chamfer angle precision. I can get the button to change the normal angle precission however it will not update the chamfer precision. can anybody explain what is wrong? the crazy thing is... when I record the macro, the precision changes fine.

       

      Any help would be appreciated.

       

       

      Dim swApp As Object

       

       

      Dim Part As Object

      Dim boolstatus As Boolean

      Dim longstatus As Long, longwarnings As Long

       

       

      Sub main()

       

       

      Set swApp = _

      Application.SldWorks

       

       

      Set Part = swApp.ActiveDoc

      boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swDimensionsExtensionLineStyleThickness, swUserPreferenceOption_e.swDetailingChamferDimension, swLineWeights_e.swLW_THIN)

      boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swDetailingAngularDimPrecision, swUserPreferenceOption_e.swDetailingChamferDimension, 0)

      End Sub

       

       

       

      precision.png

        • Re: playing back recorded macro fails...
          Peter Brinkhuis

          This works for me:

           

          Sub ChangeChamferPrecision()

              Dim swApp As SldWorks.SldWorks

              Dim swModel As ModelDoc2

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Dim boolstat As Boolean

              boolstat = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swDetailingAngularDimPrecision, swUserPreferenceOption_e.swDetailingChamferDimension, 0)

          End Sub

           

          Maybe only changing the object types to the SolidWorks types will do the trick for you.

           

          If you need to change more settings, the help is pretty detailed. It just misses code samples pretty often, but you have the basics from the recorded macro already.

          2015 SOLIDWORKS API Help - Document Properties > Dimensions > Chamfer

            • Re: playing back recorded macro fails...
              Nick Middleton

              Hi Peter,

              I have just copied that code and i cant get it to work...

               

              Do I need to keep the code that is there when creating a new macro (to paste into)?

                • Re: playing back recorded macro fails...
                  Nick Middleton

                  Im not sure if this makes much difference but I am using sw 2016 sp4

                  • Re: playing back recorded macro fails...
                    Peter Brinkhuis

                    You only need the code I posted for it to work. You can add as many subs as you want in a macro though, press F5 or press play to run only that sub.

                     

                    Are you sure the macro runs? You can add a break point halfway and run it to see if it pauses there. You can also try to add this to print true if the value was set and false if it wasn't set properly:

                     

                    debug.print boolstat

                      • Re: playing back recorded macro fails...
                        Nick Middleton

                        Hi Peter,

                         

                        I dont really understand all the code, however I can understand that certain bits that come up are for particular operations.

                         

                        the macro I recorded still works as I  have a button to change both the normal and chamfer angle precision from no zeroes to 8 zeroes and vice versa.

                         

                        I can see clearly the normal angle precision (trailing zeroes) coming and going as I press the appropriate buttons. the chamfer part of the macro does nothing....

                         

                        To be honest Im losing the will to live as I spent ten days on a piece of code that should take less than five minutes. this code recognised the drawing title ammended the trailing zeroes from smart to show. I also added the arrows to change from outside to inside.

                         

                        I purchased the automating solidworks with macros (2017 because that is what I am personally running at home)  book with the outside hope that I can get one macro to work my way one day.....

                         

                        writing macros is way to painful :-(

                          • Re: playing back recorded macro fails...
                            Peter Brinkhuis

                            I agree, programming can be painful The snippet of code that I posted above took me only a few minutes though. Just keep trying and keep reading. Sometimes you might feel you're missing the basics, so reading that book will really help.

                             

                            You said you have different buttons for macros. Have you selected the correct method in the macro button properties? In my example here, I selected the IncreaseLength sub within the Main module. You can create one macro with a few subs and hook a button to each sub.

                             

                            macroButtons.png

                            Can you post all of your code?

                              • Re: playing back recorded macro fails...
                                Nick Middleton

                                 

                                ***********************************************************

                                ***********************************************************

                                ***********************************************************

                                ******************************************************************************

                                ' C:\Users\nickmiddleton\AppData\Local\Temp\swx3024\Macro1.swb - macro recorded on 07/05/17 by nickmiddleton

                                ' ******************************************************************************

                                Dim swApp As Object

                                 

                                 

                                Dim Part As Object

                                Dim boolstatus As Boolean

                                Dim longstatus As Long, longwarnings As Long

                                 

                                 

                                Sub main()

                                 

                                 

                                Set swApp = _

                                Application.SldWorks

                                 

                                 

                                Set Part = swApp.ActiveDoc

                                boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swDetailingAngularDimPrecision, swUserPreferenceOption_e.swDetailingAngleDimension, 0)

                                End Sub

                                ***********************************************************

                                ***********************************************************

                                ***********************************************************

                                ' ******************************************************************************

                                ' C:\Users\nickmiddleton\AppData\Local\Temp\swx3024\Macro1.swb - macro recorded on 07/05/17 by nickmiddleton

                                ' ******************************************************************************

                                Dim swApp As Object

                                 

                                 

                                Dim Part As Object

                                Dim boolstatus As Boolean

                                Dim longstatus As Long, longwarnings As Long

                                 

                                 

                                Sub main()

                                 

                                 

                                Set swApp = _

                                Application.SldWorks

                                 

                                 

                                Set Part = swApp.ActiveDoc

                                boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swDetailingAngularDimPrecision, swUserPreferenceOption_e.swDetailingAngleDimension, 7)

                                End Sub

                                *****************************************

                                ******************************************

                                *******************************************

                                 

                                 

                                This is a newly created set of macros just for normal angle precision. Both sad face and purple face buttons work well and trigger the desired output.

                                 

                                When I try the Exact same thing with Chamfer precision it does less than nothing.

                                 

                                I have cut and pasted your code with no luck. ( i am not convinced its because i am running sw16sp4)

                                any further help very much appreciated

                                  • Re: playing back recorded macro fails...
                                    Peter Brinkhuis

                                    Can you run my code again, add a break point at the last line (end sub) and see what the boolstat value is by adding a watch? That does the same thing as adding debug.print. We just need to know if it doesn't execute correctly or if you don't see any result.

                                      • Re: playing back recorded macro fails...
                                        Nick Middleton

                                        This is what I get but no change from the drawing side

                                         

                                          • Re: playing back recorded macro fails...
                                            Nick Middleton

                                            One thing I have just noticed after running my recorded code for chamfer angle precision is this.

                                             

                                            in the actual preferences the box says None. and the actual drawing still has an unrefreshed collection of zeroes. rebuilding does not clear it either.

                                             

                                            if I click on none just for the sake of choosing none again.... the drawing changes.   possibly a bug?...

                                            • Re: playing back recorded macro fails...
                                              Peter Brinkhuis

                                              I just played around with a few dimensions in SolidWorks. What's probably causing this is the fact that SolidWorks just doesn't show any digits when there is nothing to show. A 45 degree chamfer will always be shown as 45 and not as 45.000000000.

                                               

                                              A way around that is to go to Options > Document Properties > Dimensions > Trailing zeroes (bottom left) and set it from Smart to Show.

                                                • Re: playing back recorded macro fails...
                                                  Nick Middleton

                                                  sadly this trailing zeroes is exactly what has triggered the requirement to use the chamfer precision tool :-(

                                                   

                                                  i automated it to change trailing zeroes from smart to show in order to get for example a 20mm diameter to read 20.00 in order to register a requirement in the tolerances. one thing i did notice today is you can mutiple select normal dimensions and change how many dp there are and it will update all selected dims.

                                                   

                                                  when you try and do the same with these blasted chamfer dimensions

                                                  it will not update the selected chamfer dimensions.

                                                   

                                                  I think I will just write this off as a glitch that cant be fixed. I get paid to mechanical engineer not fault find computer programming enigmas.

                                                   

                                                  its just rubbish when something that should be so easy is so difficult to fix.

                                                   

                                                  thanks for your feedback though. it makes me realise that I have at least been trying the right things...