inserting text to particular coordinates

inserting text to particular coordinates

Anonymous
Not applicable
557 Views
4 Replies
Message 1 of 5

inserting text to particular coordinates

Anonymous
Not applicable
Hi All,

I need to insert text taken as input in a dialog box into a particular coordinate position on the drawing.This is basically updating a revision in a drafting process.
Any ideas are welcome( code sample too).


Thanks
Avantika
0 Likes
558 Views
4 Replies
Replies (4)
Message 2 of 5

arcticad
Advisor
Advisor
Do you just need something as simple as this?

Function test()
Dim item As Variant
Dim pt(0 To 2) As Double
pt(0) = 0#: pt(1) = 0#: pt(2) = 0#
For Each item In ModelSpace
Call UpdateInfo(item.Handle, pt, "HELLO")
Next
End Function

Function UpdateInfo(Handle As String, pt As Variant, TextString As String)
Dim entity As AcadEntity
Set entity = ThisDrawing.HandleToObject(Handle)
If TypeOf entity Is AcadText Then
entity.InsertionPoint = pt
entity.TextString = TextString
End If
End Function
---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 3 of 5

Anonymous
Not applicable
Hi ,

Sorry for asking you such a basic question but I am new to VBA.
I wanted to know what you are using the Handle for.
I need to also insert date in one of the fields in the drawing.?


Thanks
Avantika
0 Likes
Message 4 of 5

Anonymous
Not applicable
From VBA Help:

Each individual line of text is a distinct object when using line text. To create a line text object, use the AddText method. This
method requires three values as input: the text string, the insertion point, and the height of the text.
The text string is the actual text to be displayed. Unicode, control code, and special characters are accepted. The insertion point
is a variant array containing three doubles representing the 3D WCS coordinate in the drawing to place the text. The height of the
text is a positive number representing the height of the uppercase text. Height is measured in the current units.

This example creates a line of text in model space, at the coordinate (2, 2, 0).

Sub Ch4_CreateText()
Dim textObj As AcadText
Dim textString As String
Dim insertionPoint(0 To 2) As Double
Dim height As Double

' Create the text object
textString = "Hello, World."
insertionPoint(0) = 2
insertionPoint(1) = 2
insertionPoint(2) = 0
height = 0.5
Set textObj = ThisDrawing.ModelSpace. _
AddText(textString, insertionPoint, height)
textObj.Update
End Sub
0 Likes
Message 5 of 5

arcticad
Advisor
Advisor
I generally avoid passing entity's around to functions.

I've has problems when autocad thinks an object is in use by another function. So it's just a preference to use a string to reference the object. Plus this allows me to store the handle in a database, Xdata or dictionary. So i can reference it later.

If you want to have the date updated then you need to make a block that contains an Attribute. And then reference the block and change the attribute.

For Example.
dim Block as AcadBlockReference
for each item in modelspace
if typeof item is acadblockreference then
if ucase(item.name) = '"MYBLOCKNAME" then
att = item.getattributes
for each attitem in att
if ucase(attitem.tagstring) = "MYATTDATE" THEN
attitem.textstring = now ' Or whatever you want
end if
next
end if
end if

I would then put in ThisDrawing

Private Sub AcadDocument_activate()
call UpdateTheDate
End Sub

So that it's always correct.
---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes