9 Replies Latest reply on Oct 8, 2014 10:17 PM by Deepak Gupta

    RESTORE UP FROM MINIMIZED STATE

    James Kashuba

      is there a quick way to "restore up" all windows that have been minimized in SW? I am able to cycle through parts and drawings but the cycling does not necessarily restore them to maximized state. I hope this make sense to those reading.

       

      Thanks,

      Jim

        • Re: RESTORE UP FROM MINIMIZED STATE
          Daniel Andersson

          Found something that might guide you. I just tried to record the macro and it worked. It gave my this... The code works for one open document.

          I have tried to make it apply for all open documents but I fail. When I loop I get different behavior depending on selected document.... not found why yet.

          Below is the macro that is failing, someone might find out why before I do (about to sleep...).

           

          To minimize:

          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

           

          Dim myModelView As Object

          Set myModelView = Part.ActiveView

          myModelView.FrameLeft = 0

          myModelView.FrameTop = 0

          myModelView.FrameState = swWindowState_e.swWindowMinimized

          End Sub

           

          To Maximize:

          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

           

          Dim myModelView As Object

          Set myModelView = Part.ActiveView

          myModelView.FrameLeft = 0

          myModelView.FrameTop = 0

          myModelView.FrameState = swWindowState_e.swWindowMaximized

          End Sub

           

          Macro with different behavior depending on which minimized document is selected once macro is executed.

          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2

          Dim myModelView As SldWorks.ModelView

          Dim longwarnings As Long

           

          Sub main()

          Dim strPath As String

           

          Set swApp = Application.SldWorks

          Set swModel = swApp.GetFirstDocument

           

          While Not swModel Is Nothing

              Set myModelView = swModel.ActiveView

              myModelView.FrameState = swWindowState_e.swWindowNormal

           

              Set swModel = swModel.GetNext

           

              If Not swModel Is Nothing Then

                  strPath = GetFilename(swModel.GetPathName)

                  swApp.ActivateDoc3 strPath, False, 2, longwarnings

              End If

          Wend

          End Sub

           

          Function GetFilename(ByVal strPath As String) As String

              If Right$(strPath, 1) <> "\" And Len(strPath) > 0 Then

                  GetFilename = GetFilename(Left$(strPath, Len(strPath) - 1)) + Right$(strPath, 1)

              End If

          End Function

           

          I might have a new try on the weekend....

          // Daniel

          • Re: RESTORE UP FROM MINIMIZED STATE
            Deepak Gupta

            Try if this one works:

            Dim swApp As SldWorks.SldWorks

            Dim swModel As SldWorks.ModelDoc2

            Dim vModels As Variant

            Dim index As Long

            Dim myModelView As Object

            Dim Errors As Long

            Sub main()

             

            Set swApp = Application.SldWorks

            vModels = swApp.GetDocuments

             

            For index = LBound(vModels) To UBound(vModels)

                Set swModel = vModels(index)

                swApp.ActivateDoc3 swModel.GetPathName, False, 1, Errors

                Set myModelView = swModel.ActiveView

                myModelView.FrameState = swWindowState_e.swWindowMaximized

            Next index

            End Sub

              • Re: RESTORE UP FROM MINIMIZED STATE
                James Kashuba

                Deepak,

                Thanks for your input, you always seem to have an answer for me. Your code had an odd execution also. It maximized one assembly drawing and then it opened every part file associated with the that drawing while leaving all the other drawings minimized. The right function should only maximize what is minimized and not open anything. It is interesting to see two different approaches to the same problem (You and Daniel that is). Thanks for your time!

                  • Re: RESTORE UP FROM MINIMIZED STATE
                    Daniel Seaman

                    Deepak's macro needs to check the visibility of each file opened:

                     

                    For index = LBound(vModels) To UBound(vModels)

                        Set swModel = vModels(index)

                        If swModel.Visible <> False Then

                            swApp.ActivateDoc3 swModel.GetPathName, False, 1, Errors

                            Set myModelView = swModel.ActiveView

                            myModelView.FrameState = swWindowState_e.swWindowMaximized ' or swWindowNormal if preferred.

                       End If

                    Next index

                      • Re: RESTORE UP FROM MINIMIZED STATE
                        James Kashuba

                        You nailed it Daniel! Thank you so much. It was Deepak's code with your tweek that worked. However, it didn't work at first. It seems that SW didn't like swWindowMaximized state. When I replaced that with swWindowNormal it functioned as intended.

                         

                        I can't even begin to tell you All how much this helped me, THANK YOU.

                        • Re: RESTORE UP FROM MINIMIZED STATE
                          Daniel Andersson

                          Edit: Ah, I see that you wrote at the same time as me. Glad that you find it working as you wanted.

                           

                          The thing is that only one document can be maximized. Using macros above still minimizes if the user presses "Restore".

                          I think that James Kashuba is aiming to have all other windows Normal and one as Maximized. Then the behavior is as at least as I expect it... I have adjusted the macros from the input from Deepak Gupta and from Daniel Seaman.

                           

                          James Kashuba, please let us know what behavior you expect from your end.

                          Dim swApp As SldWorks.SldWorks

                          Dim swModel As SldWorks.ModelDoc2

                          Dim vModels As Variant

                          Dim sCurrentModel As String

                          Dim index As Long

                          Dim myModelView As Object

                          Dim Errors As Long

                          Sub main()

                           

                          Set swApp = Application.SldWorks

                          Set swModel = swApp.ActiveDoc

                           

                          vModels = swApp.GetDocuments

                          sCurrentModel = swModel.GetPathName

                           

                          For index = LBound(vModels) To UBound(vModels)

                              Set swModel = vModels(index)

                              If swModel.Visible <> False Then

                                  swApp.ActivateDoc3 swModel.GetPathName, False, 1, Errors

                                  Set myModelView = swModel.ActiveView

                                  myModelView.FrameState = swWindowState_e.swWindowNormal

                            End If

                          Next index

                           

                          swApp.ActivateDoc3 sCurrentModel, False, 1, Errors

                          Set swModel = swApp.ActiveDoc

                          Set myModelView = swModel.ActiveView

                          myModelView.FrameState = swWindowState_e.swWindowMaximized

                           

                          End Sub

                          // Daniel

                            • Re: RESTORE UP FROM MINIMIZED STATE
                              James Kashuba

                              Daniel,

                              That is what I intended. Daniel Seaman's code worked as well, but there are differences between yours ans his. I played with a couple of scenarios, one of them being to have all open docs tiled vertical, then minimized and then restored. It worked as intended. However, when I tiled all docs and then restored them to maximized before minimizing; and then minimized them to restored them to tiled, it was not what I intended.  It still maximized all docs so I'm content with that, even if they were tiled. Your code on the other hand restored to what I had in mind. In the end, both do what I want. When I have time I am going to place your codes side by side to see the subtleties in your methods.

                               

                              Thanks Daniel for you time!

                            • Re: RESTORE UP FROM MINIMIZED STATE
                              Deepak Gupta

                              Thanks Daniel Seaman and Daniel Andersson for making me know as where I was making the mistake.