Selecting and accessing text objects

Selecting and accessing text objects

Anonymous
Not applicable
308 Views
3 Replies
Message 1 of 4

Selecting and accessing text objects

Anonymous
Not applicable
The help file shows how to create a piece of text, then change some of it's properties, such as alignment. It does not show how to select an existing piece of text through code (no user intervention needed).

I have written something that selects some text objects from the modelspace collection based on some search criteria (layer, color, etc.). I have these objects in an array of type AcadEntity, but I can't find a way to access the .alignment or .rotation for these because they are not defined as text objects.

Is there a way to convert an AcadEntity to an AcadText object? Or is there some other way to select text as AcadText objects?

Any help on this would be greatly appreciated.
0 Likes
309 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
If you are confident that the object is AcadText, but declared as
AcadEntity, you can still use the properties (just no IntelliSense). Or you
can cast them:

Sub Test()
Dim myObj As AcadEntity
With ThisDrawing.ActiveLayout.Block
Set myObj = .Item(.Count - 1) ' assumes last object is text object
Debug.Print myObj.TextString
End With
If TypeOf myObj Is AcadText Then
Dim myText As AcadText
Set myText = myObj
Debug.Print myText.TextString
End If
End Sub


--
R. Robert Bell


wrote in message news:5088211@discussion.autodesk.com...
The help file shows how to create a piece of text, then change some of it's
properties, such as alignment. It does not show how to select an existing
piece of text through code (no user intervention needed).

I have written something that selects some text objects from the modelspace
collection based on some search criteria (layer, color, etc.). I have these
objects in an array of type AcadEntity, but I can't find a way to access the
.alignment or .rotation for these because they are not defined as text
objects.

Is there a way to convert an AcadEntity to an AcadText object? Or is there
some other way to select text as AcadText objects?

Any help on this would be greatly appreciated.
0 Likes
Message 3 of 4

Anonymous
Not applicable
I am still having a little trouble with this. Here is what I am attempting.

I am in a loop through the model space collection. Element I matches all my criteria, I just have to test that it is actually Text, then I want to, using some conditions, middle justify it and change it's alignment.

If TypeOf ThisDrawing.ModelSpace.Item(I) Is AcadText Then
Set aTextObject = ThisDrawing.ModelSpace.Item(I)
aTextObject.Alignment = acAlignmentMiddleCenter
aTextObject.Rotation = aTextObject.Rotation + PI
endif

The first line does not seem to work for this (does not stop at text).
When I force it through this the Set line gives me an error.

Do you have any suggestions, or is there some other approach I should be using to do this?

Thanks
0 Likes
Message 4 of 4

Anonymous
Not applicable
This is how I'd do it.....
Dim oEnt as AcadEntity
Dim oTxt as AcadText

For Each oEnt in ThisDrawing.ModelSpace
If TypeOf oEnt is AcadText Then
Set oTxt = oEnt
oTxt.Alignment = acAlignmentMiddleCenter
oTxt.TextAlignmentPoint = oTxt.InsertionPoint
oTxt.Rotation = oTxt.Rotation + PI
oTxt.Update
End If
Next

HTH,
Jeff

wrote in message news:5088617@discussion.autodesk.com...
I am still having a little trouble with this. Here is what I am attempting.
0 Likes