Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
<html>
<head>
<title>Insert SimpleNote 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,SimpleNotes">
<meta name=MS-HKWD content="VB.NET examples,selection filter">
<meta name=MS-HKWD content="VB.NET 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="VB.NET examples,Layers">
<meta name=MS-HKWD content="VB.NET examples,Layer Manager">
<meta name=MS-HKWD content="Layer">
<meta name=MS-HKWD content="Layer Manager">
<meta name=MS-HKWD content="VB.NET examples,get entities">
</head>
<body>
<h1>Insert SimpleNote Example (VB.NET)</h1>
<p>This example shows how to insert and change a SimpleNote in a drawing document.</p>
<pre>'--------------------------------------------------------------
' Preconditions:
' 1. Create a VB.NET Windows console project.
' 2. Copy and paste this example into the VB.NET IDE.
' 3. Add a reference to:
' <i>install_dir</i>\<b>APISDK\tlb\DraftSight.Interop.dsAutomation.dll</b>
' 4. Start DraftSight and open a document.
' 5. 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>Imports DraftSight.Interop.dsAutomation
Module Module1</pre>
<pre> Sub Main()</pre>
<pre> Dim dsApp As Application
Dim dsDoc As Document
Dim dsModel As Model
Dim dsSketchManager As SketchManager
Dim dsSimpleNote As SimpleNote
Dim startX, startY, startZ As Double
Dim noteValue As String
Dim angle, height As Double</pre>
<pre> 'Connect to DraftSight
dsApp = GetObject(, "DraftSight.Application")
dsApp.<b>AbortRunningCommand</b>() ' abort any command currently running in DraftSight to avoid nested commands</pre>
<pre> 'Get active document
dsDoc = dsApp.<b>GetActiveDocument</b>()
If Not dsDoc Is Nothing Then</pre>
<pre> '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 = "Sample text"
angle = 3.14159265358979 / 4 '45 degrees in radians
height = 1.0#</pre>
<pre> 'Add a SimpleNote
dsSimpleNote = dsSketchManager.<b>InsertSimpleNote</b>(startX, startY, startZ, height, angle, noteValue)</pre>
<pre> If Not dsSimpleNote Is Nothing Then
MsgBox("A SimpleNote was added to drawing.")
End If
</pre>
<pre> Else</pre>
<pre> MsgBox("There are no open documents in DraftSight.")</pre>
<pre> End If<font FACE="Consolas" SIZE="2">
</font><font SIZE="2" face="Courier New">'Change SimpleNote text
</font> ChangeSimpleNotesText(dsDoc, dsSketchManager)</pre>
<pre> End Sub</pre>
<pre> Sub ChangeSimpleNotesText(ByVal dsDoc As Document, ByVal dsSketchManager As SketchManager)
'Get Selection Manager
Dim dsSelectionMgr As SelectionManager = dsDoc.<b>GetSelectionManager</b>()</pre>
<pre> 'Get selection filter
Dim dsSelectioFilter As SelectionFilter = 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
Dim layerNames As String() = GetLayerNames(dsDoc)</pre>
<pre> 'Get SimpleNote entities
Dim entityObjects As Object
Dim entityTypes As Object
dsSketchManager.<b>GetEntities</b>(dsSelectioFilter, layerNames, entityTypes, entityObjects)
If entityObjects IsNot Nothing AndAlso entityTypes IsNot Nothing Then
Dim dsEntityArray As Object() = DirectCast(entityObjects, Object())</pre>
<pre> Const newNoteValue As String = "New sample text"</pre>
<pre> 'Iterate through all SimpleNote entities
For index As Integer = 0 To dsEntityArray.Length - 1
'Cast the selected object to SimpleNote
Dim dsSimpleNote As SimpleNote = TryCast(dsEntityArray(index), SimpleNote)</pre>
<pre> 'Get SimpleNote text
Dim noteValue As String = dsSimpleNote.<b>Contents</b></pre>
<pre> 'Set new text for SimpleNote
dsSimpleNote.<b>Contents</b> = newNoteValue
Next
End If
End Sub</pre>
<pre> Function GetLayerNames(ByVal dsDoc As Document) As String()
Dim layerNames As String() = Nothing</pre>
<pre> Dim dsLayerManager As LayerManager = dsDoc.<b>GetLayerManager</b>()</pre>
<pre> Dim dsLayers As Object() = DirectCast(dsLayerManager.<b>GetLayers</b>(), Object())
If dsLayers IsNot Nothing Then
layerNames = New String(dsLayers.Length - 1) {}</pre>
<pre> For index As Integer = 0 To dsLayers.Length - 1
Dim dsLayer As Layer = TryCast(dsLayers(index), Layer)
layerNames(index) = dsLayer.<b>Name</b>
Next
End If</pre>
<pre> Return layerNames
End Function</pre>
<pre>End Module</pre>
<pre>
</pre>
<pre>End Module</pre>
</body>
</html>