10 Replies Latest reply on Nov 2, 2016 6:08 AM by Raghvendra Bhargava

    Drawing View GetOutline

    Di Anne

      Hi SW Community, Keith RiceDeepak Gupta Artem Taturevych

       

      Can anyone explain to me about GetOutline of a drawing View?

      Because I am currently creating line inside the view using the GetOutline.

      but it oesnt work well.

       

      below is the code I used in creating the line.

      double[] vOutLine = (double)View.GetOutline();
      swDocDraw.SketchManager.CreateLine(0, vOutLine[1], 0, 0, vOutLine[3], 0);
      

       

      below should be the output but using the GetOutline doesnt work well, the line is too small.

       

       

       

      Thanks in advance.

       

      DiAnne

          • Re: Drawing View GetOutline
            Di Anne

            Hi Deepak,

             

            I already checked the link but it seems that it doesn't help.

             

            By the way do you know how to transform coordinate in the view?

             

            Thank you in advance.

             

            Regards,

            DiAnne

              • Re: Drawing View GetOutline
                Deepak Gupta

                Try these codes:

                 

                Option Explicit

                Sub main()

                    Dim swApp                       As SldWorks.SldWorks

                    Dim swModel                     As SldWorks.ModelDoc2

                    Dim swDraw                      As SldWorks.DrawingDoc

                    Dim swView                      As SldWorks.View

                    Dim vOutline                    As Variant 

                 

                    Set swApp = Application.SldWorks

                    Set swModel = swApp.ActiveDoc

                    Set swDraw = swModel

                    Set swView = swDraw.SelectionManager.GetSelectedObject6(1, -1)

                    vOutline = swView.GetOutline

                    swDraw.ActivateView swView.Name

                    swDraw.SketchManager.CreateLine vOutline(0), vOutline(1), 0, vOutline(2), vOutline(3), 0   

                End Sub

                  • Re: Drawing View GetOutline
                    Di Anne

                    Hi Deepak,

                     

                    I've been using the same code but it doesn't work inside the view.

                      • Re: Drawing View GetOutline
                        Deepak Gupta

                        Sorry but I think I've found the to issues

                         

                        1 If your view scale it not 1:1, then you don't get 1:1 line with macro.

                         

                        2 The code have bugs and it doesn't start from view lower corner.

                         

                        Here are three views with end results using different codes

                        Set swSketchSegment = swDraw.SketchManager.CreateLine(0#, 0#, 0#, vOutline(2), vOutline(3), 0#)

                        Set swSketchSegment = swDraw.SketchManager.CreateLine(vOutline(0), vOutline(1), 0#, vOutline(2), vOutline(3), 0#)

                        Set swSketchSegment = swDraw.SketchManager.CreateLine(0#, 0#, 0#, vOutline(2) - vOutline(0), vOutline(3) - vOutline(1), 0#)

                         

                         

                        Raghvendra, I get same results using your codes also.

                          • Re: Drawing View GetOutline
                            Raghvendra Bhargava

                            Hi Deepak,

                            Thanks for the noticeable observation.

                            I found 2 things:

                            1. if I am changing only View scale then my code is working fine.

                            2. If Sheet scale is changed then it is failing so I got the solution for this:

                             

                            Dim swApp As Object
                            Dim Part As Object
                            Dim SelMgr As Object
                            Dim boolstatus As Boolean
                            Dim longstatus As Long, longwarnings As Long
                            Dim Feature As Object
                            Dim vOutline As Variant
                            Dim vPos As Variant
                            Dim swView As View
                            Dim swPoint As SketchPoint
                            Dim swDraw As DrawingDoc

                            Sub main()

                            Set swApp = Application.SldWorks

                            Set Part = swApp.ActiveDoc
                            Set swDraw = Part
                            Set SelMgr = Part.SelectionManager
                            boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0.09524432543007, 0.1747097690819, 0, False, 0, Nothing, 0)

                            Set swView = Part.SelectionManager.GetSelectedObject6(1, -1)

                            vOutline = swView.getoutline

                            vPos = swView.Position

                            Dim swSheet As Sheet

                            Set swSheet = swDraw.GetCurrentSheet

                            Dim vSheetProps As Variant

                            vSheetProps = swSheet.GetProperties

                            Dim SheetScale As Double

                            SheetScale = vSheetProps(3) / vSheetProps(2)

                            Set swPoint = Part.SketchManager.CreatePoint(vOutline(0) * SheetScale, vOutline(1) * SheetScale, 0)

                            Set swPoint = Part.SketchManager.CreatePoint(vOutline(2) * SheetScale, vOutline(3) * SheetScale, 0)

                            Set swPoint = Part.SketchManager.CreatePoint(vPos(0) * SheetScale, vPos(1) * SheetScale, 0)

                            Dim SketchSegment As SketchSegment

                            Set SketchSegment = Part.SketchManager.CreateLine(vPos(0) * SheetScale, vOutline(1) * SheetScale, 0, vPos(0) * SheetScale, vOutline(3) * SheetScale, 0)

                            End Sub

                            I think it should work out.

                            I didn't get the time to check other Scale Combination...

                             

                            Cheers Deepak Gupta

                  • Re: Drawing View GetOutline
                    Raghvendra Bhargava

                    I have created VBA sample :

                     

                    Dim swApp As Object
                    Dim Part As Object
                    Dim SelMgr As Object
                    Dim boolstatus As Boolean
                    Dim longstatus As Long, longwarnings As Long
                    Dim Feature As Object
                    Dim vOutline As Variant
                    Dim vPos As Variant
                    Dim swView As View
                    Dim swPoint As SketchPoint

                    Sub main()

                    Set swApp = Application.SldWorks

                    Set Part = swApp.ActiveDoc
                    Set SelMgr = Part.SelectionManager


                    boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0.09524432543007, 0.1747097690819, 0, False, 0, Nothing, 0)

                    Set swView = Part.SelectionManager.GetSelectedObject6(1, -1)

                    vOutline = swView.getoutline

                    vPos = swView.Position

                    Set swPoint = Part.SketchManager.CreatePoint(vOutline(0), vOutline(1), 0)

                    Set swPoint = Part.SketchManager.CreatePoint(vOutline(2), vOutline(3), 0)

                    Set swPoint = Part.SketchManager.CreatePoint(vPos(0), vPos(1), 0)

                    Dim SketchSegment As SketchSegment

                    Set SketchSegment = Part.SketchManager.CreateLine(vPos(0), vOutline(1), 0, vPos(0), vOutline(3), 0)

                    End Sub

                     

                    Above code is creating like given below picture:

                     

                    CenterLine.JPG

                     

                    May be it will help you.

                    • Re: Drawing View GetOutline
                      Artem Taturevych

                      You need to deactivate the vide

                      swDocDraw.ActivateView ""

                      Set SketchSegment = Part.SketchManager.CreateLine(vPos(0), vOutline(1), 0, vPos(0), vOutline(3), 0)

                      before creating the line otherwise the line will be created in the drawing's view space and you have to transform the coordinates.