Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
<html>
<head>
<title>Insert SimpleNote Example (VBA)</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="VBA examples">
<meta name=MS-HKWD content="VBA examples,SimpleNotes">
<meta name=MS-HKWD content="SimpleNote">
<meta name=MS-HKWD content="VBA examples,selection filter">
<meta name=MS-HKWD content="VBA examples,Selection Manager">
<meta name=MS-HKWD content="Selection Manager">
<meta name=MS-HKWD content="Selection filter">
<meta name=MS-HKWD content="VBA examples, Layers">
<meta name=MS-HKWD content="VBA examples, Layer Manager">
<meta name=MS-HKWD content="Layer">
<meta name=MS-HKWD content="Layer Manager">
<meta name=MS-HKWD content="VBA examples, get entities">
</head>
<body>
<h1>Insert SimpleNote Example (VBA)</h1>
<p>This example shows how to insert and change a SimpleNote in a drawing document.</p>
<pre>'--------------------------------------------------------------
' Preconditions:
' 1. Create a VBA macro in a software product in which VBA is
' embedded.
' 2. Copy and paste this example into the Visual Basic IDE.
' 3. Add a reference to the DraftSight type library,
' <i>install_dir</i>\<b>bin\dsAutomation.dll</b>.
' 4. Start DraftSight and open a document.
' 5. Run the macro.
'
' 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>Option Explicit</pre>
<pre>Sub main()
Dim dsApp As DraftSight.Application
Dim dsDoc As DraftSight.Document
Dim dsModel As DraftSight.Model
Dim dsSketchManager As DraftSight.SketchManager
Dim dsSimpleNote As DraftSight.SimpleNote
Dim startX, startY, startZ As Double
Dim noteValue As String
Dim angle, height As Double
</pre>
<pre> 'Connect to DraftSight
Set dsApp = GetObject(, "DraftSight.Application")
'Abort any command currently running in DraftSight
'to avoid nested commands
dsApp.<b>AbortRunningCommand</b></pre>
<pre> 'Get active document
Set dsDoc = dsApp.<b>GetActiveDocument</b>()
If Not dsDoc Is Nothing Then
</pre>
<pre> 'Get model space
Set dsModel = dsDoc.<b>GetModel</b>()
</pre>
<pre> 'Get Sketch Manager
Set dsSketchManager = dsModel.<b>GetSketchManager</b>()
</pre>
<pre> 'SimpleNote parameters (angle value should be passed in radians)
startX = 0#
startY = 0#
startZ = 0#
noteValue = "First sample text"
angle = 3.14159265358979 / 4 '45 degrees in radians
height = 1#
</pre>
<pre> 'Add a SimpleNote
Set 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
</pre>
<pre> 'Change SimpleNote text
ChangeSimpleNotesText dsDoc, dsSketchManager</pre>
<pre>End Sub</pre>
<pre> Sub ChangeSimpleNotesText(ByVal dsDoc As DraftSight.Document, ByVal dsSketchManager As DraftSight.SketchManager)</pre>
<pre> 'Get Selection Manager
Dim dsSelectionMgr As DraftSight.SelectionManager
Set dsSelectionMgr = dsDoc.<b>GetSelectionManager</b>()</pre>
<pre> 'Get selection filter
Dim dsSelectionFilter As DraftSight.SelectionFilter
Set dsSelectionFilter = dsSelectionMgr.<b>GetSelectionFilter</b>()
</pre>
<pre> 'Clear selection filter
dsSelectionFilter.<b>Clear</b></pre>
<pre> 'Add filter to get only SimpleNotes
dsSelectionFilter.<b>AddEntityType</b> (dsObjectType_e.dsSimpleNoteType)</pre>
<pre> 'Activate selection filter
dsSelectionFilter.<b>Active</b> = True
</pre>
<pre> 'Get all Layer names
Dim layerNames As Variant
layerNames = GetLayers(dsDoc)
</pre>
<pre> Dim entityTypes As Variant
Dim entityObjects As Variant
Dim entityItem As Variant</pre>
<pre>
'Get SimpleNote entities
dsSketchManager.<b>GetEntities</b> dsSelectionFilter, layerNames, entityTypes, entityObjects
</pre>
<pre> Const newNoteValue As String = "New sample text"</pre>
<pre> If Not IsArray(entityObjects) Then
Debug.Print (" Document does not have any SimpleNotes.")
Debug.Print (" ")
Else
Debug.Print (" Document has SimpleNotes.")
'Iterate through SimpleNotes
For Each entityItem In entityObjects
'Cast to SimpleNote
Dim dsSimpleNote As DraftSight.SimpleNote
Set dsSimpleNote = entityItem
'Get SimpleNote
Dim simpleNoteText As String
simpleNoteText = dsSimpleNote.<b>Contents</b>
'Set new SimpleNote text
dsSimpleNote.<b>Contents</b> = newNoteValue
</pre>
<pre> Next
Debug.Print (" ")
End If
</pre>
<pre>
End Sub</pre>
<pre> Public Function GetLayers(ByVal dsDoc As Document) As String()
'Get Layer Manager
Dim dsLayerManager As DraftSight.LayerManager
Set dsLayerManager = dsDoc.<b>GetLayerManager</b>
Dim dsLayers() As Object</pre>
<pre> 'Get Layers
dsLayers = dsLayerManager.<b>GetLayers</b>()
Dim dslayerNames() As String
Dim nbrLayers As Long
nbrLayers = UBound(dsLayers)
ReDim dslayerNames(nbrLayers) </pre>
<pre> Dim index As Long
For index = 0 To nbrLayers
Dim dsLayer As DraftSight.Layer
Set dsLayer = dsLayers(index)
dslayerNames(index) = dsLayer.<b>Name</b>
Next
</pre>
<pre> GetLayers = dslayerNames
</pre>
<pre> End Function</pre>
</body>
</html>