.NET

Reply
*perry
Message 1 of 9 (238 Views)

get object id of string in table

238 Views, 8 Replies
05-25-2007 11:50 AM
How do you get the object id of a text string in a table?
I want to get it so I can attach a hyperlink, but do not see how.

After inserting a string into a cell via this code....
myTable.SetTextString(0, 0, "test");
I can then verify the text is there like so...
string test = myTable.TextString(0, 0);//reveals above "test"
But attempts to get its object id like the following fail...

ObjectId temp = myTable.FieldId(0, 0);
ObjectId temp2 = myTable.BlockTableRecordId(0, 0);

Any pointers would be appreciated.
*perry
Message 2 of 9 (238 Views)

Re: get object id of string in table

05-29-2007 09:35 AM in reply to: *perry
I guess I just ask question on things that
either no one knows about, or no one cares about.
*Kerry Brown
Message 3 of 9 (238 Views)

Re: get object id of string in table

05-30-2007 02:39 AM in reply to: *perry
Any joy with
GetFieldId
or
GetValue



"perry" wrote in message
news:5609833@discussion.autodesk.com...
I guess I just ask question on things that
either no one knows about, or no one cares about.
Distinguished Contributor
Mikko
Posts: 212
Registered: ‎10-03-2003
Message 4 of 9 (238 Views)

Re: get object id of string in table

05-30-2007 06:10 AM in reply to: *perry
Select your table which is a blockreference and walk yourself through the ObjectIds.
If MText then add your hyperlink to the entity. Maybe something like:

For Each blkId In btr
ent = CType(t.GetObject(blkId, OpenMode.ForWrite), Entity)
If ent.GetType.Name = "MText" Then
Dim tblTxt As MText = ent
Dim hlc As HyperLinkCollection = tblTxt.Hyperlinks
Dim hl As New HyperLink()
hl.Name = "http://www.msn.com"
hlc.Add(hl)
End If
Next
Distinguished Contributor
jbooth
Posts: 223
Registered: ‎02-17-2006
Message 5 of 9 (238 Views)

Re: get object id of string in table

05-30-2007 09:14 AM in reply to: *perry
That sounds really slow, given that you will probably walk through each cell's border line entities, and whatnot.

There's also the possibility that merged cells could have text values that you don't see unless you unmerge the cells, meaning they could be accidentally selected by your code (instead of what you want).

I did look into this and I don't really know of a solution, except that maybe there is no ObjectId for the text. It's possible the text is a string value on a cell, and the cell is what has an ObjectId. Unfortunately I couldn't find a query function to get a cell's ObjectId either.

I have a feeling that the wrapper object(s) for AcDb.Tables are not yet complete.
Distinguished Contributor
Mikko
Posts: 212
Registered: ‎10-03-2003
Message 6 of 9 (238 Views)

Re: get object id of string in table

05-30-2007 09:35 AM in reply to: *perry
slow-and-steady.... Aesop's fables

Public Sub HyperTable()
Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Using t As Autodesk.AutoCAD.DatabaseServices.Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()

Dim psr As PromptSelectionResult
Dim idArray() As ObjectId
Dim objId As ObjectId
Dim ent As Entity
Try
Dim filterfor() As TypedValue = {New TypedValue(0, "ACAD_TABLE")}
Dim sf As SelectionFilter = New SelectionFilter(filterfor)
psr = ed.SelectAll(sf)
If psr.Status = PromptStatus.OK Then
Dim ss As Autodesk.AutoCAD.EditorInput.SelectionSet = psr.Value
idArray = ss.GetObjectIds()
For Each objId In idArray
Dim br As BlockReference = CType(t.GetObject(objId, OpenMode.ForWrite), BlockReference)
Dim brId As ObjectId = br.BlockTableRecord
Dim btr As BlockTableRecord = CType(t.GetObject(brId, OpenMode.ForWrite), BlockTableRecord)
Dim blkId As ObjectId
For Each blkId In btr
ent = CType(t.GetObject(blkId, OpenMode.ForWrite), Entity)
If ent.GetType.Name = "MText" Then
Dim tblTxt As MText = ent
Dim hlc As HyperLinkCollection = tblTxt.Hyperlinks
Dim hl As New HyperLink()
hl.Name = "http://en.wikipedia.org/wiki/The_Tortoise_and_the_Hare"
hlc.Add(hl)
End If
Next
Next objId
End If
t.Commit()
Catch ex As Exception
Finally
psr = Nothing
idArray = Nothing
objId = Nothing
ent = Nothing
End Try
End Using
End Sub

Works for me.
*perry
Message 7 of 9 (238 Views)

Re: get object id of string in table

05-30-2007 10:17 AM in reply to: *perry
Thanks for the input guys.
I had considered just looping through the entire
table object but it seemed like a lot of overhead.
Since there where "getter/setter" methods for getting
the text styles, I figured there must be a method for
getting the text itself (not just the string value) and
I was just not seeing it. Guess I'm not so blind
after all. There is no "good" way to do this.
Perry
*perry
Message 8 of 9 (238 Views)

Re: get object id of string in table

05-30-2007 10:20 AM in reply to: *perry
Oh yeah, I did look closely at the
table class definition (net version)
guess I better take a close look at the
arx version, maybe theres a method in there
I can pInvoke (maybe not).
Distinguished Contributor
jbooth
Posts: 223
Registered: ‎02-17-2006
Message 9 of 9 (238 Views)

Re: get object id of string in table

05-30-2007 12:43 PM in reply to: *perry
Just a preference, but I would change:

If ent.GetType.Name = "MText" Then
to:
If TypeOf ent is AcDb.MText Then

Only because I'm pretty sure the compiler handles object type comparisons faster than string comparisons.
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!