Hide Table of Contents

Reposition Drawing Views to Avoid Overlap Example (VBA)

This example shows how to reposition drawing views to avoid overlap.

'-------------------------------------------------------------------
' Preconditions:
' 1. Open install_dir\samples\introsw\bolt-assembly.slddrw.
' 2. Drag Drawing View3 so that it overlaps Drawing View2.
'
' Postconditions:
' 1. Repositions Drawing View2 and Drawing View2 so that they do
'    not overlap.
' 2. Examine the drawing and the Immediate window.
'
' NOTE: Because the drawing is used elsewhere, do not save changes.
'-----------------------------------------------------------------
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 2
    Set swView = swView.GetNextView
    vPos(3)(0) = vPos(1)(0) + (vOutline(1)(1) - vPos(0)(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) 2016 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.