Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
draftsight
/
opt
/
dassault-systemes
/
DraftSight
/
APISDK
/
Create_Rectangular_Viewport_Example_CSharp.htm
|
|---|
<html>
<head>
<title>Create Rectangular Viewport Example (C#)</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="C# examples">
<meta name=MS-HKWD content="C# examples,Viewports">
</head>
<body>
<h1>Create Rectangular Viewport Example (C#)</h1>
<p>This example shows how to create a rectangular Viewport.</p>
<p><font face="Consolas" size="2"><span style="color:green;">
//--------------------------------------------------------------</span><br>
<span style="color:green;">// Preconditions:</span><br>
<span style="color:green;">// 1. Create a C# Windows console project.</span><br>
<span style="color:green;">// 2. Copy and paste this example into the C# IDE.</span><br>
<span style="color:green;">// 3. Add a reference to:</span><br>
<span style="color:green;">// <i>install_dir</i>\<b>APISDK\tlb\DraftSight.Interop.dsAutomation.dll</b></span><br>
<span style="color:green;">// 4. Add a reference to <b>System</b>.</span><br>
<span style="color:green;">// 5. Start DraftSight.</span><br>
<span style="color:green;">// 6. Open the Immediate window.</span><br>
<span style="color:green;">// 7. Press F5 to debug the project.</span><br>
<span style="color:green;">//</span><br>
<span style="color:green;">// Postconditions: </span><br>
<span style="color:green;">// 1. </span><span style="color:green;">A Viewport is created on Sheet2.</span><br>
<span style="color: green">// 2. Examine the drawing and output printed</span><br>
<span style="color: green">// to the Immediate window.</span><br>
<span style="color:green;">//----------------------------------------------------------------</span></font></p>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white"><span style="color:blue;">using</span> System;
<span style="color:blue;">using</span> System.Diagnostics;
<span style="color:blue;">using</span> System.Runtime.InteropServices;
<span style="color:blue;">using</span> DraftSight.Interop.dsAutomation;
<span style="color:blue;">static</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">Module1</span>
{
<span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">void</span> Main()
{
DraftSight.Interop.dsAutomation.<span style="color:#2b91af;">Application</span> dsApp;
<span style="color:#2b91af;">Document</span> dsDoc = <span style="color:blue;">default</span>(<span style="color:#2b91af;">Document</span>);
<span style="color:blue;">string</span> SheetName = <span style="color:blue;">null</span>;
<span style="color:blue;">object</span>[] dsSheets = <span style="color:blue;">null</span>;
<span style="color:#2b91af;">Sheet</span> dsSheet = <span style="color:blue;">default</span>(<span style="color:#2b91af;">Sheet</span>);
<span style="color: #0000FF">int</span> index = 0;
<span style="color:#2b91af;">Viewport</span> dsViewport = <span style="color:blue;">default</span>(<span style="color:#2b91af;">Viewport</span>);
<span style="color:#2b91af;">MathUtility</span> dsMathUtility = <span style="color:blue;">default</span>(<span style="color:#2b91af;">MathUtility</span>);
<span style="color:#2b91af;">MathPoint</span> startCorner = <span style="color:blue;">default</span>(<span style="color:#2b91af;">MathPoint</span>);
<span style="color:#2b91af;">MathPoint</span> oppositeCorner = <span style="color:blue;">default</span>(<span style="color:#2b91af;">MathPoint</span>);
<span style="color:blue;">bool</span> isClipped = <span style="color:blue;">false</span>;
<span style="color:green;">//Connect to DraftSight</span>
dsApp = (DraftSight.Interop.dsAutomation.<span style="color:#2b91af;">Application</span>)<span style="color:#2b91af;">Marshal</span>.GetActiveObject(<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> ((dsDoc != <span style="color:blue;">null</span>)) {
<span style="color:green;">//Switch to Sheet space and activate Sheet2</span>
dsSheets = (<span style="color:blue;">object</span>[])dsDoc.<b>GetSheets</b>();
<span style="color:blue;">if</span> (dsSheets <span style="color:blue;">is</span> System.<span style="color:#2b91af;">Array</span>) {
<span style="color:blue;">for</span> (index = 0; index < dsSheets.Length; index++) {
dsSheet = (<span style="color:#2b91af;">Sheet</span>)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:green;">//Activate sheet</span>
dsSheet.<b>Activate</b>();
}
}
}
<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(SheetName + <span style="color:#a31515;">":"</span>);
<span style="color:#2b91af;">Debug</span>.Print(<span style="color:#a31515;">" Viewport:"</span>);
dsViewport.<b>GetIsClipped</b>(<span style="color:blue;">out</span> isClipped);
<span style="color:#2b91af;">Debug</span>.Print(<span style="color:#a31515;">" Clipped by an entity? "</span> + isClipped);
<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>);
}
}
}</pre>
</body>
</html>