How to Drawing Rectang in view of GetOutline?

Use follow code, Drawing Rectangle is not in the target location.

Need Rectangle target location in GetOutline.

Sub Mm16_3()

  Dim SwApp As SldWorks.SldWorks, SwDraw As ModelDoc2

  Dim SwView As SldWorks.View

  Dim swSelMgr As SldWorks.SelectionMgr

  Set SwApp = Application.SldWorks

  Set SwDraw = SwApp.ActiveDoc

  Set swSelMgr = SwDraw.SelectionManager

  Set SwView = swSelMgr.GetSelectedObject2(1)   

  With SwView

       Vpts = SwView.GetXform

        var = .GetOutline

        vPos = .Position

    End With   

    Dim Ww, Hh

    Ww = var(2) - var(0)

    xx1 = (-vPos(0) - Ww) / 2

    xx2 = (vPos(0) + Ww) / 2

    Hh = var(3) - var(1)

    yy1 = vPos(1) ' - Hh / 2

    yy2 = vPos(1) + Hh / 2

    SwDraw.SketchRectangle xx1, yy1, 0, xx2, yy2, 0, True

End Sub

SolidworksApi macros
Answers 1
YN
YN 2013-06-14 Best Answer

find method, the code is

Sub ll2()

  Dim SwApp As SldWorks.SldWorks, SwDraw As DrawingDoc

  Set SwApp = Application.SldWorks

  Set SwDraw = SwApp.ActiveDoc

  Dim vSheet As Variant, oSheet As Sheet

  Dim SwView As View, SwCurView As View

  Dim swSelMgr As SelectionMgr

  'On Error Resume Next

  With SwDraw

    Set swSelMgr = SwDraw.SelectionManager

    vSheet = .GetSheetNames

    For ii = 0 To UBound(vSheet)

       .ActivateSheet (vSheet(ii))

       Set oSheet = .GetCurrentSheet

       Set SwView = .GetFirstView

       Do While Not SwView Is Nothing

        If SwView.GetName2 Like "*主视图" Then

          SwDraw.Extension.SelectByID2 SwView.GetName2, "DRAWINGVIEW", 0, 0, 0, False, -1, Nothing, 0

          Set SwView = swSelMgr.GetSelectedObject2(1)

          Debug.Print ii, SwView.GetName2

          ManualBreakOutSection SwDraw, .GetCurrentSheet, SwView, 0.05

        End If

        Set SwView = SwView.GetNextView

       Loop

       'Debug.Print

    Next ii

  End With

End Sub