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 / Insert_SimpleNote_Example_CSharp.htm
Size: Mime:
<html>

<head>
<title>Insert SimpleNote 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,SimpleNotes">
<meta name=MS-HKWD content="C# examples,selection filter">
<meta name=MS-HKWD content="C# examples,Selection Manager">
<meta name=MS-HKWD content="Selection Manager">
<meta name=MS-HKWD content="Selection filter">
<meta name=MS-HKWD content="SimpleNote">
<meta name=MS-HKWD content="C# examples,Layers">
<meta name=MS-HKWD content="C# examples,Layer Manager">
<meta name=MS-HKWD content="Layer">
<meta name=MS-HKWD content="Layer Manager">
<meta name=MS-HKWD content="C# examples,get entities">
</head>


<body>
<h1>Insert SimpleNote Example (C#)</h1>
<p>This example shows how to insert and change a SimpleNote in a drawing document.</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>, <b>System.Runtime.InteropServices</b>,
//    and <b>System.Windows.Forms</b>.
// 5. Start DraftSight and open a document.
// 6. Start debugging the project.
//
// Postconditions: 
// 1. A message box pops up when a SimpleNote is
//    inserted in the drawing.
// 2. The selection filter is set to select SimpleNotes only and
//    is activated.
// 3. The SimpleNote is selected and its text changed. Examine 
//    the drawing to verify.
//----------------------------------------------------------------</pre>
<pre>using DraftSight.Interop.dsAutomation;
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;</pre>
<pre>static class Module1
{
    public static void Main()
	{
	DraftSight.Interop.dsAutomation.Application dsApp;</pre>
<pre>	Document dsDoc = default(Document);
	Model dsModel = default(Model);
	SketchManager dsSketchManager = default(SketchManager);
	SimpleNote dsSimpleNote = default(SimpleNote);
	double startX = 0;
	double startY = 0;
	double startZ = 0;
        string noteValue;
        double angle = 0;
        double height;</pre>
<pre>	//Connect to DraftSight
        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

	//Get active document
	dsDoc = dsApp.<b>GetActiveDocument</b>();
	if ((dsDoc != null)) {
		//Get model space
		dsModel = dsDoc.<b>GetModel</b>();</pre>
<pre>
		//Get Sketch Manager
		dsSketchManager = dsModel.<b>GetSketchManager</b>();</pre>
<pre>
        	//SimpleNote parameters (angle value should be passed in radians)
        	startX = 0.0;
        	startY = 0.0;
        	startZ = 0.0;
        	noteValue = &quot;Sample text&quot;;
        	height = 1.0;
        	angle = Math.PI / 4; //45 degrees in radians
        </pre>
<pre>        	//Add a SimpleNote
        	dsSimpleNote = dsSketchManager.<b>InsertSimpleNote</b>(startX, startY, startZ, height, angle, noteValue);
		if ((dsSimpleNote != null)) {
			MessageBox.Show(&quot;A SimpleNote was inserted in the drawing.&quot;);
			}
			} else {
				MessageBox.Show(&quot;There are no open documents in DraftSight.&quot;);
			}</pre>
<pre>        	//Change SimpleNote text
       	 	ChangeSimpleNotesText(dsDoc, dsSketchManager);</pre>
<pre>	}
    private static void ChangeSimpleNotesText(Document dsDoc, SketchManager dsSketchManager)
        {
            //Get Selection Manager
            SelectionManager dsSelectionMgr = dsDoc.<b>GetSelectionManager</b>();</pre>
<pre>
            //Get selection filter
            SelectionFilter dsSelectioFilter = dsSelectionMgr.<b>GetSelectionFilter</b>();</pre>
<pre>            //Clear selection filter
            dsSelectioFilter.<b>Clear</b>();</pre>
<pre>            //Add filter to get only SimpleNotes
            dsSelectioFilter.<b>AddEntityType</b>(dsObjectType_e.dsSimpleNoteType);</pre>
<pre>            //Activate selection filter
            dsSelectioFilter.<b>Active</b> = true;</pre>
<pre>            //Get all Layers in drawing
            string[] layerNames = GetLayerNames(dsDoc);</pre>
<pre>            //Get SimpleNote entities
            object entityObjects;
            object entityTypes;
            dsSketchManager.<b>GetEntities</b>(dsSelectioFilter, layerNames, out entityTypes, out entityObjects);
            if (null != entityObjects &amp;&amp; null != entityTypes)
            {
                object[] dsEntityArray = (object[])entityObjects;</pre>
<pre>                const string newNoteValue = &quot;New sample text&quot;;</pre>
<pre>                //Iterate through all SimpleNote entities
                for (int index = 0; index &lt; dsEntityArray.Length; ++index)
                {
                    //Cast the selected object to SimpleNote
                    SimpleNote dsSimpleNote = dsEntityArray[index] as SimpleNote;</pre>
<pre>                    //Get SimpleNote text
                    string noteValue = dsSimpleNote.<b>Contents</b>;</pre>
<pre>                    //Set new text for SimpleNote
                    dsSimpleNote.<b>Contents</b> = newNoteValue;
                }
            }
        }</pre>
<pre>    private static string[] GetLayerNames(Document dsDoc)
        {
            string[] layerNames = null;</pre>
<pre>            LayerManager dsLayerManager = dsDoc.<b>GetLayerManager</b>();</pre>
<pre>            object[] dsLayers = (object[])dsLayerManager.<b>GetLayers</b>();
            if (null != dsLayers)
            {
                layerNames = new string[dsLayers.Length];</pre>
<pre>                for (int index = 0; index &lt; dsLayers.Length; ++index)
                {
                    Layer dsLayer = dsLayers[index] as Layer;
                    layerNames[index] = dsLayer.<b>Name</b>;
                }
            }</pre>
<pre>            return layerNames;
        }</pre>
<pre>}
 

</pre>
<pre>
</pre>
<pre>&nbsp;</pre>

</body>

</html>