Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
<html>
<head>
<title>Create Tracker Example (VB.NET)</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="VB.NET examples">
<meta name=MS-HKWD content="VB.NET examples,trackers">
<meta name=MS-HKWD content="VB.NET examples,temporary entities">
</head>
<body>
<h1> Create Tracker Example (VB.NET)</h1>
<p>This example shows how to create a tracker and add a temporary entity to the
tracker.</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 VB.NET Windows console project.</span>
<span style="color:green;">' 2. Copy and paste this example into the VB.NET 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. Creates a temporary Circle for the tracker.</span>
<span style="color:green;">' 2. Creates a tracker and adds the temporary Circle to the</span>
<span style="color:green;">' the tracker. </span>
<span style="color:green;">' 3. Examine the pointer in the drawing to verify. </span>
<span style="color:green;">' 4. Prompts you to click in the drawing to insert a Circle.</span>
<span style="color:green;">' 5. Inserts a Circle in the drawing at the point where you clicked.</span>
<span style="color:green;">'----------------------------------------------------------------</span>
<span style="color:blue;">Imports</span> DraftSight.Interop.dsAutomation
<span style="color:blue;">Imports</span> System.Runtime.InteropServices
<span style="color:blue;">Imports</span> System
<span style="color:blue;">Imports</span> System.Windows.Forms
<span style="color:blue;">Module</span> <span style="color:#2b91af;">Module_1</span>
<span style="color:blue;">Public</span> <span style="color:blue;">WithEvents</span> dsTracker <span style="color:blue;">As</span> <span style="color:#2b91af;">Tracker</span>
<span style="color:blue;">Public</span> dsApp <span style="color:blue;">As</span> DraftSight.Interop.dsAutomation.<span style="color:#2b91af;">Application</span>
<span style="color:blue;">Public</span> dsTempCircle <span style="color:blue;">As</span> <span style="color:#2b91af;">Circle</span>
<span style="color:blue;">Public</span> <span style="color:blue;">Sub</span> Main()
<span style="color:green;">'Connect to DraftSight application</span>
dsApp = <span style="color:blue;">DirectCast</span>(<span style="color:#2b91af;">Marshal</span>.GetActiveObject(<span style="color:#a31515;">"DraftSight.Application"</span>), DraftSight.Interop.dsAutomation.<span style="color:#2b91af;">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> dsApp <span style="color:blue;">Is</span> <span style="color:blue;">Nothing</span> <span style="color:blue;">Then</span>
<span style="color:blue;">Return</span>
<span style="color:blue;">End</span> <span style="color:blue;">If</span>
<span style="color:green;">'Get active document</span>
<span style="color:blue;">Dim</span> dsDoc <span style="color:blue;">As</span> <span style="color:#2b91af;">Document</span> = dsApp.<b>GetActiveDocument</b>()
<span style="color:blue;">If</span> dsDoc <span style="color:blue;">Is</span> <span style="color:blue;">Nothing</span> <span style="color:blue;">Then</span>
<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:blue;">End</span> <span style="color:blue;">If</span>
<span style="color:green;">'Get Sketch Manager</span>
<span style="color:blue;">Dim</span> dsSketchMgr <span style="color:blue;">As</span> <span style="color:#2b91af;">SketchManager</span> = dsDoc.<b>GetModel</b>().<b>GetSketchManager</b>()
<span style="color:green;">'Create temporary Circle</span>
dsApp.<b>TemporaryEntityMode</b> = <span style="color:blue;">True</span>
dsTempCircle = dsSketchMgr.<b>InsertCircle</b>(0, 0, 0, 10)
dsApp.<b>TemporaryEntityMode</b> = <span style="color:blue;">False</span>
<span style="color:green;">'Create tracker and add temporary Circle</span>
<span style="color:blue;">Dim</span> dsTracker <span style="color:blue;">As</span> <span style="color:#2b91af;">Tracker</span> = dsApp.<b>CreateTracker</b>()
dsTracker.<b>AddTemporaryEntity</b>(dsTempCircle)
<span style="color:green;">'Prompt for point where to insert Circle</span>
<span style="color:green;">'Before prompt, add tracker to command message</span>
<span style="color:blue;">Dim</span> dsCmdMsg <span style="color:blue;">As</span> <span style="color:#2b91af;">CommandMessage</span> = dsApp.<b>GetCommandMessage</b>()
dsCmdMsg.<b>AddTracker</b>(dsTracker)
<span style="color:blue;">Dim</span> X <span style="color:blue;">As</span> <span style="color:blue;">Double</span> = 0.0
<span style="color:blue;">Dim</span> Y <span style="color:blue;">As</span> <span style="color:blue;">Double</span> = 0.0
<span style="color:blue;">Dim</span> Z <span style="color:blue;">As</span> <span style="color:blue;">Double</span> = 0.0
<span style="color:blue;">AddHandler</span> dsTracker.<b>UpdateNotify</b>, <span style="color:blue;">AddressOf</span> dsTracker_UpdateNotify
<span style="color:blue;">Dim</span> res <span style="color:blue;">As</span> <span style="color:blue;">Boolean</span> = dsCmdMsg.<b>PromptForPoint</b>(<span style="color:#a31515;">"Click to insert Circle"</span>, X, Y, Z)
<span style="color:blue;">RemoveHandler</span> dsTracker.<b>UpdateNotify</b>, <span style="color:blue;">AddressOf</span> dsTracker_UpdateNotify
<span style="color:blue;">If</span> res = <span style="color:blue;">True</span> <span style="color:blue;">Then</span>
<span style="color:green;">'Set the center of the Circle where user clicked</span>
dsTempCircle.<b>SetCenter</b>(X, Y, Z)
<span style="color:green;">'Add temporary Circle to drawing</span>
dsSketchMgr.<b>AddTemporaryEntity</b>(dsTempCircle)
<span style="color:blue;">End</span> <span style="color:blue;">If</span>
<span style="color:green;">'Remove tracker from command message if no longer needed</span>
dsCmdMsg.<b>RemoveTracker</b>(dsTracker)
<span style="color:blue;">End</span> <span style="color:blue;">Sub</span>
<span style="color:blue;">Private</span> <span style="color:blue;">Sub</span> dsTracker<b>_UpdateNotify</b>(<span style="color:blue;">ByVal</span> CursorPosition <span style="color:blue;">As</span> <span style="color:#2b91af;">MathPoint</span>) <span style="color:blue;">Handles</span> dsTracker.UpdateNotify
<span style="color:blue;">If</span> CursorPosition <span style="color:blue;">Is</span> <span style="color:blue;">Nothing</span> <span style="color:blue;">Then</span>
<span style="color:blue;">Return</span>
<span style="color:blue;">End</span> <span style="color:blue;">If</span>
<span style="color:blue;">Dim</span> x <span style="color:blue;">As</span> <span style="color:blue;">Double</span> = 0.0, y <span style="color:blue;">As</span> <span style="color:blue;">Double</span> = 0.0, z <span style="color:blue;">As</span> <span style="color:blue;">Double</span> = 0.0
CursorPosition.<b>GetPosition</b>(x, y, z)
dsTempCircle.<b>SetCenter</b>(x, y, z)
<span style="color:blue;">End</span> <span style="color:blue;">Sub</span>
<span style="color:blue;">End</span> <span style="color:blue;">Module</span></pre>
</body>
</html>