Hide Table of Contents

Reposition Drawing Views to Avoid Overlap Example (VBA)

This example shows how to reposition drawing views to avoid overlap. Some assumptions about the starting positions of the views are made.

 

'-------------------------------------

'

' Preoconditions: Drawing with three drawing views is open.

'

' Postconditions: Drawing views are repositioned so that none of them overlap.

'

'--------------------------------------

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

    Dim vPos()                      As Variant

    Dim nNumView                    As Long

    Dim bRet                        As Boolean

    

    Set swApp = CreateObject("SldWorks.Application")

    Set swModel = swApp.ActiveDoc

    Set swDraw = swModel

    

    nNumView = 0

    

    Set swView = swDraw.GetFirstView

    Do While Not swView Is Nothing

        ReDim Preserve vOutline(nNumView)

        ReDim Preserve vPos(nNumView)

        vOutline(nNumView) = swView.GetOutline

        vPos(nNumView) = swView.position

    

        Debug.Print "View = " + swView.GetName2

        Debug.Print "  Pos = (" & vPos(nNumView)(0) * 1000# & ", " & vPos(nNumView)(1) * 1000# & ") mm"

        Debug.Print "  Min = (" & vOutline(nNumView)(0) * 1000# & ", " & vOutline(nNumView)(1) * 1000# & ") mm"

        Debug.Print "  Max = (" & vOutline(nNumView)(2) * 1000# & ", " & vOutline(nNumView)(3) * 1000# & ") mm"

        

        nNumView = nNumView + 1

        

        Set swView = swView.GetNextView

    Loop

    

    ' sheet

    Set swView = swDraw.GetFirstView

    

    ' View 1

    Set swView = swView.GetNextView

    

    

    'View 2 - vertically aligned to view 1

    Set swView = swView.GetNextView

    

    vPos(2)(1) = vPos(1)(1) + _

                    (vOutline(1)(3) - vPos(1)(1)) + _

                    (vPos(2)(1) - vOutline(2)(1))

    swView.position = vPos(2)

    

    swModel.GraphicsRedraw2

    

    

    'View 3 - horizontally aligned to view 1

    Set swView = swView.GetNextView

    

    vPos(3)(0) = vPos(1)(0) + _

                    (vOutline(1)(2) - vPos(1)(0)) + _

                    (vPos(3)(0) - vOutline(3)(0))

    swView.position = vPos(3)

    

    swModel.GraphicsRedraw2

End Sub

'-------------------------------------



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Reposition Drawing Views to Avoid Overlap Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2015 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.