Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
draftsight
/
opt
/
dassault-systemes
/
DraftSight
/
APISDK
/
Create_and_Change_Trace_Example_CSharp.htm
|
|---|
<html>
<head>
<title>Create and Change Trace 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,Trace">
</head>
<body>
<h1>Create and Change Trace Example (C#)</h1>
<p>This example shows how to create a Trace and change its vertex coordinates
and thickness.</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 C# Windows console project.</span>
<span style="color:green;">// 2. Copy and paste this code into the C# project.</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. Add a reference to <b>System.Windows.Forms</b>.</span>
<span style="color:green;">// 5. Start DraftSight.</span>
<span style="color:green;">// 6. Press F5.</span>
<span style="color:green;">//</span>
<span style="color:green;">// Postconditions: </span>
<span style="color:green;">// 1. Connects to DraftSight.</span>
<span style="color:green;">// 2. Gets the active document.</span>
<span style="color:green;">// 3. Creates a Trace.</span>
<span style="color:green;">// 4. Sets the vertex coordinates of the Trace.</span>
<span style="color:green;">// 5. Sets the thickness of the Trace.</span>
<span style="color:green;">// 6. Gets the vertex coordinates of the Trace.</span>
<span style="color:green;">// Click <b>OK</b> to close each message box.</span>
<span style="color:green;">// 7. Gets the thickness of the Trace.</span>
<span style="color:green;">// Click <b>OK</b> to close the message box.</span>
<span style="color:green;">//----------------------------------------------------------------</span>
<span style="color:blue;">using</span> System;
<span style="color:blue;">using</span> DraftSight.Interop.dsAutomation;
<span style="color:blue;">using</span> System.Runtime.InteropServices;
<span style="color:blue;">using</span> System.Windows.Forms;
<span style="color:blue;">namespace</span> TraceCSharp
{
<span style="color:blue;">class</span> <span style="color:#2b91af;">Program</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:green;">//Connects to DraftSight application</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:blue;">if</span> (<span style="color:blue;">null</span> == dsApp)
{
<span style="color:blue;">return</span>;
}
<span style="color:green;">//Aborts any command currently running in DraftSight</span>
<span style="color:green;">//to avoid nested commands</span>
dsApp.<b>AbortRunningCommand</b>();
<span style="color:green;">//Gets active document</span>
<span style="color:#2b91af;">Document</span> dsDoc = dsApp.<b>GetActiveDocument</b>();
<span style="color:blue;">if</span> (<span style="color:blue;">null</span> == dsDoc)
{
<span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">"There are no open documents in DraftSight."</span>);
<span style="color:blue;">return</span>;
}
<span style="color:green;">//Gets Sketch Manager</span>
<span style="color:#2b91af;">SketchManager</span> dsSketchMgr = dsDoc.GetModel().<b>GetSketchManager</b>();
<span style="color:green;">//Creates array for Trace vertex coordinates</span>
<span style="color:blue;">double</span>[] CoordinatesArray =
{
0, 0, 0,
5, 5, 0,
-1, 10, 0,
4, 8, 0
};
<span style="color:green;">//Creates Trace </span>
<span style="color:#2b91af;">Trace</span> dsTrace = dsSketchMgr.<b>InsertTrace</b>(CoordinatesArray);
<span style="color:green;">//Sets the vertex coordinates of trace</span>
dsTrace.<b>SetVertex1Coordinate</b>(1.2, 2.0, 0.0);
dsTrace.<b>SetVertex2Coordinate</b>(1.1, 2.3, 0.0);
dsTrace.<b>SetVertex3Coordinate</b>(2.2, 1.0, 0.0);
dsTrace.<b>SetVertex4Coordinate</b>(2.2, 3.0, 0.0);
<span style="color:green;">//Sets Trace thickness</span>
dsTrace.<b>Thickness</b> = 2.0;
<span style="color:green;">//Gets Trace vertex coordinates</span>
<span style="color:blue;">double</span> X, Y, Z;
dsTrace.<b>GetVertex1Coordinate</b>(<span style="color:blue;">out</span> X, <span style="color:blue;">out</span> Y, <span style="color:blue;">out</span> Z);
<span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">"GetVertex1Coordinate: ("</span> + X + <span style="color:#a31515;">", "</span> + Y + <span style="color:#a31515;">", "</span> + Z + <span style="color:#a31515;">")"</span>);
dsTrace.<b>GetVertex2Coordinate</b>(<span style="color:blue;">out</span> X, <span style="color:blue;">out</span> Y, <span style="color:blue;">out</span> Z);
<span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">"GetVertex2Coordinate: ("</span> + X + <span style="color:#a31515;">", "</span> + Y + <span style="color:#a31515;">", "</span> + Z + <span style="color:#a31515;">")"</span>);
dsTrace.<b>GetVertex3Coordinate</b>(<span style="color:blue;">out</span> X, <span style="color:blue;">out</span> Y, <span style="color:blue;">out</span> Z);
<span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">"GetVertex3Coordinate: ("</span> + X + <span style="color:#a31515;">", "</span> + Y + <span style="color:#a31515;">", "</span> + Z + <span style="color:#a31515;">")"</span>);
dsTrace.<b>GetVertex3Coordinate</b>(<span style="color:blue;">out</span> X, <span style="color:blue;">out</span> Y, <span style="color:blue;">out</span> Z);
<span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">"GetVertex4Coordinate: ("</span> + X + <span style="color:#a31515;">", "</span> + Y + <span style="color:#a31515;">", "</span> + Z + <span style="color:#a31515;">")"</span>);
<span style="color:green;">//Gets Trace thickness</span>
<span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">"Thickness: "</span> + dsTrace.<b>Thickness</b>);
}
}
}</pre>
</body>
</html>