Does anyone have or know of a LISP routine that I can run that will make alternating rows of color in a table?
I can setup a table with the TABLE command and setup the rows to alternate gray and white, but if I add or delete a row, the alternating background fill pattern gets messed up (see attached example). Manually redoing the pattern isn't bad for a few rows, but for 30 or more it's a real pain.
If I could run a command that would activate a routine that would start with gray at the top and then alternate white and gray for every row for the rest of the table, that would be awesome.
Thanks
Solved! Go to Solution.
Solved by Lee_Mac. Go to Solution.
Please try the following program, you may alter the background colour where noted as required:
;; Alternating Table Background Colour - Lee Mac (defun c:altback ( / *error* acc col fnc idx obj row sel tmp ) (defun *error* ( msg ) (if (and (= 'vla-object (type acc)) (not (vlax-object-released-p acc))) (vlax-release-object acc) ) (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")) (princ (strcat "\nError: " msg)) ) (princ) ) (setq col '(215 215 215)) ;; True Colour (r g b) for cell background (if (setq sel (ssget "_:L" '((0 . "ACAD_TABLE")))) (if (setq acc (vla-getinterfaceobject (vlax-get-acad-object) (strcat "autocad.accmcolor." (substr (getvar 'acadver) 1 2)))) (progn (apply 'vla-setrgb (cons acc col)) (repeat (setq idx (sslength sel)) (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))) col (vla-get-columns obj) ) (repeat (setq row (vla-get-rows obj)) (if (zerop (rem (setq row (1- row)) 2)) (setq fnc (lambda ( a b ) (vla-setcellbackgroundcolor obj a b acc))) (setq fnc (lambda ( a b ) (vla-setcellbackgroundcolornone obj a b :vlax-true))) ) (repeat (setq tmp col) (fnc row (setq tmp (1- tmp)))) ) ) (vlax-release-object acc) ) (princ "\nUnable to interface with AcCmColor object.") ) ) (princ) ) (vl-load-com) (princ)
I hope this helps!
Lee
Lee:
That is perfect! Thanks for your help!
This lisp doesn't seem to be working in 2018. When I run it, AutoCAD either locks up or sits there with the spinning wheel indefinitely.
Any chance you can update this routine?
It's working for me in 2018.1.1. Are you patched with the latest version?
How big is your table. I've been using it just fine, but I also just tested in a table with 50 rows and 9 columns and it took about 15 seconds to run through the command. Don't do anything else in the program while it's running through that command, though.
Table is a linked excel datalink file (door schedule) with 19x134 cells. I am running 2018.1.1 as well.
Perhaps this table is just too big...
Any ideas?
My table isn't linked to Excel (all AutoCAD native TABLE command), so that could be the source of the problem you're experiencing.
I just tried to run it on a 19 x 134 table in a 3.1MB drawing with a lot of block and text in it and let it run for over 5 minutes with no completion and about the 4 minute mark it minimized itself and won't restore, so it's probably dead.
So yes, it may just be too large a table for AutoCAD 2018 to deal with. Note my system specs in my signature... nothing underpowered.
A workaround might be to break your rows off into 5 sections and adjust the borders for the new sections so they seamlessly snap into your first table visually. Then AutoCAD might be able to handle it better doing it a section at a time. Not sure if that would be more or less hassle than manually setting the backgrounds.
Hi Lee, this LISP is very useful. Thank you! Is there a way to make it start working after the title and header row, or to specify at which row you want it to begin? Thanks again! Great work!