VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

deleting an item from an array of text objects

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
263 Views, 3 Replies

deleting an item from an array of text objects

I have the following routine which inserts text (a number from 0 to 3) at
locations picked by the user. It's actually creating 11 sets of 4 text
objects each. This routine works fine, but I want to make it possible to
modify any one of these text objects, for example, replace textObj(5,3) with
a new text string and location.

I've tried just redefining textObj(5,3) with another AddText entry, but that
only creates a new entry on top of the old entry. I know that they are all
stored as Items in aDoc.ModelSpace, so I really need to replace the Item,
not the textObj. So the question is: what's the easiest way to identify
which item is actually textObj(5,3)? I could search all items for one with
the same insertion point as the textObj, but it's possible that that might
screw up and delete the wrong thing. Any other ideas?

Thanks in advance,

John S

=========================================

Dim aDoc As AcadDocument
Dim textObj(10, 3) As AcadText
Dim Loc As Variant

for i = 0 to 10
for j = 0 to 3
Loc = aDoc.Utility.GetPoint(, "Click on the location for bond #" & j
& " on lead #")
' insert the value of "j" as a text object in the drawing
Set textObj(i, j) = aDoc.ModelSpace.AddText(j), Loc, 0.004)
next j
next i
3 REPLIES 3
Message 2 of 4
Bryco
in reply to: Anonymous

You may want to make them blocks w/ names 10-3 etc, having one attribute instead of the text.
Message 3 of 4
fxcastil
in reply to: Anonymous

John,

I am not quite sure why you are creating an array of
textobj(10,3). If you are just inserting the text you dont need to do this with an array of textobj. I will assume you created the array to keep track of each textobj seperately.

If that was the reason then what you want to keep track of is the "handle" property of each text object . The handle is a unique long variable for each entity in the drawing.

Look at the "Handle" property and "HandleToObject" property.
If you know the "handle" you then use the "HandleToObject" to get a hold (set a variable) of that entity and erase or modify it.
Dim aDoc As AcadDocument
Dim objText As AcadText

Dim textObj(10, 3) As AcadText
Dim Loc As Variant
Dim returnPnt As Variant
Dim i As Integer
Dim j As Integer

'
For i = 0 To 2
For j = 0 To 3


Loc = ThisDrawing.Utility.GetPoint(, "Click on the location for bond #" & j & " on lead #")
' insert the value of "j" as a text object in the drawing
Set textObj(i, j) = ThisDrawing.ModelSpace.AddText((j), Loc, 0.004)

MsgBox textObj(i, j).Handle

Next j



Next i

Dim objent As AcadEntity


For Each objent In ThisDrawing.ModelSpace

If UCase(objent.ObjectName) = UCase("AcDbText") Then
MsgBox objent.Handle
End If

Next

Fred C
Message 4 of 4
Anonymous
in reply to: Anonymous

Fred,

Yes, I need the array to keep track of each textobj separately. . . it's a
long story why.

Your solution with the Handle property was exactly what I was looking for. .
. a unique identifier that both textobj and modelspace.items have in common.

One thing I'm curious about though, if I look at what's inside either
textobj or modelspace.items using the watch window, I can see all kinds of
properties, but not "handle". Why is it hidden? Is there any way to make
it visible? Not that important if you don't know. . . just a curiosity.

Thanks much for the help,

John S.


wrote in message news:5068979@discussion.autodesk.com...
John,

I am not quite sure why you are creating an array of
textobj(10,3). If you are just inserting the text you dont need to do this
with an array of textobj. I will assume you created the array to keep track
of each textobj seperately.

If that was the reason then what you want to keep track of is the "handle"
property of each text object . The handle is a unique long variable for each
entity in the drawing.

Look at the "Handle" property and "HandleToObject" property.
If you know the "handle" you then use the "HandleToObject" to get a hold
(set a variable) of that entity and erase or modify it.
Dim aDoc As AcadDocument
Dim objText As AcadText

Dim textObj(10, 3) As AcadText
Dim Loc As Variant
Dim returnPnt As Variant
Dim i As Integer
Dim j As Integer

'
For i = 0 To 2
For j = 0 To 3


Loc = ThisDrawing.Utility.GetPoint(, "Click on the location for bond #"
& j & " on lead #")
' insert the value of "j" as a text object in the drawing
Set textObj(i, j) = ThisDrawing.ModelSpace.AddText((j), Loc, 0.004)

MsgBox textObj(i, j).Handle

Next j



Next i

Dim objent As AcadEntity


For Each objent In ThisDrawing.ModelSpace

If UCase(objent.ObjectName) = UCase("AcDbText") Then
MsgBox objent.Handle
End If

Next

Fred C

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost