Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
draftsight
/
opt
/
dassault-systemes
/
DraftSight
/
APISDK
/
Create_Rectangular_Viewport_Example_VBA.htm
|
|---|
<html>
<head>
<title>Create Rectangular Viewport Example (VBA)</title>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link rel="stylesheet" type="text/css" href="ApiHelp.css">
<meta name=MS-HKWD content="VBA examples">
<meta name=MS-HKWD content="VBA examples, Viewports">
</head>
<body>
<h1>Create Rectangular Viewport Example (VBA)</h1>
<p>This example shows how to create a rectangular Viewport.</p>
<pre>'--------------------------------------------------------------
'Preconditions:
' 1. Create a VBA macro in a software product in which VBA is
' embedded.
' 2. Copy and paste this example into the Visual Basic IDE.
' 3. Add a reference to the DraftSight type library,
' <i>install_dir</i>\<b>bin\dsAutomation.dll</b>.
' 4. Start DraftSight.
' 5 Open the Immediate window.
' 6. Run the macro.
'
' Postconditions:
' 1. A Viewport is created on Sheet2.
' 2. Examine the drawing and output printed
' to the Immediate window.
'----------------------------------------------------------------</pre>
<pre>Option Explicit</pre>
<pre>Sub main()
Dim dsApp As DraftSight.Application
Dim dsDoc As DraftSight.Document
Dim SheetName as String
Dim dsSheets As Variant
Dim dsSheet As DraftSight.Sheet
Dim index As Long
Dim dsViewport As DraftSight.Viewport
Dim dsMathUtility As DraftSight.MathUtility
Dim startCorner As DraftSight.MathPoint
Dim oppositeCorner As DraftSight.MathPoint
Dim isClipped As Boolean </pre>
<pre> 'Connect to DraftSight
Set dsApp = GetObject(, "DraftSight.Application") </pre>
<pre> 'Abort any command currently running in DraftSight
'to avoid nested commands
dsApp.<b>AbortRunningCommand</b> </pre>
<pre> 'Get active document
Set dsDoc = dsApp.<b>GetActiveDocument</b>()
If Not dsDoc Is Nothing Then</pre>
<pre> 'Switch to Sheet space and activate Sheet2
dsSheets = dsDoc.<b>GetSheets</b>
If IsArray(dsSheets) Then
For index = LBound(dsSheets) To UBound(dsSheets)
Set dsSheet = dsSheets(index)
'Get sheet name
SheetName = dsSheet.<b>Name</b>
'Change sheet name, if it is not a model
If SheetName <> "Model" Then
'Activate sheet
dsSheet.<b>Activate</b>
End If
Next
End If </pre>
<pre> ' Set the corners for the Viewport
Set dsMathUtility = dsApp.<b>GetMathUtility</b>
Set startCorner = dsMathUtility.<b>CreatePoint</b>(0, 0, 0)
Set oppositeCorner = dsMathUtility.<b>CreatePoint</b>(3, 3, 0) </pre>
<pre> 'Create a rectangular Viewport
Set dsViewport = dsSheet.<b>InsertRectangularViewport</b>(dsStandardViewports_1, False, startCorner, oppositeCorner) </pre>
<pre> ' Activate and access the rectangular Viewport
dsViewport.<b>Active</b> = True </pre>
<pre> Debug.Print (SheetName & ":")
Debug.Print " Viewport:"
dsViewport.<b>GetIsClipped</b> (isClipped)
Debug.Print " Clipped by an entity? " & isClipped
Debug.Print " Height: " & dsViewport.<b>Height</b>
Debug.Print " Width: " & dsViewport.<b>Width</b>
Debug.Print " Locked in model workspace? " & dsViewport.<b>DisplayLocked</b>
Debug.Print " Displayed in graphics area? " & dsViewport.<b>IsOn</b>
Debug.Print " Visible? " & dsViewport.<b>Visible</b> </pre>
<pre> Else
Debug.Print "There are no open documents in DraftSight." </pre>
<pre> End If
End Sub</pre>
</body>
</html>