Jump to content

Get handle of text in a table cell


Tyke

Recommended Posts

I have a table with text entries in the cells, I want to extract the cell text and the handle to that text and save it to an external document.
The only thing I am unable to do is get the text handle and I cannot find any examples in the web. I can get the handle of the table, but that doesn't help.

Does anybody know how to get the handle?

 

Thanks for any advice.

Ben

Edited by Tyke
ps I'm using VBA here.
Link to comment
Share on other sites

1 hour ago, Tyke said:

I have a table with text entries in the cells, I want to extract the cell text and the handle to that text and save it to an external document.
The only thing I am unable to do is get the text handle and I cannot find any examples in the web. I can get the handle of the table, but that doesn't help.

Does anybody know how to get the handle?

 

Thanks for any advice.

Ben

 

Sub MyTable()
Dim pt As Variant
Dim ent As AcadEntity
ThisDrawing.Utility.GetEntity ent, pt, vbCr & "Pick a required entity: "
Open "C:\Users\IO\Documents\DataFromTable.txt" For Output As #1
        If TypeOf ent Is AcadTable Then
        TableRows = ent.Rows
        TableCol = ent.Columns
            For X = 1 To TableRows
                For Y = 0 To TableCol - 1
                    RetVal = ent.GetText(X, Y)
                    Print #1, X, Y, RetVal
                Next
            Next
        End If
        
Close #1

End Sub

image.png.ef3d17df980b44fb4cee73c8ebec0a33.png

 

Result

image.png.118f670dd42059710ad5db681ba43612.png

Link to comment
Share on other sites

Not real sure about this (entget (car (nentsel))) appears to give handle of text when you pick a cell not a table.

 

If you explode you will get a different handle id for the text.

Edited by BIGAL
Link to comment
Share on other sites

@PeterPan9720

Thanks for the code, but you are writing to the table and I want to deal with an existing table not create one. I can iterate through each cell and get the text in that cell, but what I can't do is get the handle of the text object.

Thanks, Ben

Link to comment
Share on other sites

@BIGAL

Thanks BigAl,

I'm working in VBA not LISP, but is it possible to do that in VBA?

This is the code that I'm using:

            ' loop thro each cell in table
            For r = 0 To objEnt.rows - 1
                                
                For c = 0 To objEnt.Columns - 1
                    
                    strText = oTable.GetText(r, c)
                    strHandle = objEnt.Handle
                    
                    Write2Word
                    
                Next c
                
            Next r

I can see that "objEnt.Handle" will return the handle of the table, which it does just fine. "oTable.GetText(r, c)" returns the text in the cell but not the text object in the cell so I can't get at its handle.

The text is exported to Word and/or Excel and edited in a translation tool and then reinserted into the drawing. The reinsertion process uses the text objects handle, so it's important to be able to get the handle in the first place.

If its not possible to get the handle then I could look at a workaround of getting the table and creating a dummy handle bases on the cell place in the table. A lot more work and not as neat, but it could be doable.

Thanks,

Ben

Link to comment
Share on other sites

4 hours ago, Tyke said:

@PeterPan9720

Thanks for the code, but you are writing to the table and I want to deal with an existing table not create one. I can iterate through each cell and get the text in that cell, but what I can't do is get the handle of the text object.

Thanks, Ben

@Tyke

,,,,but you are writing to the table,,,

Please look at the code, I'm not writing the table, I'm reading the text inside once you select the wanted table object, if you have more than one table, this is another issue, and different from what you asked.

The print #1 has been used for write on text file, not on the table, be aware.

 

See :

 

ThisDrawing.Utility.GetEntity ent, pt, vbCr & "Pick a required entity: " ' Select an object,
' once selected you will have also the coordinates in pt variable as array X, Y, Z (0 to 2 double precision).

        If TypeOf ent Is AcadTable Then ' If object it's a table then write on txt file the value.

The text file produce could be referenced by row and column write with the cell value.

If want to manipulate the text you can, and of course re-import into the table in the same way.

