22 Replies Latest reply on Mar 24, 2016 11:18 PM by Deepak Gupta

    Toggle Display annotations

    Peter Farnham

      In Solidworks 2014 API

      When recording a macro the following is recorded.

      boolstatus = Part.Extention.SelectBtID2 ("Annotations", "DCABINET", 0,0,0 False, 0, Nothing, 0

       

      Setting False to 1

      boolstatus = Part.Extention.SelectBtID2 ("Annotations", "DCABINET", 0,0,0 False, 1, Nothing, 0

      sets the Display Annotations off.

       

      This no longer works in 2015.

      Is there a new way of doing this?

       

      Thank you.

        • Re: Toggle Display annotations
          Deepak Gupta

          Peter, the codes you've set above will not be doing the toggle IMO. Instead use following codes:

           

          Option Explicit

          Dim swApp As SldWorks.SldWorks

          Dim swModel As IModelDoc2

           

          Sub main()

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

           

          swModel.Extension.SetUserPreferenceToggle swUserPreferenceToggle_e.swDisplayAnnotations, _

          swUserPreferenceOption_e.swDetailingNoOptionSpecified, False 'Changing to True will set to ON

           

          End Sub

            • Re: Toggle Display annotations
              Peter Farnham

              Thank you Deepak,

               

              The line

              swModel.Extension.SetUserPreferenceToggle swUserPreferenceToggle_e.swDisplayAnnotations, _

               

              is showing red.

              I copied and pasted into VBA.

               

              I want to toggle the others too " show feature dimensions" ect.. but I can look these up :-)

               

              Thanks again.

                • Re: Toggle Display annotations
                  Deepak Gupta

                  Not sure if you noticed the complete line. I added an underscore to move some portion of the line to next line.

                   

                  swModel.Extension.SetUserPreferenceToggle swUserPreferenceToggle_e.swDisplayAnnotations, swUserPreferenceOption_e.swDetailingNoOptionSpecified, False

                   

                  swModel.Extension.SetUserPreferenceToggle swUserPreferenceToggle_e.swDisplayFeatureDimensions, swUserPreferenceOption_e.swDetailingNoOptionSpecified, False

                    • Re: Toggle Display annotations
                      Peter Farnham

                      Haha silly me!

                      Got it,

                       

                      Thank you

                      • Re: Toggle Display annotations
                        Peter Farnham

                        Hi Deepak,

                         

                        I Have noticed that IModeldoc2 is obsolete in 2015 API, being replaced by SetUserPreferenceToggle Method (IModelDocExtension).

                        I have tried all afternoon to try to make it work using the new member but so far have failed using the example shown in the API help.

                         

                        Can I be a pain and ask you to re-write in in the new method please. this is what I have so far.

                         

                        Sub main()

                        Dim swApp           As SldWorks.SldWorks
                        Dim instance As SldWorks.IModelDocExtension
                        Dim UserPref As Integer
                        Dim UserPrefOption As Integer
                        Dim value As Boolean


                        'value = instance.SetUserPreferenceToggle(UserPref, UserPrefOption, value)' as shown in help

                         

                        value = instance.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDisplayAnnotations, swUserPreferenceOption_e.swDetailingNoOptionSpecified, 0) 'Changing to 1 will set to ON ' what I got from help

                         

                        End Sub

                         

                        Pete

                          • Re: Toggle Display annotations
                            Deepak Gupta

                            IModeldoc2 for SetUserPreferenceToggle was obsoleted in earlier version of SOLIDWORKS and not 2015. Also if you look at the macro codes I've posted above, they are using the ModelDocExtension and not IModeldoc2. Don't worry as how the variable has been declared.

                             

                            Further, those same codes are working fine in 2014 and 2015. If you still having issue then use the following updates codes:

                             

                            Option Explicit

                            Dim swApp As SldWorks.SldWorks

                            Dim swModel As IModelDoc2

                            Dim swModExt As SldWorks.ModelDocExtension

                             

                            Sub main()

                            Set swApp = Application.SldWorks

                            Set swModel = swApp.ActiveDoc

                            Set swModExt = swModel.Extension

                               

                            swModExt.SetUserPreferenceToggle swUserPreferenceToggle_e.swDisplayAnnotations, swUserPreferenceOption_e.swDetailingNoOptionSpecified, False

                             

                            End Sub

                      • Re: Toggle Display annotations
                        Chris Manger

                        Hello Deepak.   I have a macro that toggles the display settings, but it only works on the part/assembly that is open.  Do you have any code that traverses the assembly and toggles the setting for all parts/subassemblies?

                      • Re: Toggle Display annotations
                        Oleg Bezyaev

                        Hi Peter.

                        Just interesting, which object you selected that returns "DCABINET"?

                          • Re: Toggle Display annotations
                            Deepak Gupta

                            Tools > Options > Document Properties > Detailing > Display annotations

                             

                            OR

                             

                            DCA.png

                            • Re: Toggle Display annotations
                              Peter Farnham

                              Hi Oleg,

                               

                              As Deepak shows, but you get DCABINET for the others below too.

                               

                              Part of the recorded macro below, macro works in 2014 but I can not get it to work in 2015.

                               

                              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.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 1, Nothing, 0)
                              boolstatus = Part.Extension.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 1, Nothing, 0)
                              boolstatus = Part.Extension.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 1, Nothing, 0)
                              boolstatus = Part.Extension.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 1, Nothing, 0)
                              boolstatus = Part.Extension.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 1, Nothing, 0)
                              boolstatus = Part.Extension.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 1, Nothing, 0)
                              boolstatus = Part.SetUserPreferenceToggle(swUserPreferenceToggle_e.swViewDisplayHideAllTypes, False)
                              boolstatus = Part.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDisplayOrigins, False)

                               

                              Pete

                                • Re: Toggle Display annotations
                                  Deepak Gupta

                                  Peter, these are all pointing to one type only:

                                  boolstatus = Part.Extension.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 1, Nothing, 0)

                                  boolstatus = Part.Extension.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 1, Nothing, 0)

                                  boolstatus = Part.Extension.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 1, Nothing, 0)

                                  boolstatus = Part.Extension.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 1, Nothing, 0)

                                  boolstatus = Part.Extension.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 1, Nothing, 0)

                                  boolstatus = Part.Extension.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 1, Nothing, 0)

                                  And these two are for the view menu

                                   

                                  boolstatus = Part.SetUserPreferenceToggle(swUserPreferenceToggle_e.swViewDisplayHideAllTypes, False) 'Uncheck Hide All

                                  boolstatus = Part.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDisplayOrigins, False) ' Hide Origin

                                    • Re: Toggle Display annotations
                                      Peter Farnham

                                      Hi Deepak,

                                       

                                      I would like you to record a macro (2015 sp2.1)selecting or de-selecting

                                      Annotations

                                           Display Annotations

                                           Show Feature Dimensions

                                           Show Reference Dimensions

                                           Show DimXpert Dimensions

                                       

                                      and I am sure you will get the following code:-

                                      ' ******************************************************************************
                                      ' C:\Users\Pete\AppData\Local\Temp\swx8092\Macro1.swb - macro recorded on 04/05/15 by Pete
                                      ' ******************************************************************************
                                      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.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 0, Nothing, 0)
                                      boolstatus = Part.Extension.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 0, Nothing, 0)
                                      boolstatus = Part.Extension.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 0, Nothing, 0)
                                      boolstatus = Part.Extension.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 0, Nothing, 0)

                                      End Sub

                                       

                                      Not exactly the same code that you have shown to me, (which works perfectly I might add :-)  )

                                      I would like to understand why the code is so different.

                                       

                                      As a sub question the following all used to work and now only works until the last line which fails as it is no longer an option it seems.

                                       

                                      'toggles value, can not toggle using the toggle method.

                                       

                                      boolstatus = swApp.RunCommand(swCommands_ViewPartingLines, False)

                                      boolstatus = swApp.RunCommand(swCommands_View3DSketchPlane, False)

                                      boolstatus = swApp.RunCommand(swCommands_View3DSketchDimensions, False)

                                      boolstatus = swApp.RunCommand(swCommands_ViewWeldBeads, False)' fails on this code

                                       

                                      I have searched for the weld bead toggle as well as the grid view toggle and the 3D sketch view toggle, but to no avail at the moment.

                                      I have found all of the others in the hide/show toolbar.

                                       

                                      I am at home till Tuesday where I can grab the working 2014 macro from my desktop at work to show you.

                                      I am testing 2015 sp2.1 at home before I release it in a working environment as there many broken things in it, hopefully fixed in sp3, but that's another issue.

                                       

                                      Regards

                                      Pete

                                        • Re: Toggle Display annotations
                                          Deepak Gupta

                                          Peter Farnham wrote:

                                           

                                          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.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 0, Nothing, 0)
                                          boolstatus = Part.Extension.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 0, Nothing, 0)
                                          boolstatus = Part.Extension.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 0, Nothing, 0)
                                          boolstatus = Part.Extension.SelectByID2("Annotations", "DCABINET", 0, 0, 0, False, 0, Nothing, 0)

                                          End Sub

                                           

                                          This is due to fact that macro is only recording the Annotations folder selection and not what action is being done inside.

                                           

                                           

                                          boolstatus = swApp.RunCommand(swCommands_ViewWeldBeads, False)' fails on this code

                                          For me it is coming as swUserPreferenceToggle_e.swDisplayLights, so seems like there is a bug. Same results with 2014 or earlier but it seems like this method has not been implemented yet. But looking through the view menu option, it seems to be be implemented in 2015 or may be that is a mistake..