Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
draftsight
/
opt
/
dassault-systemes
/
DraftSight
/
APISDK
/
Create_Highlight_Selection_Set_Example_CSharp.htm
|
|---|
<html>
<head>
<title>Create Highlight Selection set 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,highlight selection set">
</head>
<body>
<h1>Create Highlight Selection Set Example (C#)</h1>
<p>This example shows how to create a highlight selection set.</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 active document.</span>
<span style="color:green;">// 3. Gets Sketch Manager.</span>
<span style="color:green;">// 4. Inserts a Circle and an Arc.</span>
<span style="color:green;">// 5. Creates an instance of a highlight selection set.</span>
<span style="color:green;">// 6. Adds Arc to the highlight selection set.</span>
<span style="color:green;">// 7. Move the pointer over both the Arc and Circle. Only the Arc</span>
<span style="color:green;">// is highlighted. Press F5 to continue.</span>
<span style="color:green;">// 8. Removes Arc from highlight selection set.</span>
<span style="color:green;">// 9. Adds Circle to highlight selection set.</span>
<span style="color:green;">// 10. Move the pointer over both the Arc and Circle. Only</span>
<span style="color:green;">// the Circle is highlighted.</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> HighlightSetCSharp
{
<span style="color:blue;">class</span> <span style="color:#2b91af;">Program</span>
{
<span style="color:blue;">private</span> <span style="color:blue;">static</span> DraftSight.Interop.dsAutomation.<span style="color:#2b91af;">Application</span> dsApp;
<span style="color:blue;">static</span> <span style="color:blue;">void</span> Main(<span style="color:blue;">string</span>[] args)
{
<span style="color:green;">//Connect 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;">//Abort any command currently running in DraftSight to avoid nested commands</span>
dsApp.<b>AbortRunningCommand</b>();
<span style="color:green;">//Get 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:green;">//Get Sketch Manager</span>
<span style="color:#2b91af;">SketchManager</span> dsSketchMgr = dsDoc.<b>GetModel</b>().<b>GetSketchManager</b>();
<span style="color:green;">//Draw a Circle and Arc</span>
<span style="color:#2b91af;">Circle</span> dsCircle = dsSketchMgr.<b>InsertCircle</b>(5.0, 5.0, 0.0, 10.0);
<span style="color:#2b91af;">CircleArc</span> dsCircleArc = dsSketchMgr.<b>InsertArc</b>(7.5, 7.5, 0.0, 10.0, 2.5, 5.0);
dsApp.<b>Zoom</b>(<span style="color:#2b91af;">dsZoomRange_e</span>.dsZoomRange_Bounds, <span style="color:blue;">null</span>, <span style="color:blue;">null</span>);
<span style="color:green;">//Create highlight selection set</span>
<span style="color:#2b91af;">DispatchWrapper</span>[] dsEntities = <span style="color:blue;">new</span> <span style="color:#2b91af;">DispatchWrapper</span>[1];
dsEntities[0] = <span style="color:blue;">new</span> <span style="color:#2b91af;">DispatchWrapper</span>(dsCircleArc);
<span style="color:#2b91af;">HighlightSet</span> dsHighlightSet = dsDoc.CreateHighlightSet(dsEntities);
dsHighlightSet.<b>Highlight</b> = <span style="color:blue;">true</span>;
dsDoc.<b>Rebuild</b>(<span style="color:#2b91af;">dsRebuildType_e</span>.dsRebuildType_AllViewports);
System.Diagnostics.<span style="color:#2b91af;">Debugger</span>.Break();
<span style="color:green;">//Move pointer over the Arc and Circle</span>
<span style="color:green;">//Only the Arc is highlighted
//Press F5 to continue</span>
<span style="color:green;">//Remove entities from highlight selection set</span>
dsHighlightSet.<b>RemoveEntities</b>(dsEntities);
dsDoc.<b>Rebuild</b>(<span style="color:#2b91af;">dsRebuildType_e</span>.dsRebuildType_AllViewports);
<span style="color:green;">//Add Circle to highlight selection set</span>
dsEntities.<b>Initialize</b>();
dsEntities[0] = <span style="color:blue;">new</span> <span style="color:#2b91af;">DispatchWrapper</span>(dsCircle);
dsHighlightSet.<b>AddEntities</b>(dsEntities);
dsHighlightSet.<b>Highlight</b> = <span style="color:blue;">true</span>;
dsDoc.<b>Rebuild</b>(<span style="color:#2b91af;">dsRebuildType_e</span>.dsRebuildType_AllViewports);
<span style="color:green;">//Move pointer over the Arc and Circle</span>
<span style="color:green;">//Only the Circle is highlighted</span>
}
}
}</pre>
</body>
</html>