Tyke Posted February 15, 2021 Posted February 15, 2021 (edited) 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 February 15, 2021 by Tyke ps I'm using VBA here. Quote
PeterPan9720 Posted February 15, 2021 Posted February 15, 2021 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 Result Quote
BIGAL Posted February 15, 2021 Posted February 15, 2021 (edited) 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 February 15, 2021 by BIGAL Quote
Tyke Posted February 16, 2021 Author Posted February 16, 2021 @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 Quote
Tyke Posted February 16, 2021 Author Posted February 16, 2021 @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 Quote
PeterPan9720 Posted February 16, 2021 Posted February 16, 2021 (edited) 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 February 16, 2021 by PeterPan9720 Quote
Tyke Posted February 16, 2021 Author Posted February 16, 2021 @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. Quote
PeterPan9720 Posted February 16, 2021 Posted February 16, 2021 (edited) @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 February 16, 2021 by PeterPan9720 Quote
Tyke Posted February 16, 2021 Author Posted February 16, 2021 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. Quote
PeterPan9720 Posted February 16, 2021 Posted February 16, 2021 (edited) 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 February 16, 2021 by PeterPan9720 Quote
BIGAL Posted February 17, 2021 Posted February 17, 2021 (edited) 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 February 17, 2021 by BIGAL Quote
Tyke Posted February 25, 2021 Author Posted February 25, 2021 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 Quote
Recommended Posts
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.