If you want to scan all tables in the drawing and for each have an handle, I guess it's possible (I have to check) so when you import manipulated text you will have the handle of wanted table.

So really I don't understand why the above code do not cover your requirements.

 

Edited by PeterPan9720
Link to comment
Share on other sites

@PeterPan9720

I understand what you are doing but you have missed the point of what I'm trying to do. I want to get the handle of the text object in the cell, I have already got the text object value. I have the handle of the table, but that doesn't really help me here, other when there are multiple tables in the drawing.

Link to comment
Share on other sites

@Tyke You have the row and column of table text value, and table handle, so it could be easy to rewrite the table.

So i didn't miss that part.

Again you didn't talk until now of more than one table.

If you have more than one table you have to use a different way to select all table, like as Selection Set and each table will have an handle, and/or a specific title available at row, col 0,0

Edited by PeterPan9720
Link to comment
Share on other sites

It's not just tables I'm dealing with, I'm going through each object in the drawing and when I know what kind of object it is, for example "AcDbMText" then I have a Case Select which deals with each type of object that I am interested in, not just tables. For a table I have no problem retrieving the cell value but I need the cell value AND the handle of of the text object in that cell. Writing values back to to a cell is also not a problem, but the whole program is based on using handles to access the various objects and I want to stay with that principle.

Link to comment
Share on other sites

13 minutes ago, Tyke said:

It's not just tables I'm dealing with, I'm going through each object in the drawing and when I know what kind of object it is, for example "AcDbMText" then I have a Case Select which deals with each type of object that I am interested in, not just tables. For a table I have no problem retrieving the cell value but I need the cell value AND the handle of of the text object in that cell. Writing values back to to a cell is also not a problem, but the whole program is based on using handles to access the various objects and I want to stay with that principle.

@Tyke

So the input data has been changed, due to you wrote "...I have a table with text entries in the cells, I want to extract the cell text ...." you didn't talk about different objects.

You can try to use the API with WriteProfileString and ReadProfileString, it's the same method used for read and write Windows INI file, so when the object it's a text you will write an header with [TEXT] or if object it's a table you will write [TABLE], followed by Handle.

Sub ApplicationProfile
  Dim strSection, strStringItem, strIntItem
  strSection = "My Section"
  strStringItem = "My String Item"
  strIntItem = "My Int Item"

  'Write a string value to ArcPad.ini
  Call Application.WriteProfileString(strSection, strStringItem, "test")

  'Retrieve the string value
  Dim strValue
  strValue = Application.GetProfileString(strSection, strStringItem)
  'Display the value retrieved
  MsgBox strValue

  'Write an integer value to ArcPad.ini
  Call Application.WriteProfileInt(strSection, strIntItem, 60)

  'Retrieve the integer value
  Dim intValue
  intValue =Application.GetProfileInt(strSection, strIntItem)
  'Display the value retrieved
  MsgBox intValue
End Sub

 

Edited by PeterPan9720
Link to comment
Share on other sites

Need a select Cell 3,2 etc then look at what it is you can have say a block, so not just text, others like background colour. You want all properties of cell.

 

Found something Acad Table Object - AutoCAD 2006 VBA - Visual Basic for Applications (engram9.info) go fair way down talks about select cell, method then you would do possibly strHandle = objEnt.Handle cell, I dont play much in VBA so will leave for others.

 

(vlax-dump-object  (vlax-ename->vla-object (car  (nentsel "Pick cell text"))))

 

 

 

 

 

 

Edited by BIGAL
Link to comment
Share on other sites

  • 2 weeks later...

Hi BigAl,

According to Autodesk the table object in AutoCAD is not a complex object and the cells do not have a text object in them. They are more like the caption on a user form, they have a value but more like a caption in a table. You can see this when you try to select the text in a cell, you can't.

 

I got around the problem by creating a dummy handle for each cell bases on the table handle and the row and column indices, with that I can retrieve the cell value and later reinsert the edited value back into the table.

 

Thank you for you time in helping me, it is appreciated. This post is just to close off the topic.

Best regards,

Ben

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...