Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
draftsight
/
opt
/
dassault-systemes
/
DraftSight
/
APISDK
/
Create_Rectangular_Viewport_Example_VBNET.htm
|
|---|
<html>
<head>
<title>Create Rectangular Viewport Example (VB.NET)</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="VB.NET examples">
<meta name=MS-HKWD content="VB.NET examples,Viewports">
</head>
<body>
<h1> Create Rectangular Viewport Example (VB.NET)</h1>
<p>This example shows how to create a rectangular Viewport.</p>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white"><span style="color:green;">'--------------------------------------------------------------</span>
<span style="color:green;">' Preconditions:</span>
<span style="color:green;">' 1. Create a VB.NET Windows console project.</span>
<span style="color:green;">' 2. Copy and paste this project into the VB.NET IDE.</span>
<span style="color:green;">' 3. Add a reference to</span>
<span style="color:green;">' <i>install_dir\</i><b>APISDK\tlb\DraftSight.Interop.dsAutomation.dll</b></span>
<span style="color:green;">' 4. Start DraftSight.
' 5. Open the Immediate window.</span>
<span style="color:green;">' 6. Press F5.</span>
<span style="color:green;">'</span>
<span style="color:green;">' Postconditions:
' 1. A Viewport is created on Sheet2.</span>
<span style="color: green">' 2. Examine the drawing and output printed</span>
<span style="color: green">' to the Immediate window.
'----------------------------------------------------------------</span> </pre>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white"><span style="color: blue">Imports</span> DraftSight.Interop.dsAutomation
<span style="color: blue">Module</span> <span style="color: #2b91af">Module1</span>
<span style="color: blue">Sub</span> Main()
<span style="color: blue">Dim</span> dsApp <span style="color: blue">As</span> <span style="color: #2b91af">Application</span>
<span style="color: blue">Dim</span> dsDoc <span style="color: blue">As</span> <span style="color: #2b91af">Document</span>
<span style="color: blue">Dim</span> SheetName <span style="color: blue">As</span> <span style="color: blue">String</span>
<span style="color: blue">Dim</span> dsSheets <span style="color: blue">As</span> <span style="color: blue">Object</span>
<span style="color: blue">Dim</span> dsSheet <span style="color: blue">As</span> <span style="color: #2b91af">Sheet</span>
<span style="color: blue">Dim</span> index <span style="color: blue">As</span> <span style="color: blue">Integer</span>
<span style="color: blue">Dim</span> dsViewport <span style="color: blue">As</span> <span style="color: #2b91af">Viewport</span>
<span style="color: blue">Dim</span> dsMathUtility <span style="color: blue">As</span> <span style="color: #2b91af">MathUtility</span>
<span style="color: blue">Dim</span> startCorner <span style="color: blue">As</span> <span style="color: #2b91af">MathPoint</span>
<span style="color: blue">Dim</span> oppositeCorner <span style="color: blue">As</span> <span style="color: #2b91af">MathPoint</span>
<span style="color: blue">Dim</span> isClipped <span style="color: blue">As</span> <span style="color: blue">Boolean</span>
<span style="color: green">'Connect to DraftSight</span>
dsApp = GetObject(, <span style="color: #a31515">"DraftSight.Application"</span>)
<span style="color: green">'Abort any command currently running in DraftSight</span>
<span style="color: green">'to avoid nested commands</span>
dsApp.<b>AbortRunningCommand</b>()
<span style="color: green">'Get active document</span>
dsDoc = dsApp.<b>GetActiveDocument</b>()
<span style="color: blue">If</span> <span style="color: blue">Not</span> dsDoc <span style="color: blue">Is</span> <span style="color: blue">Nothing</span> <span style="color: blue">Then</span>
<span style="color: green">'Switch to Sheet space and activate Sheet2</span>
dsSheets = dsDoc.<b>GetSheets</b>
<span style="color: blue">If</span> IsArray(dsSheets) <span style="color: blue">Then</span>
<span style="color: blue">For</span> index = LBound(dsSheets) <span style="color: blue">To</span> UBound(dsSheets)
dsSheet = dsSheets(index)
<span style="color: green">'Get sheet name</span>
SheetName = dsSheet.<b>Name</b>
<span style="color: green">'Change sheet name, if it is not a model</span>
<span style="color: blue">If</span> SheetName <> <span style="color: #a31515">"Model"</span> <span style="color: blue">Then</span>
<span style="color: green">'Activate sheet</span>
dsSheet.<b>Activate</b>()
<span style="color: blue">End</span> <span style="color: blue">If</span>
<span style="color: blue">Next</span>
<span style="color: blue">End</span> <span style="color: blue">If</span>
<span style="color: green">' Set the corners for the Viewport</span>
dsMathUtility = dsApp.<b>GetMathUtility</b>
startCorner = dsMathUtility.<b>CreatePoint</b>(0, 0, 0)
oppositeCorner = dsMathUtility.<b>CreatePoint</b>(3, 3, 0)
<span style="color: green">'Create a rectangular Viewport</span>
dsViewport = dsSheet.<b>InsertRectangularViewport</b>(<span style="color: #2b91af">dsStandardViewports_e</span>.dsStandardViewports_1, <span style="color: blue">False</span>, startCorner, oppositeCorner)
<span style="color: green">' Activate and access the rectangular Viewport</span>
dsViewport.<b>Active</b> = <span style="color: blue">True</span>
<span style="color: #2b91af">Debug</span>.Print(<span style="background-position: 0 0">SheetName</span> & <span style="color: #a31515">":"</span>)
<span style="color: #2b91af">Debug</span>.Print(<span style="color: #a31515">" Viewport:"</span>)
dsViewport.<b>GetIsClipped</b>(isClipped)
<span style="color: #2b91af">Debug</span>.Print(<span style="color: #a31515">" Clipped by an entity? "</span> & <b>isClipped</b>)
<span style="color: #2b91af">Debug</span>.Print(<span style="color: #a31515">" Height: "</span> & dsViewport.<b>Height</b>)
<span style="color: #2b91af">Debug</span>.Print(<span style="color: #a31515">" Width: "</span> & dsViewport.<b>Width</b>)
<span style="color: #2b91af">Debug</span>.Print(<span style="color: #a31515">" Locked in model workspace? "</span> & dsViewport.<b>DisplayLocked</b>)
<span style="color: #2b91af">Debug</span>.Print(<span style="color: #a31515">" Displayed in graphics area? "</span> & dsViewport.<b>IsOn</b>)
<span style="color: #2b91af">Debug</span>.Print(<span style="color: #a31515">" Visible? "</span> & dsViewport.<b>Visible</b>)
<span style="color: blue">Else</span>
<span style="color: #2b91af">Debug</span>.Print(<span style="color: #a31515">"There are no open documents in DraftSight."</span>)
<span style="color: blue">End</span> <span style="color: blue">If
</span>
<span style="color: blue">End</span> <span style="color: blue">Sub</span>
<span style="color: blue">End</span> <span style="color: blue">Module</span>
</pre>
</body>
</html>