Find/Replace Blank Table Cell Values

Brent.Mierzwiak
Explorer

Find/Replace Blank Table Cell Values

Brent.Mierzwiak
Explorer
Explorer

Can anyone provide me with simple coding that would enable me to batch edit blank table cell values?  The AutoCAD find/replace utility doesn't execute with a blank entry (not a space) in the Find what text entry box.  For my specific application I want to find all of the blank cells in a single table in the current AutoCAD drawing and replace those with a "-".  That would simply convey to the audience that the specification for a given parameter is unknown, wasn't provided, or simply isn't necessary - whereas a blank cell might indicate that the specification is tbd or perhaps was overlooked, and needs to ultimately be provided.  So far, all of the online batch find/replace utilities I have tried have the same limitation as AutoCAD's find/replace utility.  Perhaps there's a wildcard sequence or other character code I could use to act as a substitute for a blank value?

0 Likes
Reply
Accepted solutions (1)
1,530 Views
6 Replies
Replies (6)

Sea-Haven
Mentor
Mentor
Accepted solution

You need to look at various table functions, 2 in particular get num rows and get num cols. So you make a double repeat.

(vla-get-rows obj) same for columns

 

(repeat numcols

(repeat numrows 

then

(setq txt (vla-gettext objtable row col ))

then check if blank

(vla-settext objtable row col  "-")

add 1 to row

)

reset row to 2

add 1 to col

) ; repeat

) ; repeat

 

Have a go, a good task to start learning about loops.

0 Likes

Brent.Mierzwiak
Explorer
Explorer

Nice...that looks reasonable.  I will give it a dig.  I realize (think) my request is fundamental but, after all, automation beats manual hands down!

0 Likes

Sea-Haven
Mentor
Mentor

If you get stuck post what you have get more help if you have a go.

0 Likes

Brent.Mierzwiak
Explorer
Explorer

Here is the code that I assembled and derived, mostly using bits and pieces of code that I referenced from other Autodesk postings and web threads.  It seems to work quite well but table operations aren't exactly instantaneous.  Oh well, beggars can't be choosey.  Kudos go out to Sea-Haven, Lee Mac, etc...you guys certainly know what you're doing.

 

(defun c:tbd ( / sel )

   (if (setq sel (ssget "_+.:E:S" '((0 . "ACAD_TABLE"))))

       (tbd (vlax-ename->vla-object (ssname sel 0)))

   )

)

(defun tbd ( obj / col row txt )

   (repeat (setq row (vla-get-rows obj))

       (repeat (setq row (1- row) col (vla-get-columns obj))

           (setq txt (vla-gettext obj row (setq col (1- col))))

             (if (= txt "")

               (setq txt (vla-settext obj row col "-"))

             )

       )

   )

(princ)

)

 

My next self-imposed task is to create a companion routine that will perform the same replacement function but exclude operating on all of the cells in a couple of columns, in my case columns 3 and 4.  Sea-Haven, without giving me the full answer, can you provide me with a hint as to how to approach that variation using the code above as my basis?  I enjoy a challenge and the discovery from learning.

 

Thank you in advance!

0 Likes

Sea-Haven
Mentor
Mentor

Happy to help best way to learn, set your max rows and columns outside the repeats if you want cols 3 & 4 only then set col repeat to 2 set col to 3.

 

A bit of rearranging the repeats that is all.

0 Likes

Brent.Mierzwiak
Explorer
Explorer

Ok, and just to confirm, your hint applies to excluding columns 3/4, correct?

0 Likes