.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

get object id of string in table

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
802 Views, 8 Replies

get object id of string in table

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.
8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: Anonymous

I guess I just ask question on things that
either no one knows about, or no one cares about.
Message 3 of 9
Anonymous
in reply to: Anonymous

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.
Message 4 of 9
Mikko
in reply to: Anonymous

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
Message 5 of 9
jbooth
in reply to: Anonymous

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.
Message 6 of 9
Mikko
in reply to: Anonymous

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.
Message 7 of 9
Anonymous
in reply to: Anonymous

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
Message 8 of 9
Anonymous
in reply to: Anonymous

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).
Message 9 of 9
jbooth
in reply to: Anonymous

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.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost