Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
<html>
<head>
<title>Insert Splines 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,Splines">
<meta name=MS-HKWD content="VB.NET examples,points">
<meta name=MS-HKWD content="VB.NET examples,prompts">
<meta name=MS-HKWD content="VB.NET examples,commands">
<meta name=MS-HKWD content="VB.NET examples,events">
<meta name=MS-HKWD content="VB.NET examples,notifications">
<meta name=MS-HKWD content="VB.NET examples,entities">
<meta name=MS-HKWD content="VB.NET examples,Layers">
<style>
<!--
.style7
{
text-align: left;
font-size: 11px;
}
-->
</style>
</head>
<body>
<h1>Insert Splines Example (VB.NET)</h1>
<p>This example shows how to:</p>
<ul>
<li><font face="Verdana" style="font-size: 8pt">construct several Splines, which are displayed as
the Dassault Systèmes logo in a DraftSight drawing. </font></li>
<li><font face="Verdana" style="font-size: 8pt">fire events before
and after commands are executed.</font></li>
<li><font face="Verdana" style="font-size: 8pt">select a group of entities
and modify a member in that group of entities.</font></li>
<li><font face="Verdana" style="font-size: 8pt">execute a command using
IApplication::RunCommand.</font></li>
</ul>
<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 the DraftSight type library,</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.</span>
<span style="color:green;">' 6. Press F5.</span>
<span style="color:green;">'</span>
<span style="color:green;">' Postconditions:
' 1. CommandPreNotify event is fired. Click <b>OK</b> to close the</span>
<span style="color:green;">' message box.</span>
<span style="color:green;">' 2. Click anywhere in the drawing when you are prompted</span>
<span style="color:green;">' in the command window to <b>Click to insert a point</b></span>
<span style="color:green;">' <b>for the lower-left corner for the 3DS logo</b>.</span>
<span style="color:green;">' 3. CommandPostNotify event is fired. Click <b>OK</b> to close</span>
<span style="color:green;">' the message box.
' 4. The Dassault Systemes logo is constructed in the drawing.</span>
<span style="color:green;">' a. Examine the drawing to verify.</span>
<span style="color:green;">' b. </span><span style="color:green;">Press F5 </span><span style="color:green;">in the IDE.</span>
<span style="color:green;">' The Dassault Systemes logo's letter D is changed </span>
<span style="color:green;">' from blue to yellow.</span>
<span style="color:green;">' c. </span><span style="color:green;">Press F5 to </span><span style="color:green;">in the IDE.</span>
<span style="color:green;">' The Dassault Systemes logo's letter D is changed</span>
<span style="color:green;">' back to blue.</span>
<span style="color:green;">' d. </span><span style="color:green;">Press F5 </span><span style="color:green;">in the IDE.</span>
<span style="color:green;">' 5. CommandPreNotify event is fired. Click OK to close the</span>
<span style="color:green;">' the message box.</span>
<span style="color:green;">' 6. CommandPostNotify event is fired. Click OK to close the</span>
<span style="color:green;">' message box.</span>
<span style="color:green;">' 7. The Dassault Systemes logo is deleted.
'----------------------------------------------------------------</span>
<span style="color:blue;">Imports</span> DraftSight.Interop.dsAutomation
<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;">Module1</span></pre>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white"> <span style="color:blue;">Dim</span> <span style="color:blue;">WithEvents</span> dsApp <span style="color:blue;">As</span> DraftSight.Interop.dsAutomation.<span style="color:#2b91af;">Application
</span> <span style="color:blue;">Dim</span> commandPreNotifyCommand <span style="color:blue;">As</span> <span style="color:blue;">String</span> = <span style="color:#a31515;">" "</span>
<span style="color:blue;">Dim</span> commandPostNotifyCommand <span style="color:blue;">As</span> <span style="color:blue;">String</span> = <span style="color:#a31515;">" "</span>
<span style="color:blue;">Dim</span> dsDoc <span style="color:blue;">As</span> <span style="color:#2b91af;">Document</span>
<span style="color:blue;">Sub</span> Main()</pre>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white"> <span style="color:blue;">Dim</span> dsSketchMgr <span style="color:blue;">As</span> <span style="color:#2b91af;">SketchManager</span>
<span style="color:blue;">Dim</span> dsSelectionManager <span style="color:blue;">As</span> <span style="color:#2b91af;">SelectionManager</span>
<span style="color:blue;">Dim</span> dsSelectionFilter <span style="color:blue;">As</span> <span style="color:#2b91af;">SelectionFilter</span>
<span style="color:blue;">Dim</span> dsEntityHelper <span style="color:blue;">As</span> <span style="color:#2b91af;">EntityHelper</span>
<span style="color:green;">'Connect to DraftSight</span>
dsApp = GetObject(, <span style="color:#a31515;">"DraftSight.Application"</span>)
<span style="color:green;">' Abort any command currently running in DraftSight to</span>
<span style="color:green;">' avoid nested commands</span>
dsApp.<b>AbortRunningCommand</b>()</pre>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white"> <span style="color:green;">'Get command message object</span>
<span style="color:blue;">Dim</span> dsCommandMessage <span style="color:blue;">As</span> <span style="color:#2b91af;">CommandMessage</span>
dsCommandMessage = dsApp.<b>GetCommandMessage</b>
<span style="color:green;">'Get active document</span>
dsDoc = 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>
MsgBox(<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 model space</span>
<span style="color:blue;">Dim</span> dsModel <span style="color:blue;">As</span> <span style="color:#2b91af;">Model</span>
dsModel = dsDoc.<b>GetModel</b>()
<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>
dsSketchMgr = dsModel.<b>GetSketchManager</b>()
<span style="color:blue;">Dim</span> x <span style="color:blue;">As</span> <span style="color:blue;">Double</span>
<span style="color:blue;">Dim</span> y <span style="color:blue;">As</span> <span style="color:blue;">Double</span>
<span style="color:blue;">Dim</span> z <span style="color:blue;">As</span> <span style="color:blue;">Double</span>
<span style="color:green;">' Prompt to insert the a point for lower-left corner of the 3DS logo</span>
<span style="color:blue;">Dim</span> dsMathUtility <span style="color:blue;">As</span> <span style="color:#2b91af;">MathUtility</span>
<span style="color:blue;">Dim</span> dsMathPlane <span style="color:blue;">As</span> <span style="color:#2b91af;">MathPlane</span>
dsMathUtility = dsApp.<b>GetMathUtility</b>()
dsMathPlane = dsMathUtility.<b>CreateXYPlane</b>()
<span style="color:blue;">Dim</span> status <span style="color:blue;">As</span> <span style="color:blue;">Boolean</span>
status = dsCommandMessage.<b>PromptForPoint2</b>(<span style="color:#a31515;">"Click to insert a point for the lower-left corner for the 3DS logo"</span>, <span style="color:blue;">True</span>, 0, 0, 0, x, y, z, dsMathPlane)
<span style="color:blue;">Dim</span> spArray1(26) <span style="color:blue;">As</span> <span style="color:blue;">Double</span>
<span style="color:blue;">Dim</span> spArray2(23) <span style="color:blue;">As</span> <span style="color:blue;">Double</span>
<span style="color:blue;">Dim</span> spArray3(17) <span style="color:blue;">As</span> <span style="color:blue;">Double</span>
<span style="color:green;">' Construct the D</span>
spArray1(0) = x + 0.4513
spArray1(1) = y + 0.3825
spArray1(2) = z + 0.0#
spArray1(3) = x + 0.324
spArray1(4) = y + 0.1912
spArray1(5) = z + 0.0#
spArray1(6) = x + 0.1261
spArray1(7) = y + 0.0932
spArray1(8) = z + 0.0#
spArray1(9) = x + 0.2571
spArray1(10) = y + 0.3839
spArray1(11) = z + 0.0#
spArray1(12) = x + 0.0023
spArray1(13) = y + 0.0086
spArray1(14) = z + 0.0#
spArray1(15) = x + 0.2132
spArray1(16) = y + 0.0711
spArray1(17) = z + 0.0#
spArray1(18) = x + 0.5275
spArray1(19) = y + 0.4664
spArray1(20) = z + 0.0#
spArray1(21) = x + 0.428
spArray1(22) = y + 0.5052
spArray1(23) = z + 0.0#
spArray1(24) = x + 0.1237
spArray1(25) = y + 0.4568
spArray1(26) = z + 0.0#
<span style="color:blue;">Dim</span> spline1 <span style="color:blue;">As</span> <span style="color:#2b91af;">Spline</span>
spline1 = dsSketchMgr.<b>InsertSpline</b>(spArray1, <span style="color:blue;">True</span>, 0, 0, 0, 0, 0, 0)
<span style="color:green;">' Construct the S</span>
spArray2(0) = x + 0.4659
spArray2(1) = y + 0.1472
spArray2(2) = 0.0#
spArray2(3) = x + 0.8218
spArray2(4) = y + 0.2052
spArray2(5) = z + 0.0#
spArray2(6) = x + 0.6099
spArray2(7) = y + 0.5472
spArray2(8) = z + 0.0#
spArray2(9) = x + 0.7898
spArray2(10) = y + 0.6372
spArray2(11) = z + 0.0#
spArray2(12) = x + 0.9877
spArray2(13) = y + 0.5952
spArray2(14) = z + 0.0#
spArray2(15) = x + 0.7158
spArray2(16) = y + 0.5472
spArray2(17) = z + 0.0#
spArray2(18) = x + 0.9318
spArray2(19) = y + 0.2232
spArray2(20) = z + 0.0#
spArray2(21) = x + 0.7818
spArray2(22) = y + 0.1112
spArray2(23) = z + 0.0#
<span style="color:blue;">Dim</span> spline2 <span style="color:blue;">As</span> <span style="color:#2b91af;">Spline</span>
spline2 = dsSketchMgr.<b>InsertSpline</b>(spArray2, <span style="color:blue;">True</span>, 0, 0, 0, 0, 0, 0)
<span style="color:green;">' Construct the 3</span>
spArray3(0) = x + 0.6319
spArray3(1) = y + 0.8672
spArray3(2) = z + 0.0#
spArray3(3) = x + 0.33
spArray3(4) = y + 0.9233
spArray3(5) = z + 0.0#
spArray3(6) = x + 0.5
spArray3(7) = y + 0.9642
spArray3(8) = z + 0.0#
spArray3(9) = x + 0.7318
spArray3(10) = y + 0.8952
spArray3(11) = z + 0.0#
spArray3(12) = x + 0.6279
spArray3(13) = y + 0.6892
spArray3(14) = z + 0.0#
spArray3(15) = x + 0.369
spArray3(16) = y + 0.5563
spArray3(17) = z + 0.0#
<span style="color:blue;">Dim</span> spline3 <span style="color:blue;">As</span> <span style="color:#2b91af;">Spline</span>
spline3 = dsSketchMgr.<b>InsertSpline</b>(spArray3, <span style="color:blue;">True</span>, 0, 0, 0, 0, 0, 0)
<span style="color:green;">' Set the colors for the logo</span>
<span style="color:blue;">Dim</span> color1 <span style="color:blue;">As</span> <span style="color:#2b91af;">Color</span>
<span style="color:blue;">Dim</span> color2 <span style="color:blue;">As</span> <span style="color:#2b91af;">Color</span>
<span style="color:blue;">Dim</span> color3 <span style="color:blue;">As</span> <span style="color:#2b91af;">Color</span>
color1 = spline1.<b>Color</b>
color2 = spline2.<b>Color</b>
color3 = spline3.<b>Color</b>
color1.<b>SetNamedColor</b>(<span style="color:#2b91af;">dsNamedColor_e</span>.dsNamedColor_Blue)
color2.<b>SetNamedColor</b>(<span style="color:#2b91af;">dsNamedColor_e</span>.dsNamedColor_Yellow)
color3.<b>SetNamedColor</b>(<span style="color:#2b91af;">dsNamedColor_e</span>.dsNamedColor_Red)
spline1.Color = <b>color1</b>
spline2.Color = <b>color2</b>
spline3.Color = <b>color3</b></pre>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white"> <span style="color:green;">' Examine the drawing to verify
' that the logo was created</span>
<span style="color:green;">' and that the letter D is blue, the </span>
<span style="color:green;">' letter S is yellow, and the non-letter </span>
<span style="color:green;">' is red</span>
<font color="#0000FF"> </font><span style="color: #0000FF"> Stop
</span> <span style="color:green;">' </span><span style="color:green;">Press F5 to </span><span style="color:green;">change the colors of the logo
</span>
<span style="color:green;">'Get Selection Manager</span>
dsSelectionManager = dsDoc.<b>GetSelectionManager</b>
<span style="color:green;">'Get selection filter</span>
dsSelectionFilter = dsSelectionManager.<b>GetSelectionFilter</b>
<span style="color:green;">'Clear selection filter</span>
dsSelectionFilter.<b>Clear</b>()
<span style="color:green;">'Add Spline entities to the selection filter</span>
dsSelectionFilter.<b>AddEntityType</b>(<span style="color:#2b91af;">dsObjectType_e</span>.dsSplineType)
<span style="color:green;">'Activate selection filter</span>
dsSelectionFilter.<b>Active</b> = <span style="color:blue;">True</span>
<span style="color:green;">'Get all layer names</span>
<span style="color:blue;">Dim</span> layerNames <span style="color:blue;">As</span> <span style="color:blue;">String</span>() = GetLayers(dsDoc)
<span style="color:blue;">Dim</span> entityTypes() <span style="color:blue;">As</span> <span style="color:blue;">Integer</span> = <span style="color:blue;">Nothing</span>
<span style="color:blue;">Dim</span> entityObjects() <span style="color:blue;">As</span> <span style="color:blue;">Object</span> = <span style="color:blue;">Nothing</span>
<span style="color:green;">'Get Spline entities</span>
dsSketchMgr.<b>GetEntities</b>(dsSelectionFilter, layerNames, entityTypes, entityObjects)
<span style="color:green;">' Get EntityHelper</span>
dsEntityHelper = dsApp.<b>GetEntityHelper</b>
<span style="color:green;">' Change the letter D in the logo from blue to yellow</span>
dsEntityHelper.<b>SetColor</b>(entityObjects(0), color2)
<span style="color:blue;">Stop</span>
<span style="color:green;">' Examine the drawing to verify that</span>
<span style="color:green;">' the color of D has changed from blue to yellow</span>
<span style="color:green;">' </span><span style="color:green;">Press F5 to continue</span><span style="color:green;">
</span>
dsEntityHelper.<b>SetColor</b>(entityObjects(0), color1)
<span style="color:blue;">Stop</span>
<span style="color:green;">' Examine the drawing to verify that the color
' of D has changed back to blue</span>
<span style="color:green;">' Press F5 to delete the logo
</span>
<span style="color:blue;">Dim</span> state <span style="color:blue;">As</span> <span style="color: #0000FF">Integer</span>
state = dsApp.<b>RunCommand</b>(<span style="color:#a31515;">"DELETE ALL"</span> & Chr(10) & Chr(10), <span style="color:blue;">False</span>)
<span style="color:blue;">End</span> <span style="color:blue;">Sub</span></pre>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white"> <span style="color:blue;">Private</span> <span style="color:blue;">Sub</span> dsApp_CommandPreNotify(<span style="color:blue;">ByVal</span> commandPreNotifycommand <span style="color:blue;">As</span> <span style="color:blue;">String</span>, <span style="color:blue;">ByVal</span> doc <span style="color:blue;">As</span> <span style="color:#2b91af;">Document</span>) <span style="color:blue;">Handles</span> dsApp.CommandPreNotify
MsgBox(<span style="color:#a31515;">"CommandPreNotify event was fired before "</span> & commandPreNotifycommand & <span style="color:#a31515;">" was executed."</span>)
<span style="color:blue;">End</span> <span style="color:blue;">Sub
</span>
<span style="color:blue;">Private</span> <span style="color:blue;">Sub</span> dsApp_CommandPostNotify(<span style="color:blue;">ByVal</span> commandPostNotifycommand <span style="color:blue;">As</span> <span style="color:blue;">String</span>, <span style="color:blue;">ByVal</span> doc <span style="color:blue;">As</span> <span style="color:#2b91af;">Document</span>) <span style="color:blue;">Handles</span> dsApp.CommandPostNotify
MsgBox(<span style="color:#a31515;">"CommandPostNotify event was fired after "</span> & commandPostNotifycommand & <span style="color:#a31515;">" was executed."</span>)
<span style="color:blue;">End</span> <span style="color:blue;">Sub</span>
</pre>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white"> <span style="color:blue;">Function</span> GetLayers(<span style="color:blue;">ByVal</span> dsDoc <span style="color:blue;">As</span> <span style="color:#2b91af;">Document</span>) <span style="color:blue;">As</span> <span style="color:blue;">String</span>()
<span style="color:green;">'Get Layer Manager and Layer names</span>
<span style="color:blue;">Dim</span> dsLayerManager <span style="color:blue;">As</span> <span style="color:#2b91af;">LayerManager</span> = dsDoc.<b>GetLayerManager</b>()
<span style="color:blue;">Dim</span> dsLayers <span style="color:blue;">As</span> <span style="color:blue;">Object</span>() = <span style="color:blue;">DirectCast</span>(dsLayerManager.<b>GetLayers</b>(), <span style="color:blue;">Object</span>())
<span style="color:blue;">Dim</span> layerNames <span style="color:blue;">As</span> <span style="color:blue;">String</span>() = <span style="color:blue;">New</span> <span style="color:blue;">String</span>(dsLayers.Length - 1) {}
<span style="color:blue;">For</span> index <span style="color:blue;">As</span> <span style="color:blue;">Integer</span> = 0 <span style="color:blue;">To</span> dsLayers.Length - 1
<span style="color:blue;">Dim</span> dsLayer <span style="color:blue;">As</span> <span style="color:#2b91af;">Layer</span> = <span style="color:blue;">TryCast</span>(dsLayers(index), <span style="color:#2b91af;">Layer</span>)
layerNames(index) = dsLayer.<b>Name</b>
<span style="color:blue;">Next</span>
<span style="color:blue;">Return</span> layerNames
<span style="color:blue;">End</span> <span style="color:blue;">Function</span></pre>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white">
<span style="color:blue;">End</span> <span style="color:blue;">Module</span></pre>
</body>
</html>