Visual Basic Customization

Visual Basic Customization

Reply
*John Sauber
Message 1 of 4 (46 Views)

deleting an item from an array of text objects

46 Views, 3 Replies
01-25-2006 11:54 AM
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
Distinguished Contributor
Bryco
Posts: 525
Registered: ‎10-25-2005
Message 2 of 4 (46 Views)

Re: deleting an item from an array of text objects

01-25-2006 05:12 PM in reply to: *John Sauber
You may want to make them blocks w/ names 10-3 etc, having one attribute instead of the text.
Distinguished Contributor
fxcastil
Posts: 404
Registered: ‎11-11-2002
Message 3 of 4 (46 Views)

Re: deleting an item from an array of text objects

01-25-2006 07:15 PM in reply to: *John Sauber
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
*John Sauber
Message 4 of 4 (46 Views)

Re: deleting an item from an array of text objects

01-26-2006 07:31 AM in reply to: *John Sauber
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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!