Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
draftsight
/
opt
/
dassault-systemes
/
DraftSight
/
APISDK
/
Load_and_Activate_LineStyles_Example_CSharp.htm
|
|---|
<html>
<head>
<title>Load and Activate LineStyles Example 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,LineStyles">
<meta name=MS-HKWD content="C# examples,LineStyle Manager">
<meta name=MS-HKWD content="C# examples,Lines">
</head>
<body>
<h1>Load and Activate LineStyles Example (C#)</h1>
<p>This example shows how to load and activate LineStyles.</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 references to <b>System</b> and <b>System.Windows.Forms</b>.</span>
<span style="color:green;">// 5. Start DraftSight and open a document.</span>
<span style="color:green;">// 6. Start debugging the project.</span>
<span style="color:green;">//</span>
<span style="color:green;">// Postconditions: </span>
<span style="color:green;">// 1. Gets the active document.</span>
<span style="color:green;">// 2. Gets the LineStyle Manager.</span>
<span style="color:green;">// 3. Loads the BATTING and ZIGAG LineStyles.</span>
<span style="color:green;">// 4. Activates and draws a Line for each LineStyle </span>
<span style="color:green;">// loaded in Step 3.</span>
<span style="color:green;">//----------------------------------------------------------------</span>
<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;">using</span> System;
<span style="color:blue;">static</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">Program</span>
{
<span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">void</span> Main(<span style="color:blue;">string</span>[] args)
{
DraftSight.Interop.dsAutomation.<span style="color:#2b91af;">Application</span> dsApp;
<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:green;">// Abort any command currently running in DraftSight to avoid nested commands</span>
dsApp.<b>AbortRunningCommand</b>();
<span style="color:blue;">if</span> (<span style="color:blue;">null</span> == dsApp)
{
<span style="color:blue;">return</span>;
}
<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 LineStyle manager</span>
<span style="color:#2b91af;">LineStyleManager</span> dsLineStyleMgr = dsDoc.<b>GetLineStyleManager</b>();
<span style="color:green;">//Load LineStyles</span>
<span style="color:blue;">string</span> lineStyleFilePath = System.IO.<span style="color:#2b91af;">Path</span>.Combine(
dsApp.<b>GetSystemFiles</b>().<b>GetUserDataPath</b>(),
<span style="color:#a31515;">"Linestyles"</span>);
<span style="color:blue;">string</span> lineStyleFile = System.IO.<span style="color:#2b91af;">Path</span>.Combine(lineStyleFilePath, <span style="color:#a31515;">"MM.LIN"</span>);
<span style="color:#2b91af;">LineStyle</span> dsLineStyle = <span style="color:blue;">null</span>;
dsLineStyleMgr.<b>LoadLineStyle</b>(<span style="color:#a31515;">"BATTING"</span>, lineStyleFile, <span style="color:blue;">out</span> dsLineStyle);
dsLineStyleMgr.<b>LoadLineStyle</b>(<span style="color:#a31515;">"ZIGZAG"</span>, lineStyleFile, <span style="color:blue;">out</span> dsLineStyle);
<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;">//Activate BATTING LineStyle and insert Line</span>
dsLineStyle = dsLineStyleMgr.<b>GetLineStyle</b>(<span style="color:#a31515;">"BATTING"</span>);
dsLineStyle.<b>Activate</b>();
dsSketchMgr.<b>InsertLine</b>(0, 0, 0, 100, 100, 0);
<span style="color:green;">//Activate ZIGZAG LineStyle and insert Line</span>
dsLineStyle = dsLineStyleMgr.<b>GetLineStyle</b>(<span style="color:#a31515;">"ZIGZAG"</span>);
dsLineStyle.<b>Activate</b>();
dsSketchMgr.<b>InsertLine</b>(100, 0, 0, 200, 100, 0);
}
}</pre>
</body>
</html>