Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
draftsight
/
opt
/
dassault-systemes
/
DraftSight
/
APISDK
/
Create_Mathemetical_Circular_Arcs_Example_CSharp.htm
|
|---|
<html>
<head>
<title>Create Mathematical Circular Arcs 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,math circular Arcs">
</head>
<body>
<h1>Create Mathematical Circular Arcs Example (C#)</h1>
<p>This example shows how to create mathematical circular Arcs.</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 example into the C# 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. 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 mathematical circular Arc.</span>
<span style="color: green">// 4. Gets the point on the mathematical circular Arc</span>
<span style="color: green">// closest to a mathematical point. Click OK to close
// the message box.</span>
<span style="color: green">// 5. Sets the radius for the mathematical circular Arc.</span>
<span style="color: green">// 6. Creates another mathematical circular Arc.</span>
<span style="color: green">// 7. Sets the radius for the mathematical circular Arc.</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> MathCircArcCSharp
{
<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: #2b91af">MathUtility</span> dsMathUtility = dsApp.<b>GetMathUtility</b>();
<span style="color: green">//Creates mathematical circular Arc</span>
<span style="color: #2b91af">MathPoint</span> dsCenter = dsMathUtility.<b>CreatePoint</b>(3.0, 7.0, 0.0);
<span style="color: #2b91af">MathVector</span> dsNormal = dsMathUtility.<b>CreateVector</b>(1.0, 0.0, 0.0);
<span style="color: blue">double</span> dsRadius = 2;
<span style="color: #2b91af">MathVector</span> RefVector = dsMathUtility.<b>CreateVector</b>(1.0, 0.0, 0.0);
<span style="color: #2b91af">MathCircArc</span> dsMathCircArc = dsMathUtility.<b>CreateCircArc</b>(dsCenter, dsNormal, RefVector, dsRadius, 20, 45);
<span style="color: green">//Gets point on mathematical circular Arc</span>
<span style="color: green">//closest to this point</span>
<span style="color: #2b91af">MathPoint</span> point = dsMathUtility.<b>CreatePoint</b>(3.0, 7.0, 0.0);
<span style="color: #2b91af">MathPoint</span> closestPoint = dsMathCircArc.<b>GetClosestPointTo</b>(point);
<span style="color: blue">double</span> X, Y, Z;
closestPoint.<b>GetPosition</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">"Closest point of (3, 7, 0) is ("</span> + X + <span style="color: #a31515">", "</span> + Y + <span style="color: #a31515">", "</span> + Z + <span style="color: #a31515">")"</span>);
<span style="color: green">//Sets radius of mathematical circular Arc</span>
dsMathCircArc.<b>Radius</b> = 6.4;
<span style="color: green">//Creates a mathematical circular Arc defining a Circle</span>
<span style="color: green">//with the specified center, normal, and radius</span>
<span style="color: #2b91af">MathPoint</span> center = dsMathUtility.<b>CreatePoint</b>(2.0, 3.1, 0.0);
<span style="color: #2b91af">MathVector</span> normal = dsMathUtility.<b>CreateVector</b>(1.0, 0.0, 0.0);
<span style="color: blue">double</span> radius = 3.0;
<span style="color: #2b91af">MathCircArc</span> circle = dsMathUtility.<b>CreateCircle</b>(center, normal, radius);
}
}
}</pre>
</body>
</html>