Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Table Cell Text String Different From String Displayed

DGCSCAD
Advocate

Table Cell Text String Different From String Displayed

DGCSCAD
Advocate
Advocate

After running the LISP below (I forgot where I found it, so if it's yours, I apologize), the old string that has been replaced remains in the updated table cell and properties, but the string displayed in the updated table cell displays the new string. So, when modifying or selecting the table cell, it shows/returns the old string.

 

I'm just trying to save the displayed text string as a variable for now.

 

 

(defun replacestr (Obj new old / str)
   (foreach Property '(TextString TextOverride)
     (and
       (vlax-property-available-p Obj Property)
       (setq str (vlax-get Obj Property))
       (while (vl-string-search old str) ;;<- look for string
          (setq str (vl-string-subst new old str )) ;;<-replace here
          (vlax-put Obj Property str)
       )
     )
  )
)

(defun replaceall (new old)
   (vlax-for n
 	    (vla-get-blocks
 	      (vla-get-activedocument
 		(vlax-get-acad-object)))
     (vlax-for m n
       (if (and  (= "AcDbBlockReference" (vla-get-objectname m))
 	     (= :vlax-true (vla-get-hasattributes m)))
          (foreach att (vlax-invoke m  'getattributes)
             (replacestr att new old)
          )
          (replacestr m new old)
       )
     )
   )
 )

 

 

Displayed Text: 84100299

Actual Text String: $CABLE

 

Table Cell Text String Problem 001.png

 

A nudge as to how/why this is happening would be greatly appreciated.

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Reply
409 Views
13 Replies
Replies (13)

DGCSCAD
Advocate
Advocate

I'm including a dwg and lsp for others to test and see.

 

I realize the code I used was meant for attributes, but it worked (or, at least I thought it worked) for table cell text, so I ran with it. Just trying to unravel what has been done for now.

AutoCad 2018 (full)
Win 11 Pro
0 Likes

paullimapa
Mentor
Mentor

Not working properly because TABLES & Cells are not the same as BLOCKS & Attributes.

I found this code here which searches for a blank Cell value & replaces it with a "-":

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/find-replace-blank-table-cell-values...

I modified and called it tbsr.lsp 

At the beginning of the code is where I defined what you're searching for & replacing.

So you can change this to match your needs:

 (setq valuefind    "$CABLE"
       valuereplace "TESTING"
 )

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes

DGCSCAD
Advocate
Advocate

Thank you Paul.

 

I have a few functions that find/replace table cell text strings, I was just wondering why/how that situation occurred. I was going to try and grab the displayed text string from the errant cells to see if I can correct it with lisp, but there's no way to do that.

 

I was pressed for time and slapped that piece of code in where I should have used a specific-to-table-cell function. I thought it would work as a catch-all for tables, atts, mtext, etc., but I failed to investigate it further. I only found out about it when a coworker pointed it out to me.

AutoCad 2018 (full)
Win 11 Pro
0 Likes

paullimapa
Mentor
Mentor

If you're curious as to what's actually being evaluated with the testtbl.lsp function you quickly put together, I placed a number of alert functions in the revised version attached so you can be notified as to what's going on. 

FYI: Though a Table object is considered as a Block, it does not have Attributes. So you don't need an If statement to check this:

 

(if (and  (= "AcDbBlockReference" (vla-get-objectname m))
 	     (= :vlax-true (vla-get-hasattributes m)))

 

Instead a more accurate way to use an If statement to check is to look for the actual name of the Table object which is "AcDbTable"

Also fortunately, we don't have to cycle through the Table block object searching for the MText object (bypassing all the Line objects that make up the Table) to change the TextString value. Instead we are to use the (vla-settext) function which requires the Table object's row & column numbers to locate the Text value to be changed.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes

komondormrex
Advisor
Advisor

@DGCSCAD wrote:

A nudge as to how/why this is happening would be greatly appreciated.


well, there is how it works.

replaceall function iterates through all objects in a dwg database. there is no difference if there are table blocks, because it will iterate though all table objects too. if it find any object that has say text object with textstring or textoverride properties (these are dims i suppose) it will pass it to replacestr  function which replaces string from to. 

thus replaceall function will do replacing for all applicable objects. but tables are service dynamic blocks with theirs definition and it just cannot get inside that definition and do its stuff. but it could make a one_time_replacing_until_regenerated changing for table definition. that's it.

0 Likes

DGCSCAD
Advocate
Advocate

@paullimapa 

@komondormrex 

I appreciate the explanations. Thank you for that.

 

The one question I have is: Where is the "TESTING" string stored (see example 1 below)?

 

If I close the dwg, then reopen, the cell will display "TESTING" until I click on it (see example 2 below).

 

acad_mj2OS3cb9n.gif

acad_zbPjgyeI7A.gif

AutoCad 2018 (full)
Win 11 Pro
0 Likes

komondormrex
Advisor
Advisor

i may presume it is stored in a sort of screen temporal version of a table block which is not real interpretation until it regenerated.

autocad developers know that for sure)

0 Likes

DGCSCAD
Advocate
Advocate

It does seem to be that way. I appreciate the insight.

AutoCad 2018 (full)
Win 11 Pro
0 Likes

paullimapa
Mentor
Mentor

Once you Move it that version is gone. Same when you Cooy the new version only shows the original string. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes

DGCSCAD
Advocate
Advocate

Yes, I had noticed that. I'd really like to know where that 'phantom' text is located in the drawing database since it's saved with the drawing.

AutoCad 2018 (full)
Win 11 Pro
0 Likes

paullimapa
Mentor
Mentor

Only Autodesk knows. But Iโ€™m sure they wonโ€™t tell. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes

DGCSCAD
Advocate
Advocate

Keep Your Secrets ADesk.png

AutoCad 2018 (full)
Win 11 Pro

paullimapa
Mentor
Mentor

lol...you know what they say"

"if they tell you they'll have to .... you"


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos