Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
draftsight
/
opt
/
dassault-systemes
/
DraftSight
/
APISDK
/
Create_Circular_Pattern_Example_CSharp.htm
|
|---|
<html>
<head>
<title>Create Circular Pattern 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,circular patterns">
<meta name=MS-HKWD content="C# examples,Circles">
</head>
<body>
<h1>Create Circular Pattern Example (C#)</h1>
<p>This example shows how to construct a circular pattern of Circles in a
DraftSight drawing.</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 <b>System</b> and <b>System.Windows.Forms</b>.
// 5. Start DraftSight and open a drawing document.
// 6. Run the macro.
//
// Postconditions:
// 1. Constructs three Circles.
// 2. Creates a circular pattern using the Circles.
// 3. Zooms the drawing to fit.
// 4. Examine the drawing.
//----------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using DraftSight.Interop.dsAutomation;
using System.Runtime.InteropServices;
using System.Windows.Forms;
</pre>
<pre>static class Module1
{
public static void Main()
{
DraftSight.Interop.dsAutomation.Application dsApp;
Document dsDoc = default(Document);
Model dsModel = default(Model);
SketchManager dsSketchManager = default(SketchManager);
Circle dsCircle1 = default(Circle);
Circle dsCircle2 = default(Circle);
Circle dsCircle3 = default(Circle);</pre>
<pre> //Connect to DraftSight
dsApp = (DraftSight.Interop.dsAutomation.Application)Marshal.GetActiveObject("DraftSight.Application");
dsApp.AbortRunningCommand(); // abort any command currently running in DraftSight to avoid nested commands</pre>
<pre> //Get active document
dsDoc = dsApp.<b>GetActiveDocument</b>();</pre>
<pre> if ((dsDoc != null)) {
//Get model space
dsModel = dsDoc.<b>GetModel</b>();</pre>
<pre> //Get Sketch Manager
dsSketchManager = dsModel.<b>GetSketchManager</b>();</pre>
<pre> //Circle parameters
double center1X = 0;
double center2X = 0;
double center3X = 0;
center1X = 30.0;
center2X = 60.0;
center3X = 90.0;</pre>
<pre> double center1Y = 0;
double center2Y = 0;
double center3Y = 0;
center1Y = 30.0;
center2Y = 60.0;
center3Y = 90.0;</pre>
<pre> double center1Z = 0;
double center2Z = 0;
double center3Z = 0;
center1Z = 0.0;
center2Z = 0.0;
center3Z = 0.0;</pre>
<pre> double radius1 = 0;
double radius2 = 0;
double radius3 = 0;
radius1 = 10.0;
radius2 = 10.0;
radius3 = 10.0;</pre>
<pre> //Draw the Circles
dsCircle1 = dsSketchManager.<b>InsertCircle</b>(center1X, center1Y, center1Z, radius1);
dsCircle2 = dsSketchManager.<b>InsertCircle</b>(center2X, center2Y, center2Z, radius2);
dsCircle3 = dsSketchManager.<b>InsertCircle</b>(center3X, center3Y, center3Z, radius3);</pre>
<pre> //Circular pattern parameters
double angleBetween = 0;
angleBetween = 3.14159265358979 / 2; //90 degrees in radians</pre>
<pre> double fillAngle = 0;
fillAngle = 4.71238898; //270 degrees in radians
</pre>
<pre> int totalNumber = 0;
totalNumber = 4;</pre>
<pre> double elementBasePointX = 0;
double elementBasePointY = 0;
double axisPointX = 0;
double axisPointY = 0;
elementBasePointX = 0.0;
elementBasePointY = 0.0;
axisPointX = 0.0;
axisPointY = 0.0;</pre>
<pre> bool orientElementsAboutAxis = false;
orientElementsAboutAxis = true;</pre>
<pre> //Prepare list of entity types
int[] dsEntityTypes = new int[3];
dsEntityTypes[0] = (int)dsObjectType_e.dsCircleType;
dsEntityTypes[1] = (int)dsObjectType_e.dsCircleType;
dsEntityTypes[2] = (int)dsObjectType_e.dsCircleType;</pre>
<pre> //Prepare list of entities
DispatchWrapper[] dsEntities = new DispatchWrapper[3];
dsEntities[0] = new DispatchWrapper(dsCircle1);
dsEntities[1] = new DispatchWrapper(dsCircle2);
dsEntities[2] = new DispatchWrapper(dsCircle3);</pre>
<pre> //Create circular pattern
dsSketchManager.<b>PatternCircular</b>(dsBasePatternOn_e.dsBasePatternOn_AngleBetweenAndElementsNumber, angleBetween, fillAngle, totalNumber, elementBasePointX, elementBasePointY, axisPointX, axisPointY, orientElementsAboutAxis, dsEntityTypes,
dsEntities);</pre>
<pre> //Zoom to fit
dsApp.<b>Zoom</b>(dsZoomRange_e.dsZoomRange_Fit, null, null);
</pre>
<pre> } else {
MessageBox.Show("There are no open documents in DraftSight.");</pre>
<pre> }
}</pre>
<pre>}</pre>
<p> </p>
</body>
</html>