4 Replies Latest reply on Jun 4, 2014 4:49 PM by Chris Johnson

    Reposition Drawing Views based on user selection

    Chris Johnson

      I'm revisiting an abandoned idea for a macro that will reposition pre-selected drawing views based on the order that the user selected them.

       

      The first view selected is the top view.

      The second view selected is the bottom view.

      The remaining views selected are the views that are to be repositioned evenly between the top and bottom views. The top & bottom views are not moved.

       

      In other words if you had 4 drawing views selected and the top view was 6” above the bottom view, then the middle views would be repositioned so that all 4 views are 2” apart.

       

       

      My problem is I have no idea how to traverse only through the selected views in order to get their positions and then reposition  as needed.

       

      Get first view & get next view dont seem applicable in this situation.

       

      How would you guys do this?

      example.jpg

       

      Thank you!

      Chris

        • Re: Reposition Drawing Views based on user selection
          Artem Taturevych

          You need to loop through the selected object from 1 to SelectionMgr::GetSelectedObjectCount2. Then you can get the pointer either using the SelectionMgr::GetSelectedObject6 or SelectionMgr::GetSelectedObjectsDrawingView2. to allow users selected any entity from the view. Check the 'Selection Lists (VBA)' example in API Help for a sample code.

          ______________________________________________

          Regards, Artem Taturevych | Snr. Developer | IC3D ANZ

           

          IC3DSteel – New Steel Solution for SolidWorks

          translationXpert – SolidWorks files language translator

          LinkedIn - SolidWorks API Group

          • Re: Reposition Drawing Views based on user selection
            Chris Johnson

            Thanks Artem,

            That got the ball rolling. Im well on my way now!

             

            Chris

              • Re: Reposition Drawing Views based on user selection
                Chris Johnson

                Artem,

                 

                here is a sample of what im trying to do. it mostly works but im getting unexpected results and I have no idea why.

                 

                Preconditions:

                1.) CTRL Select drawing views in this order; topview, bottomview & then middleview

                2.) run macro

                 

                DESIRED post conditions:

                1.) middle view moves midway between the top and bottom views

                2.) top and bottom views remain unmoved

                 

                Actual post conditions:

                1.) middle AND Top views move up instead of middle view moving to the midway point

                 

                do you see what im doing wrong?

                 

                Thank you!

                Chris

                 

                 

                  Sub Main()

                 

                    Dim swApp                     As SldWorks.SldWorks

                    Dim swModel                   As SldWorks.ModelDoc2

                    Dim swSelMgr                  As SldWorks.SelectionMgr

                    Dim swView                    As SldWorks.View

                 

                    Dim TopView                   As Variant

                    Dim BottomView                As Variant

                    Dim MiddleView                As Variant

                    Dim Distance                  As Double

                    Dim spacing                   As Double

                 

                    'Connect to Solidworks & active document

                        Set swApp = Application.SldWorks

                        Set swModel = swApp.ActiveDoc

                        Set swSelMgr = swModel.SelectionManager

                   

                 

                    'Get TopView pos

                        Set swView = swSelMgr.GetSelectedObject6(1, -1)

                            TopView = swView.Position

                 

                    'Get BottomView pos

                        Set swView = swSelMgr.GetSelectedObject6(2, -1)

                            BottomView = swView.Position

                        Set swView = Nothing

                 

                        

                    'Reposition Middle View

                        Set swView = swSelMgr.GetSelectedObject6(3, -1)

                       

                            Distance = TopView(1) - BottomView(1)

                            spacing = Distance / 2

                           

                            MiddleView = swView.Position

                            MiddleView(1) = TopView(1) - spacing

                           

                            swView.Position = MiddleView

                           

                 

                        swModel.EditRebuild3

                 

                    Set swApp = Nothing

                End Sub