Hi all,
Trying to work out how to place a predefined text string onto the drawing, without bring up any menus or options.
Have tried
CadInputQueue.SendKeyin "place text" CadInputQueue.SendKeyin sText
But the keyin window appears and i cant work out how to close it.
Also have tried
CadInputQueue.SendKeyin "place dialogtext icon" CadInputQueue.SendMessageToApplication "WORDPROC", sText
Which brings up the word processor but doesn't input the text.
Ideally i'd like to simple click a button on a form and the text appears on the drawing at the cursor ready for the user to select the location.
Cheers,
Rob
I recommend you to use the CreateTextElement1 method to create a TextElement and then call ActiveModelReference.AddElement to add this text element to your model.
HTH, Yongan
small sample
dim text as string ' text string
dim rotmatrix as matrix3d ' text rotation
dim p1 as point3d ' textt origin
RotMatrix = Matrix3dFromAxisAndRotationAngle(2, 0)
Set Text = CreateTextElement1(Nothing, "text to be written, P1, RotMatrix)
ActiveModelReference.AddElement Testo
Answer Verified By: Rob Golding
Unknown said: CadInputQueue.SendKeyin "place text" CadInputQueue.SendKeyin sText
In general, if you queue a user key-in using VBA then the result is the same as if you performed that task manually. In other words, MicroStation can't distinguish between you typing place dialogtext icon and VBA queueing place dialogtext icon.
If a key-in causes MicroStation to pop a dialog, then it will pop that dialog.
If you want to avoid the consequents of a user key-in, then use VBA to create objects directly, in the way that others have suggested. Search VBA help for examples. Searching for CreateTextElement1 reveals an example under topic Elements and Levels.
Regards, Jon Summers LA Solutions
Thanks for the replies. Has basically got what i wanted.
The only thing is that i would like the user to place the text where they would like, is there a way i can put the new text element to the cursor and have the user select the point? rather than define the point?
Unknown said:The only thing is that i would like the user to place the text where they would like, is there a way Ii can put the new text element to the cursor and have the user select the point?
Write a class that Implements IPrimitiveCommandEvents. Read about Interface Oriented Programming in VBA help. Start that class from your form and pass it the string to be created.
Sub PlaceTextInteractive (s As String) Dim oTextPlacer As New clsGolding oTextPlacer.Text = s CommandState.StartPrimitive oTextPlacer End Sub
Create a class module named clsGolding. Put the following in that class...
Implements IPrimitiveCommandEvents
Private m_strText As String
[Edit] ' wrong: Public Property Set Text (s As String)Public Property Let Text (s As String) m_strText = sEnd Property
' Add all the subroutines required by IPrimitiveCommandEvents
Sub IPrimitiveCommandEvents_Datapoint (point As Point3d, oView As View) Dim oText As TextElement Set oText = CreateTextElement1 (Nothing, m_strText, point, Matrix3dIdentity) ActiveModelReference.AddElement oTextEnd Sub
Thanks Jon,
I haven't been able to get that to work unfortunatley.
I have done as above...
-Created a Class Module called "clsGolding" which has the following in it... But when run the below error appears.
My form has a button that simply is this
PlaceTextInteractive ("testing")
Which controls this
Sub PlaceTextInteractive(s As String) Dim oTextPlacer As New clsGolding oTextPlacer.Text = s CommandState.StartPrimitive oTextPlacerEnd Sub
What have I done wrong?
See the highlighted portion of your code? Thats the error. Unfortunately the Screenshot is too small, could not read it.
But I can see it is not the part you copied into your mail.
I understand the highlighted part is the error but not too sure why its appearing.
I have attached the picture rather than embed it.
Thanks for the replies guys.
Your Property needs a Getter! Google your error text, you will find an answer.
When you write a class property with VB/VBA...
In your screenshot, the incomprehensible error message is trying to tell you to use Let rather tha Set in your Text property. Try this instead:
Public Property Let Text (s As String) m_strText = sEnd Property
Unknown said:What have I done wrong?
Nothing! That was my fault for writing the wrong keyword in my example below. I'm always forgetting to use Let for PODs.