Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
draftsight / opt / dassault-systemes / DraftSight / APISDK / Create_Angular_Dimensions_Example_CSharp.htm
Size: Mime:
<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(&quot;DraftSight.Application&quot;);
	    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(&quot;There are no open documents in DraftSight.&quot;);
                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 = &quot;AngularDimArc&quot;;</pre>
<pre>            AngularDimension dsAngularDim = dsSketchMgr.<b>InsertAngularDimensionArc</b>(dsArc, dimPosition, dimTextOverride);</pre>
<pre>            Debug.Print(Environment.NewLine + &quot;An angular Dimension for an arc was added.&quot;);</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 + &quot;An angular Dimension using two lines was added.&quot;);</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 + &quot;An angular Dimension using three points was added.&quot;);</pre>
<pre>            return dsAngular3PointDim;
        }</pre>
<pre>        private static void PrintAngularDimProperties(AngularDimension dsAngularDim)
        {
            Debug.Print(&quot;  Angular Dimension parameters...&quot;);</pre>
<pre>            Debug.Print(&quot;    Type = &quot; + 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(&quot;    Dimension style = &quot; + dsGeneralDim.<b>DimensionStyle</b>);
            Debug.Print(&quot;    Handle = &quot; + dsGeneralDim.<b>Handle</b>);
            Debug.Print(&quot;    Measurement (in radians) = &quot; + dsGeneralDim.<b>Measurement</b>.ToString());
            Debug.Print(&quot;    Related = &quot; + dsGeneralDim.<b>Related</b>.ToString());
            Debug.Print(&quot;    Text override = &quot; + dsGeneralDim.<b>TextOverride</b>);
            Debug.Print(&quot;    Text rotation = &quot; + dsGeneralDim.<b>TextRotation</b>);</pre>
<pre>            //Get text position
            double x, y;
            dsGeneralDim.<b>GetTextPosition</b>(out x, out y);
            Debug.Print(&quot;    Text position (&quot; + x + &quot;,&quot; + y + &quot;)&quot;);</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(&quot;    Center point (&quot; + x + &quot;,&quot; + y + &quot;,&quot; + z + &quot;)&quot;);</pre>
<pre>            //Get arc point
            dsAngularDim.<b>GetArcPoint</b>(out x, out y, out z);
            Debug.Print(&quot;    Arc point (&quot; + x + &quot;,&quot; + y + &quot;,&quot; + z + &quot;)&quot;);</pre>
<pre>            //Get first line's start point
            dsAngularDim.<b>GetLine1Point</b>(out x, out y, out z);
            Debug.Print(&quot;    Line1's start point (&quot; + x + &quot;,&quot; + y + &quot;,&quot; + z + &quot;)&quot;);</pre>
<pre>            //Get first line end point
            dsAngularDim.<b>GetLine1EndPoint</b>(out x, out y, out z);
            Debug.Print(&quot;    Line1's end point (&quot; + x + &quot;,&quot; + y + &quot;,&quot; + z + &quot;)&quot;);</pre>
<pre>            //Get second line start point
            dsAngularDim.<b>GetLine2Point</b>(out x, out y, out z);
            Debug.Print(&quot;    Line2's start point (&quot; + x + &quot;,&quot; + y + &quot;,&quot; + z + &quot;)&quot;);</pre>
<pre>            //Get second line end point
            dsAngularDim.<b>GetLine2EndPoint</b>(out x, out y, out z);
            Debug.Print(&quot;    Line2's end point (&quot; + x + &quot;,&quot; + y + &quot;,&quot; + z + &quot;)&quot;);            
        }
    }
}</pre>
<p>&nbsp;</p>
</font>
<p>&nbsp;</p>

</body>

</html>