> Set Viewports Example (VB.NET)
Welcome
Getting Started
SolidWorks API Help
FeatureWorks API Help
SolidWorks Document Manager API Help
eDrawings API Help
SolidWorks Routing API Help
SolidWorks Simulation API Help
SolidWorks Utilities API Help
SolidWorks Workgroup PDM API Help
Hide Table of Contents Show Table of Contents

Set Viewports Example (VB.NET)

This example shows how to set viewports and check and change whether they're linked.

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

' Preconditions:

' 1. Open:

' <SolidWorks_install_dir>\samples\tutorial\introtosw\pressure_plate.sldprt

' 2. Set some breakpoints (e.g., before and after panning the viewports).

'

' Postconditions:

' 1. Viewport arrangement set to Two View-Horizontal.

' 2. Top viewport is panned; bottom viewport also

'    panned because it is linked to top viewport.

' 3. Viewports are unlinked.

' 4. Top viewport is panned; bottom view isn't panned

'    because viewports were unlinked.

' 5. Viewport arrangement set to single view.

'

' NOTE: Because this model is used in a SolidWorks

'       online tutorial, do not save any changes

'       when you close the model document.

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

Imports SolidWorks.Interop.sldworks

Imports SolidWorks.Interop.swconst

Imports System

Imports System.Diagnostics

 

