All,
I am new to programming (meaning not good at it.) I am trying to write a simple vba script that calls a microstation utility (text to node). It works fine if I comment out the bolded line of code, which coincidentally is the line that completes the command. I am trying to get it to place the text node back at the same xyz that the original text was placed at. If I comment it out I watch the status line at the bottom of microstation run through all the elements (but of course nothing is printed). If I put that line back in it crashes microstation. If I "step thru" the code as long as my cursor is in view 1 it wont crash, but will place the text nodes wherever my cursor is. If my cursor leaves the view it will crash it. Thoughts?
Thanks in advance
Troy
Option Explicit
Sub Test()
Dim ee As ElementEnumerator
Dim es As ElementScanCriteria
Dim elArray() As Element
Dim iStart As Integer
Dim iEnd As Integer
Dim i As Integer
Dim startPoint As Point3d
Dim point As Point3d
Set es = New ElementScanCriteria
es.ExcludeAllTypes
es.IncludeType msdElementTypeText
Set ee = ActiveModelReference.Scan(es)
elArray = ee.BuildArrayFromContents
iStart = LBound(elArray)
iEnd = UBound(elArray)
For i = iStart To iEnd
' Send a keyin that can be a command string
CadInputQueue.SendKeyin "createnode"
' Coordinates are in master units
startPoint.X = elArray(i).AsTextElement.Origin.X
startPoint.Y = elArray(i).AsTextElement.Origin.Y
startPoint.Z = elArray(i).AsTextElement.Origin.Z
point.X = startPoint.X
point.Y = startPoint.Y
point.Z = startPoint.Z
CadInputQueue.SendDataPoint point, 1
' Accept with origin
point.X = 0
point.Y = 0
point.Z = 0
CadInputQueue.SendDataPoint point, 1
' place at original pt
point.X = startPoint.X
point.Y = startPoint.Y
point.Z = startPoint.Z
CadInputQueue.SendDataPoint point, 1 'this is the line that crashes me
CadInputQueue.SendReset
Next
CommandState.StartDefaultCommand
End Sub