MicroStation V8i SS4
Hey all, I have create some code to place a cell, record that placement point (oMessage.Point) and then start the "place note" tool and populate the word processor with the value of that point. My issue is that is only giving me the value after the decimal of that point. It is ignoring the data that I need. For instance, if the value is 66927.1878173258 (from the expression watch), it is only pasting 1878173258. I need the full value and only 2 decimal places. I am currently only calling a single variable but eventually it will be all 3.
How do I resolve this issue? Here is the code:
Sub PlaceCoordNoteDEV() Dim startPoint As Point3d Dim oView As View Dim pt1 As Point3d, pt2 As String Dim point As Point3d Dim lngTemp As Long Dim oMessage As CadInputMessage Dim pt1X As Double On Error GoTo cleanup
Do While True
' Set element template and place cell CadInputQueue.SendKeyin "template active general\annotation\text\Text wLeader T10" CadInputQueue.SendKeyin "ac=Location Marker"
'Show messages ShowPrompt "Place ID Point" ShowMessage "Select ID Point in screen" 'CadInputQueue.SendKeyin "set item toolsettings celltruescaletoggle=1"
' Commands below will use the placement point above be recorded and use Set oMessage = CadInputQueue.GetInput(msdCadInputTypeDataPoint, msdCadInputTypeReset) If oMessage.InputType = msdCadInputTypeDataPoint Then CadInputQueue.SendDataPoint oMessage.point pt1 = oMessage.point pt1X = oMessage.point.X
pt2 = CDbl(pt1X) 'Get View Set oView = oMessage.View With CadInputQueue
.SendDataPoint pt1, oView .SendKeyin "choose none" .SendKeyin "place note"
.SendMessageToApplication "WORDPROC", "1 PasteTextInEditor 23" + pt2 .SendDataPoint pt1, oView
'Show Messages ShowPrompt "Select next point for Note placement" ShowMessage "Select next point for Note placement"
Set oMessage = CadInputQueue.GetInput(msdCadInputTypeDataPoint, msdCadInputTypeReset) If oMessage.InputType = msdCadInputTypeDataPoint Then CadInputQueue.SendDataPoint oMessage.point
End If End With
ElseIf oMessage.InputType = msdCadInputTypeReset Then GoTo cleanupEnd If
Loop
cleanup:
CadInputQueue.SendKeyin "choose none"CadInputQueue.SendKeyin "reset"ShowPrompt ""ShowMessage "Macro Exited"
End Sub
Mark Winegar said:
pt1X = oMessage.point.X
pt2 = CDbl(pt1X)
pt1x is declared as Double, so you've made a copy of point.X.
pt1x
Double, so you've made a copy of point.X.
point.X
pt2 is declared as a String, so I think there's typo in the above. Try:
pt2
String
pt2 = CStr (pt1X)
In fact, you never use variable pt1X again, so it would be simpler to discard pt1X and write:
pt1X
pt2 = CStr (oMessage.point.X)
Mark Winegar said:I need the full value and only 2 decimal places
You can use VBA's Format function for better control. For example:
Format
pt2 = Format(oMessage.point.X, "#,##0.00")
Regards, Jon Summers LA Solutions
Answer Verified By: Mark Winegar
That worked! thanks!
I have 2 additional comment/questions.
The macro does not work in CONNECT. I assume the code to talk to the word processor is different so I just have not looked into that at this time.
The macro seems to work when the coords of the element are close to the global origin, but it having issues when the elements are much further from the global origin. How do I get the output to work consistently no matter where the element is in the model? I feel that the formatting is out of whack and that what I am trying to do is not possible. Let me know if you have any thoughts. Here is the code thus far:
Sub Main() Dim mdlapp As String mdlapp = "XYZTXT" If (IsMdlLoaded(mdlapp)) Then Debug.Print "'" & mdlapp & "' is loaded" ShowMessage "'" & mdlapp & "' is loaded" Else Debug.Print "'" & mdlapp & "' is not loaded" ShowMessage "'" & mdlapp & "' is not loaded" End IfEnd Sub' ---------------------------------------------------------------------Function IsMdlLoaded(appName As String) As Boolean IsMdlLoaded = False On Error GoTo err_IsMdlLoaded Const SUCCESS As Long = 0 If (SUCCESS = mdlSystem_getTaskStatistics(0, appName)) Then IsMdlLoaded = True End If Exit Function
err_IsMdlLoaded: MsgBox "Error no. " & CStr(Err.Number) & ": " & Err.Description, vbCritical Or vbOKOnly, "IsMdlLoaded Error"End Function
'---------------------------------------------------------'-- PlaceXYNote'-- Placing X,Y coordinates in a note w/leader'---------------------------------------------------------Sub PlaceXYNote() Dim startPoint As Point3d Dim oView As View Dim point As Point3d Dim lngTemp As Long Dim oMessage As CadInputMessage Dim pt1 As Point3d Dim pt2 As String Dim pt3 As String Dim pt4 As String On Error GoTo cleanupDo While True
'Show messages ShowPrompt "Select Placement Point" ShowMessage "Select Placement Point" CadInputQueue.SendKeyin "namedgroup delete Temp1" CadInputQueue.SendKeyin "place node" ' Commands below will use the placement point above be recorded and use Set oMessage = CadInputQueue.GetInput(msdCadInputTypeDataPoint, msdCadInputTypeReset) If oMessage.InputType = msdCadInputTypeDataPoint Then CadInputQueue.SendDataPoint oMessage.point pt1 = oMessage.point pt2 = Format(oMessage.point.Y, "###0.00") 'Northing pt3 = Format(oMessage.point.X, "###0.00") 'Easting 'Get View Set oView = oMessage.View 'Get Startpoint CadInputQueue.SendKeyin "choose last" CadInputQueue.SendKeyin "namedgroup create Temp1" With CadInputQueue .SendKeyin "place note"
.SendMessageToApplication "WORDPROC", "1 PasteTextInEditor 14" + "X" + "X=" + pt3 + Chr$(13) + "Y=" + pt2 .SendDataPoint pt1, oView 'Show Messages ShowPrompt "Select next point for Note placement" ShowMessage "Select next point for Note placement" Set oMessage = CadInputQueue.GetInput(msdCadInputTypeDataPoint, msdCadInputTypeReset) If oMessage.InputType = msdCadInputTypeDataPoint Then CadInputQueue.SendDataPoint oMessage.point CadInputQueue.SendKeyin "choose group set temp1" CadInputQueue.SendKeyin "delete" CadInputQueue.SendKeyin "choose none" CadInputQueue.SendKeyin "namedgroup delete Temp1" End If End With
cleanup: CadInputQueue.SendKeyin "choose none" CadInputQueue.SendKeyin "reset" ShowPrompt "" ShowMessage "PlaceXYNote Exited"
Mark Winegar said:The macro does not work in CONNECT
Please start a new thread. While VBA for CONNECT is mostly the same as V8, you are calling some MDL functions that may require some additional tweaking where you declare them.
Mark Winegar said:pt2 = Format(oMessage.point.Y, "###0.00") 'Northing pt3 = Format(oMessage.point.X, "###0.00") 'Easting
Prefer named variables to comments. Comments wear out over time. This expresses better your intents...
Dim easting As String easting = Format(oMessage.point.X, "###0.00") Dim northing As String northing = Format(oMessage.point.Y, "###0.00")
Mark Winegar said:The macro seems to work when the coords of the element are close to the global origin, but it having issues when the elements are much further from the global origin
Please provide an example!
Coord Note Testing.dgnIt looks like the issue may be the number of characters allowed from the code "14":
With CadInputQueue .SendKeyin "place note"
.SendMessageToApplication "WORDPROC", "1 PasteTextInEditor 14" + "X" + "X=" + easting + Chr$(13) + "Y=" + northing
Is this a correct assumption? What am I not understanding on how the processor is being populated?