Partial Class SolidWorksMacro

 

    Public Sub main()

 

        Dim swModel As ModelDoc2

        Dim swModelViewManager As ModelViewManager

        Dim swModelView As ModelView

 

        swModel = swApp.ActiveDoc

 

        ' Set the viewport arrangement to Two View-Horizontal

        Debug.Print("Set viewport arrangement to Two View-Horizontal...")

        swModelViewManager = swModel.ModelViewManager

        swModelViewManager.ViewportDisplay = swViewportDisplay_e.swViewportTwoViewHorizontal

 

        ' Check to see if the viewports are linked

        Debug.Print("Are viewports linked? " & swModelViewManager.LinkedViews)

 

        ' Pan the model in the top viewport

        ' The model in the bottom viewport also pans

        ' because it's linked to the top viewport

        Debug.Print("Panning the model in top viewport; model in bottom viewport also pans because the viewports are linked...")

        swModelView = swModel.ActiveView

        swModelView.TranslateBy(-0.0005535897435897, 0)

        swModelView.TranslateBy(-0.0005535897435897, 0)

        swModelView.TranslateBy(-0.0005535897435897, 0.0005535897435897)

        swModelView.TranslateBy(-0.003875128205128, 0.001660769230769)

        swModelView.TranslateBy(-0.004982307692308, 0.0005535897435897)

        swModelView.TranslateBy(-0.005535897435897, 0.0005535897435897)

        swModelView.TranslateBy(-0.007196666666667, 0)

        swModelView.TranslateBy(-0.006089487179487, 0)

        swModelView.TranslateBy(-0.006643076923077, 0)

        swModelView.TranslateBy(-0.004982307692308, 0)

        swModelView.TranslateBy(-0.005535897435897, 0)

        swModelView.TranslateBy(-0.002214358974359, 0)

        swModelView.TranslateBy(-0.0005535897435897, 0)

        swModelView.TranslateBy(0, -0.0005535897435897)

        swModelView.TranslateBy(0, -0.001107179487179)

        swModelView.TranslateBy(0.001107179487179, -0.002214358974359)

        swModelView.TranslateBy(0.001660769230769, -0.004982307692308)

        swModelView.TranslateBy(0.002214358974359, -0.006643076923077)

        swModelView.TranslateBy(0.001660769230769, -0.006089487179487)

        swModelView.TranslateBy(0.001107179487179, -0.003321538461538)

        swModelView.TranslateBy(0, -0.001107179487179)

        swModelView.TranslateBy(0, 0.0005535897435897)

        swModelView.TranslateBy(0, 0.001107179487179)

        swModelView.TranslateBy(0.0005535897435897, 0.0005535897435897)

        swModelView.TranslateBy(0.001107179487179, 0.003875128205128)

        swModelView.TranslateBy(0.002767948717949, 0.004428717948718)

        swModelView.TranslateBy(0.002214358974359, 0.006643076923077)

        swModelView.TranslateBy(0.002767948717949, 0.005535897435897)

        swModelView.TranslateBy(0.003875128205128, 0.006643076923077)

        swModelView.TranslateBy(0.002214358974359, 0.004428717948718)

        swModelView.TranslateBy(0, 0.001107179487179)

        swModelView.TranslateBy(-0.0005535897435897, 0)

        swModelView.TranslateBy(-0.0005535897435897, 0)

        swModelView.TranslateBy(-0.001660769230769, 0)

        swModelView.TranslateBy(-0.003875128205128, 0.0005535897435897)

        swModelView.TranslateBy(-0.01328615384615, 0.002767948717949)

        swModelView.TranslateBy(-0.01328615384615, 0.002767948717949)

        swModelView.TranslateBy(-0.0160541025641, 0.003321538461538)

        swModelView.TranslateBy(-0.01273256410256, 0.003321538461538)

        swModelView.TranslateBy(-0.006643076923077, 0.001660769230769)

        swModelView.TranslateBy(-0.002767948717949, 0.0005535897435897)

        swModelView.TranslateBy(0.0005535897435897, 0)

        swModelView.TranslateBy(0.002767948717949, 0)

        swModelView.TranslateBy(0.008857435897436, -0.0005535897435897)

        swModelView.TranslateBy(0.02435794871795, -0.001660769230769)

        swModelView.TranslateBy(0.03044743589744, -0.002214358974359)

        swModelView.TranslateBy(0.01826846153846, -0.004428717948718)

        swModelView.TranslateBy(0.01217897435897, -0.004982307692308)

        swModelView.TranslateBy(0.004428717948718, -0.004982307692308)

        swModelView.TranslateBy(0.001660769230769, -0.003875128205128)

        swModelView.TranslateBy(0, -0.001660769230769)

        swModelView.TranslateBy(0.0005535897435897, -0.0005535897435897)

        swModelView.TranslateBy(0.001660769230769, 0)

        swModelView.TranslateBy(0.002214358974359, 0)

        swModelView.TranslateBy(0.008303846153846, 0.001107179487179)

        swModelView.TranslateBy(0.009411025641026, 0.004428717948718)

        swModelView.TranslateBy(0.01328615384615, 0.008303846153846)

        swModelView.TranslateBy(0.003875128205128, 0.007750256410256)

        swModelView.TranslateBy(-0.002767948717949, 0.007750256410256)

        swModelView.TranslateBy(-0.006643076923077, 0.003875128205128)

        swModelView.TranslateBy(-0.006643076923077, 0)

        swModelView.TranslateBy(-0.006089487179487, 0)

        swModelView.TranslateBy(-0.008857435897436, 0)

        swModelView.TranslateBy(-0.006643076923077, -0.001107179487179)

        swModelView.TranslateBy(-0.002767948717949, -0.003321538461538)

        swModelView.TranslateBy(-0.001660769230769, -0.001660769230769)

        swModelView.TranslateBy(-0.0005535897435897, -0.001107179487179)

        swModelView.TranslateBy(0, -0.0005535897435897)

        swModelView.TranslateBy(0, 0.0005535897435897)

        swModelView.TranslateBy(0, 0.0005535897435897)

 

        ' Fit the model in each viewport

        swModel.ViewZoomtofit2()

 

        ' Unlink the viewports

        Debug.Print("Unlink the viewports...")

        swModelViewManager.LinkedViews = False

        Debug.Print("Are viewports linked? " & swModelViewManager.LinkedViews)

 

        ' Pan the model in the top viewport

        ' The model in the bottom viewport doesn't pan

        ' because it's no longer linked to the top viewport

        Debug.Print("Panning the model in top viewport; model in bottom viewport doesn't pan because the viewports are no longer linked...")

        swModelView = swModel.ActiveView

        swModelView.TranslateBy(-0.0005535897435897, 0)

        swModelView.TranslateBy(-0.0005535897435897, 0)

        swModelView.TranslateBy(-0.0005535897435897, 0.0005535897435897)

        swModelView.TranslateBy(-0.003875128205128, 0.001660769230769)

        swModelView.TranslateBy(-0.004982307692308, 0.0005535897435897)

        swModelView.TranslateBy(-0.005535897435897, 0.0005535897435897)

        swModelView.TranslateBy(-0.007196666666667, 0)

        swModelView.TranslateBy(-0.006089487179487, 0)

        swModelView.TranslateBy(-0.006643076923077, 0)

        swModelView.TranslateBy(-0.004982307692308, 0)

        swModelView.TranslateBy(-0.005535897435897, 0)

        swModelView.TranslateBy(-0.002214358974359, 0)

        swModelView.TranslateBy(-0.0005535897435897, 0)

        swModelView.TranslateBy(0, -0.0005535897435897)

        swModelView.TranslateBy(0, -0.001107179487179)

        swModelView.TranslateBy(0.001107179487179, -0.002214358974359)

        swModelView.TranslateBy(0.001660769230769, -0.004982307692308)

        swModelView.TranslateBy(0.002214358974359, -0.006643076923077)

        swModelView.TranslateBy(0.001660769230769, -0.006089487179487)

        swModelView.TranslateBy(0.001107179487179, -0.003321538461538)

        swModelView.TranslateBy(0, -0.001107179487179)

        swModelView.TranslateBy(0, 0.0005535897435897)

        swModelView.TranslateBy(0, 0.001107179487179)

        swModelView.TranslateBy(0.0005535897435897, 0.0005535897435897)

        swModelView.TranslateBy(0.001107179487179, 0.003875128205128)

        swModelView.TranslateBy(0.002767948717949, 0.004428717948718)

        swModelView.TranslateBy(0.002214358974359, 0.006643076923077)

        swModelView.TranslateBy(0.002767948717949, 0.005535897435897)

        swModelView.TranslateBy(0.003875128205128, 0.006643076923077)

        swModelView.TranslateBy(0.002214358974359, 0.004428717948718)

        swModelView.TranslateBy(0, 0.001107179487179)

        swModelView.TranslateBy(-0.0005535897435897, 0)

        swModelView.TranslateBy(-0.0005535897435897, 0)

        swModelView.TranslateBy(-0.001660769230769, 0)

        swModelView.TranslateBy(-0.003875128205128, 0.0005535897435897)

        swModelView.TranslateBy(-0.01328615384615, 0.002767948717949)

        swModelView.TranslateBy(-0.01328615384615, 0.002767948717949)

        swModelView.TranslateBy(-0.0160541025641, 0.003321538461538)

        swModelView.TranslateBy(-0.01273256410256, 0.003321538461538)

        swModelView.TranslateBy(-0.006643076923077, 0.001660769230769)

        swModelView.TranslateBy(-0.002767948717949, 0.0005535897435897)

        swModelView.TranslateBy(0.0005535897435897, 0)

        swModelView.TranslateBy(0.002767948717949, 0)

        swModelView.TranslateBy(0.008857435897436, -0.0005535897435897)

        swModelView.TranslateBy(0.02435794871795, -0.001660769230769)

        swModelView.TranslateBy(0.03044743589744, -0.002214358974359)

        swModelView.TranslateBy(0.01826846153846, -0.004428717948718)

        swModelView.TranslateBy(0.01217897435897, -0.004982307692308)

        swModelView.TranslateBy(0.004428717948718, -0.004982307692308)

        swModelView.TranslateBy(0.001660769230769, -0.003875128205128)

        swModelView.TranslateBy(0, -0.001660769230769)

        swModelView.TranslateBy(0.0005535897435897, -0.0005535897435897)

        swModelView.TranslateBy(0.001660769230769, 0)

        swModelView.TranslateBy(0.002214358974359, 0)

        swModelView.TranslateBy(0.008303846153846, 0.001107179487179)

        swModelView.TranslateBy(0.009411025641026, 0.004428717948718)

        swModelView.TranslateBy(0.01328615384615, 0.008303846153846)

        swModelView.TranslateBy(0.003875128205128, 0.007750256410256)

        swModelView.TranslateBy(-0.002767948717949, 0.007750256410256)

        swModelView.TranslateBy(-0.006643076923077, 0.003875128205128)

        swModelView.TranslateBy(-0.006643076923077, 0)

        swModelView.TranslateBy(-0.006089487179487, 0)

        swModelView.TranslateBy(-0.008857435897436, 0)

        swModelView.TranslateBy(-0.006643076923077, -0.001107179487179)

        swModelView.TranslateBy(-0.002767948717949, -0.003321538461538)

        swModelView.TranslateBy(-0.001660769230769, -0.001660769230769)

        swModelView.TranslateBy(-0.0005535897435897, -0.001107179487179)

        swModelView.TranslateBy(0, -0.0005535897435897)

        swModelView.TranslateBy(0, 0.0005535897435897)

        swModelView.TranslateBy(0, 0.0005535897435897)

 

        ' Change the viewport arrangement back to a single viewport

        swModelViewManager.ViewportDisplay = swViewportDisplay_e.swViewportSingle

 

        ' Fit the model in the viewport

        swModel.ViewZoomtofit2()

 

    End Sub

    ''' <summary>

    ''' The SldWorks swApp variable is pre-assigned for you.

    ''' </summary>

    Public swApp As SldWorks

 

End Class



Related SolidWorks Forum Content

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:   Set Viewports Example (VB.NET)
*Comment:  
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) 2012 SP05

The search functionality within the web help is in a beta test phase and you may experience periodic delays or interruptions in its performance. These are the normal and ordinary features of a beta test and shall not under any circumstances give rise to any liability on the part of DS SolidWorks or its licensors. The topics within the Web-based help are not beta topics; they document API Help (English only) 2012 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.