Author Topic: Stripping text overrides from table cells.  (Read 3755 times)

0 Members and 1 Guest are viewing this topic.

mr_nick

  • Guest
Stripping text overrides from table cells.
« on: February 19, 2007, 04:29:08 AM »
Can anybody point me in the right direction to enable me to strip the overrides from table cells?

If I paste cells from an Excel sheet into AutoCAD as AutoCAD entities, my table is created exactly as I want it - other than the fonts from the sheet come in and override the textstyle. I have tried changing the text in the sheet prior to doing the copy and paste, but the fonts are not the same (look at RomanS insrted in the two ways and you'll see what I mean).

I read the 'text style replacement' thread which looked like it may be of some assistance but right at the end I noticed the line "One thing I did learn from this is that you can't have formatted strings in a Table object. " This goes against what I'm seeing as all the cells, even though using the 'standard' text style, are overridden on the font name and height i.e the cell contents are "{\\fArial|b0|i0|c0;\\H1.098x;Failsworth School}".

Is there an easy way to strip these overrides without having to explode the table and then strip the resultant mtext?

Sdoman

  • Guest
Re: Stripping text overrides from table cells.
« Reply #1 on: February 19, 2007, 08:18:52 AM »
A couple years ago, I worked on removing formatting from Tables as a new feature for StripMtext.  Discovered that it is possible, but if a table cell contains a field, the field will be converted to static text string. 

So it is possible to remove formatting from Table cells using AutoLISP, especially a Table you just created by pasting into AutoCAD.  But if you have embedded field objects in the cells, all that work of creating fields will be lost.  The cells which contain fields will become cells which contain text.

I thought that conversion of fields to text not acceptable and abandon the project. If this is a commonly occurring problem for AutoCAD users, then if I can find the time, I could re-investigate.

mr_nick

  • Guest
Re: Stripping text overrides from table cells.
« Reply #2 on: February 19, 2007, 08:37:32 AM »
Steve.

I had followed the thread on the Autodesk forums in which you had talked of expanding StripMtext functionality and thought I had hit the jackpot - until I found that the thread was a couple of years old  :-(

If you were to put this function, would it not be possible to have an option in the dialog for it to not bother with tables? Although I do occasionally have fields in my tables, I primarily use the copy/paste from Excel and stripping the overrides would be a massive benefit for me.

If you don't have time to instigate this functionality, would you be able to give a few pointers on where to start looking so that I could have a crack at cobbling something together myself?

Sdoman

  • Guest
Re: Stripping text overrides from table cells.
« Reply #3 on: February 19, 2007, 08:58:48 AM »
...
If you were to put this function, would it not be possible to have an option in the dialog for it to not bother with tables? Although I do occasionally have fields in my tables, I primarily use the copy/paste from Excel and stripping the overrides would be a massive benefit for me.
...

I thought about displaying a warning that fields where found in the cell and then prompt to ignore that cell or overwrite with the text value.  Still, it bother me having such a work around.  In your situation, having just pasted in a Table from Excel, I can see that it would save a lot of work and there wouldn't be any fields (yet) anyway.

I have some code (somewhere) that I used for experimenting.  I could send you what I have.  It should work, minus error checking, and minus a snazzy user interface.  It may take me a little while to cobble something more user friendly together. 
 






 

mr_nick

  • Guest
Re: Stripping text overrides from table cells.
« Reply #4 on: February 19, 2007, 09:03:35 AM »
Steve, whatever snippets you would be prepared to throw out would be much appreciated.

Fatty

  • Guest
Re: Stripping text overrides from table cells.
« Reply #5 on: February 19, 2007, 09:22:42 AM »
FYI, this thread must be useful for you:
http://discussion.autodesk.com/thread.jspa?messageID=4834290
then use Hittest to get the cell text value and unformat it

~'J'~

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Stripping text overrides from table cells.
« Reply #6 on: February 19, 2007, 09:39:51 AM »
Good link Fatty. :)

You can try this if you don't mind debugging it. 8-)

Code: [Select]
(defun c:Striptable ()
  (if (setq ss (ssget "_+.:E:S" '((0 . "ACAD_TABLE"))))
    (progn
      (setq taobj (vlax-ename->vla-object (ssname ss 00)))
      (setq ColCnt 0)
      (repeat (vla-get-Columns Obj)
        (setq RowCnt 0)
        (repeat (vla-get-Rows Obj)
          (vla-SetText Obj RowCnt ColCnt (Strip_Text vla-GetText Obj RowCnt ColCnt)))
          (setq RowCnt (1+ RowCnt))
        )
        (setq ColCnt (1+ ColCnt))
      )
    )
  )
  (princ)
)

 Strip_Text by CAB


<edit: fixed the link>
« Last Edit: February 22, 2007, 08:26:15 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

mr_nick

  • Guest
Re: Stripping text overrides from table cells.
« Reply #7 on: February 19, 2007, 10:00:09 AM »
CAB,

With a bit of tweaking, your code does the job handsomely.

Code: [Select]
(defun c:Striptable ()
  (if (setq ss (ssget "_+.:E:S" '((0 . "ACAD_TABLE"))))
    (progn
      (setq obj (vlax-ename->vla-object (ssname ss 00)))
      (setq ColCnt 0)
      (repeat (vla-get-Columns Obj)
        (setq RowCnt 0)
        (repeat (vla-get-Rows Obj)
          (vla-SetText Obj RowCnt ColCnt (Strip_Text (vla-GetText Obj RowCnt ColCnt)))
          (setq RowCnt (1+ RowCnt))
        )
        (setq ColCnt (1+ ColCnt))
      )
    )
  )
  (princ)
)

Thanks to everyone for their input - much appreciated. :-D

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Stripping text overrides from table cells.
« Reply #8 on: February 19, 2007, 10:21:34 AM »
Glad that worked for you. The table loop came from Tim Willey, who also has a text stripper here somewhere.
'steved has the "Mother of All Strippers" so I would be interested in anything he has to share.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Sdoman

  • Guest
Re: Stripping text overrides from table cells.
« Reply #9 on: February 21, 2007, 11:23:42 PM »
Glad that worked for you. The table loop came from Tim Willey, who also has a text stripper here somewhere.
'steved has the "Mother of All Strippers" so I would be interested in anything he has to share.

I wrote something similar to what you posted CAB.  Iterating through the rows and column, getting the cell value, stripping it, and writing it back to the cell.  I recall there being some issues when cells are merged.  Since the OP's issue has been solved, I haven't looked for my code.

And for the record, StripMtext uses John Uhden's Unformat utility.


« Last Edit: February 21, 2007, 11:24:59 PM by 'steved »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Stripping text overrides from table cells.
« Reply #10 on: February 22, 2007, 08:34:21 AM »
And for anyone wanting a look at StripMtext by Steve Doman look here http://tinyurl.com/32kxkr
And by John Uhden look here: http://tinyurl.com/2kbmvz
And for Tim Willey look here: http://www.theswamp.org/index.php?topic=14247.msg172893#msg172893
« Last Edit: February 22, 2007, 08:40:22 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ur_naz

  • Newt
  • Posts: 68
  • Made in Ukraine
Re: Stripping text overrides from table cells.
« Reply #11 on: August 02, 2014, 06:03:45 AM »
Is it possible to make StripMText to work with mtexts inside blocks, also anonimous blocks?