Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
draftsight
/
opt
/
dassault-systemes
/
DraftSight
/
APISDK
/
Create_Angular_Dimensions_Example_CSharp.htm
|
|---|
<html>
<head>
<title>Create Angular Dimensions 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,angular Dimensions">
<meta name=MS-HKWD content="C# examples,Dimensions">
<meta name=MS-HKWD content="Dimension, angular">
<meta name=MS-HKWD content="Angular Dimension">
<meta name=MS-HKWD content="Dimension">
<meta name=MS-HKWD content="Dimension, general">
</head>
<body>
<h1>Create Angular Dimension Example (C#)</h1>
<p>This example shows how to create angular Dimensions using 3 points, 2 lines,
and an arc.</p>
<pre>//-------------------------------------------------------------
// Preconditions:
// 1. Create a C# Windows console project.
// 2. Copy and paste this example into the C# IDE.
// 3. Add a reference to:
// <i>install_dir</i>\<b>APISDK\tlb\DraftSight.Interop.dsAutomation.dll</b>.
// 4. Add references to System and System.Windows.Forms.
// 5. Set a breakpoint at:
// dsApp.Zoom(dsZoomRange_e.dsZoomRange_Fit, null, null);
// 6. Start DraftSight and open a document.
// 7. Click Start Debugging.
//
// Postconditions:
// 1. Angular Dimensions using 3 points, 2 lines, and an arc are created.
// 2. Examine the Output or Immediate window.
// 3. Click Continue.
// 4. Examine the drawing.
//------------------------------------------------------------</pre>
<pre>using System;
using System.Collections.Generic;
using System.Text;
using DraftSight.Interop.dsAutomation;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;</pre>
<pre>namespace AddAngularDimension
{
class Program
{
private static DraftSight.Interop.dsAutomation.Application dsApp;</pre>
<pre> static void Main(string[] args)
{
//Connect to the DraftSight application
dsApp = (DraftSight.Interop.dsAutomation.Application)Marshal.GetActiveObject("DraftSight.Application");
dsApp.<b>AbortRunningCommand</b>(); // abort any command currently running in DraftSight to avoid nested commands</pre>
<pre> //Get the active document
Document dsDoc = dsApp.<b>GetActiveDocument</b>();
if (null == dsDoc)
{
MessageBox.Show("There are no open documents in DraftSight.");
return;
}</pre>
<pre> //Get the model space
Model dsModel = dsDoc.<b>GetModel</b>();</pre>
<pre> //Get the sketch manager
SketchManager dsSketchMgr = dsModel.<b>GetSketchManager</b>();</pre>
<pre> //Add an angular Dimension using three points
AngularDimension dsAngular3PointDim = AddAngularDimensionUsing3Points(dsSketchMgr); </pre>
<pre> //Print the angular Dimension's properties
PrintAngularDimProperties(dsAngular3PointDim);</pre>
<pre> //Add an angular Dimension using two lines
AngularDimension dsAngular2LinesDim = AddAngularDimensionUsing2Lines(dsSketchMgr);</pre>
<pre> //Print the angular Dimension's properties
PrintAngularDimProperties(dsAngular2LinesDim);</pre>
<pre> //Add an angular Dimension for the arc
AngularDimension dsAngularArcDim = AddAngularDimensionForArc(dsSketchMgr);</pre>
<pre> //Print the angular Dimension's properties
PrintAngularDimProperties(dsAngularArcDim);</pre>
<pre> //Zoom to fit
dsApp.<b>Zoom</b>(dsZoomRange_e.dsZoomRange_Fit, null, null);
}</pre>
<pre> private static AngularDimension AddAngularDimensionForArc(SketchManager dsSketchMgr)
{
//Draw an arc
double centerX = 18, centerY = 2, centerZ = 0;
double radius = 3;
double startAngle = 0.0, endAngle = Math.PI / 2;
CircleArc dsArc = dsSketchMgr.<b>InsertArc</b>(centerX, centerY, centerZ, radius, startAngle, endAngle);</pre>
<pre> //Angular Dimension's position
double[] dimPosition = new double[] { 20, 5, 0 };</pre>
<pre> //Text override
string dimTextOverride = "AngularDimArc";</pre>
<pre> AngularDimension dsAngularDim = dsSketchMgr.<b>InsertAngularDimensionArc</b>(dsArc, dimPosition, dimTextOverride);</pre>
<pre> Debug.Print(Environment.NewLine + "An angular Dimension for an arc was added.");</pre>
<pre> return dsAngularDim;
}</pre>
<pre> private static AngularDimension AddAngularDimensionUsing2Lines(SketchManager dsSketchMgr)
{
//Draw two lines for an angular Dimension
Line dsFirstLine = dsSketchMgr.<b>InsertLine</b>(7, 0, 0, 10, 3, 0);
Line dsSecondLine = dsSketchMgr.<b>InsertLine</b>(12, 0, 0, 15, 2, 0);</pre>
<pre> //Angular Dimension position
double[] dimPosition = new double[] { 13, 4, 0 };</pre>
<pre> //No text override - empty string
string dimTextOverride = string.Empty;</pre>
<pre> AngularDimension dsAngularDim = dsSketchMgr.<b>InsertAngularDimension2Line</b>(dsFirstLine, dsSecondLine, dimPosition, dimTextOverride);</pre>
<pre> Debug.Print(Environment.NewLine + "An angular Dimension using two lines was added.");</pre>
<pre> return dsAngularDim;
}</pre>
<pre> private static AngularDimension AddAngularDimensionUsing3Points(SketchManager dsSketchMgr)
{
//Angular Dimension parameters
double[] centerPoint = new double[] { 0, 0, 0 };
double[] angleStartPoint = new double[] { 2, 2, 0 };
double[] angleEndPoint = new double[] { 2, 4, 0 };
double[] dimPosition = new double[] { 5, 5, 0 };</pre>
<pre> //No text override - empty string
string dimTextOverride = string.Empty;</pre>
<pre> AngularDimension dsAngular3PointDim = dsSketchMgr.<b>InsertAngularDimension3Point</b>(centerPoint, angleStartPoint, angleEndPoint, dimPosition, dimTextOverride);</pre>
<pre> Debug.Print(Environment.NewLine + "An angular Dimension using three points was added.");</pre>
<pre> return dsAngular3PointDim;
}</pre>
<pre> private static void PrintAngularDimProperties(AngularDimension dsAngularDim)
{
Debug.Print(" Angular Dimension parameters...");</pre>
<pre> Debug.Print(" Type = " + dsAngularDim.<b>Type</b>.ToString());</pre>
<pre> //Get general Dimension object, which contains common Dimension properties
GeneralDimension dsGeneralDim = dsAngularDim.<b>GetGeneralDimension</b>();</pre>
<pre> Debug.Print(" Dimension style = " + dsGeneralDim.<b>DimensionStyle</b>);
Debug.Print(" Handle = " + dsGeneralDim.<b>Handle</b>);
Debug.Print(" Measurement (in radians) = " + dsGeneralDim.<b>Measurement</b>.ToString());
Debug.Print(" Related = " + dsGeneralDim.<b>Related</b>.ToString());
Debug.Print(" Text override = " + dsGeneralDim.<b>TextOverride</b>);
Debug.Print(" Text rotation = " + dsGeneralDim.<b>TextRotation</b>);</pre>
<pre> //Get text position
double x, y;
dsGeneralDim.<b>GetTextPosition</b>(out x, out y);
Debug.Print(" Text position (" + x + "," + y + ")");</pre>
<pre> //Print specific parameters for angular Dimension
double z;
//Get center point
dsAngularDim.<b>GetCenterPoint</b>(out x, out y, out z);
Debug.Print(" Center point (" + x + "," + y + "," + z + ")");</pre>
<pre> //Get arc point
dsAngularDim.<b>GetArcPoint</b>(out x, out y, out z);
Debug.Print(" Arc point (" + x + "," + y + "," + z + ")");</pre>
<pre> //Get first line's start point
dsAngularDim.<b>GetLine1Point</b>(out x, out y, out z);
Debug.Print(" Line1's start point (" + x + "," + y + "," + z + ")");</pre>
<pre> //Get first line end point
dsAngularDim.<b>GetLine1EndPoint</b>(out x, out y, out z);
Debug.Print(" Line1's end point (" + x + "," + y + "," + z + ")");</pre>
<pre> //Get second line start point
dsAngularDim.<b>GetLine2Point</b>(out x, out y, out z);
Debug.Print(" Line2's start point (" + x + "," + y + "," + z + ")");</pre>
<pre> //Get second line end point
dsAngularDim.<b>GetLine2EndPoint</b>(out x, out y, out z);
Debug.Print(" Line2's end point (" + x + "," + y + "," + z + ")");
}
}
}</pre>
<p> </p>
</font>
<p> </p>
</body>
</html>