ILoveMadoka Posted April 13, 2023 Share Posted April 13, 2023 (edited) I'm "transferring my question from here: Out of the box, to make a change to an existing table / tablestyle (specifically the border line weights/fonts) to BYLAYER You have to start the TABLESTYLE command, pick the desired style (we have 12 separate ones) Pick the Borders tab, pick modify, pick the cell style (3ea), set each property to BYLAYER and then assign the lineweight, linetype and color to ALL BORDERS via Apply Properties button. Pick the Text tab and change the font and text height and color. Change to the next cell style and repeat all those steps again. The BYLAYER command does not go into the internals of a table. I also created a "clean" table style then changed my existing tables to that new style but the cell styles kept their original settings. I have found an ALT route using the Properties tab to accomplish the same thing which is a bit quicker. I was hoping to put something together to in a lisp routine so I could pick a table (or all tables) and change the lines colors I found this code from Tharwat - this works (defun c:Test ( / sty tbl obj row col r c) ;; Tharwat - Date: 11.Jul.2017 ;; (setq sty "Standard") ;; Change the Text Style to suit your desired one. (if (and (or (tblsearch "STYLE" sty) (alert (strcat "Text style <" sty "> is not found in drawing <!>")) ) (princ "\nPick on Table :") (setq tbl (ssget "_+.:S:E:L" '((0 . "ACAD_TABLE")))) (setq obj (vlax-ename->vla-object (ssname tbl 0)) row (vla-get-rows obj) col (vla-get-columns obj) r 0 c 0 ) ) (repeat row (repeat col (vla-setcelltextstyle obj r c sty) (setq c (1+ c)) ) (setq r (1+ r) c 0) ) ) (princ) ) (vl-load-com) and I found this somewhere in my travels as well - this works! (defun c:Example_CellMargin_by_Jef() (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) (setq dictionaries (vla-get-Dictionaries doc)) (setq dictObj (vla-Item dictionaries "acad_tablestyle")) (setq keyName "Copy of Standard");name of table style to be changed (setq tempObj (vla-GetObject dictObj keyName)) (vla-put-HorzCellMargin tempObj 0.22) (vla-put-VertCellMargin tempObj 0.25) ) These items from the extended entity list seem to control the color (64 . 10) (65 . 10) (66 . 10) (68 . 10) (69 . 10) Do these two have to do with the border colors? VLA-GETCELLGRIDCOLOR VLA-SETCELLGRIDCOLOR Edited April 13, 2023 by ILoveMadoka Quote Link to comment Share on other sites More sharing options...
ILoveMadoka Posted April 13, 2023 Author Share Posted April 13, 2023 This is my unsuccessful attempt (defun c:test2 () (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) (setq dictionaries (vla-get-Dictionaries doc)) (setq dictObj (vla-Item dictionaries "acad_tablestyle")) (setq keyName "MyStyle");name of table style to be changed - Does Exist (setq tempObj (VLA-GETCELLGRIDCOLOR dictObj keyName)) (VLA-SETCELLGRIDCOLOR tempObj 3) ) Quote Link to comment Share on other sites More sharing options...
ILoveMadoka Posted April 13, 2023 Author Share Posted April 13, 2023 Talking to myself I suppose... I found this code by ronjonp that changes the text color inside a selected table - AWESOME! (defun c:foo (/ co e el o) ;; RJP » 2019-11-12 (cond ((and (setq e (car (entsel))) (= "ACAD_TABLE" (cdr (assoc 0 (setq el (entget e))))) (setq co (vla-get-truecolor (vlax-ename->vla-object e))) (setq o (cdr (assoc 342 el))) ) (vla-put-colorindex co 12) (vla-setcolor (setq o (vlax-ename->vla-object o)) actitlerow co) (vla-put-colorindex co 11) (vla-setcolor o acheaderrow co) (vla-put-colorindex co 256) (vla-setcolor o acdatarow co) ) ) (princ) If I can change the border colors of the three sections I'm golden. Help? Please? 1 Quote Link to comment Share on other sites More sharing options...
Steven P Posted April 13, 2023 Share Posted April 13, 2023 I think there was something about 2 or 3 weeks ago making up tables in the LISP, but I haven't had chance to find the reference and discussion for you yet Quote Link to comment Share on other sites More sharing options...
ILoveMadoka Posted April 13, 2023 Author Share Posted April 13, 2023 (edited) These are existing tables that users have changed each sections line colors for some unknown reason. Fonts too but that issue is solved... (per ronjonp!) Edited April 13, 2023 by ILoveMadoka Quote Link to comment Share on other sites More sharing options...
ILoveMadoka Posted April 13, 2023 Author Share Posted April 13, 2023 (edited) I have all these snippets but I do not possess the skills or knowledge to effectively put them together.. Like these: (VLA-SETCOLOR2 (VLA-SETCELLGRIDCOLOR (VLA-SETCELLGRIDCOLOR2 (vla-SetBackgroundColor I tried marrying those with ronjonp's code above but had no luck whatsoever... I'm a hack that can sometimes get something to work... I rely on people such as yourself or Lee or ronjonp or mhupp or so many others that I could name here to hold my hand or to shine a light or provide the missing pieces.. and for that I am so very grateful.. I've come a long way but I'm still in 1st grade around those who really know what they are doing.. I feel good that I at least try before saying "write me program that does X." Edited April 13, 2023 by ILoveMadoka 1 Quote Link to comment Share on other sites More sharing options...
Steven P Posted April 13, 2023 Share Posted April 13, 2023 (edited) Been doing some reading. See below which adds to RonJons code from a couple of years ago. I've referenced a couple of the posts I looked at for reference. The third one is quite good to keep handy - a complete list of vla- fuctions. I've put a couple of notes in the code, see how this is for you. ;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/tablestyle-text-color/td-p/9142019 ;https://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-7B82400C-53D0-4D1A-94FA-66BB3040F0AA ;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/complete-list-of-vl-vla-and-vlax-functions/td-p/4666405 ;https://help.autodesk.com/view/OARX/2019/ENU/?guid=GUID-DF80B4AB-0481-4702-967F-021B4F59AD9F (defun c:foo (/ co e el o col) ;; RJP » 2019-11-12 (cond ((and (setq e (car (entsel))) (= "ACAD_TABLE" (cdr (assoc 0 (setq el (entget e))))) (setq co (vla-get-truecolor (vlax-ename->vla-object e))) (setq o (cdr (assoc 342 el))) ) ;;Text Colours (vla-put-colorindex co 12) (vla-setcolor (setq o (vlax-ename->vla-object o)) actitlerow co) (vla-put-colorindex co 11) (vla-setcolor o acheaderrow co) (vla-put-colorindex co 256) (vla-setcolor o acdatarow co) ;;Cell Colours: ;;Create a colour object (setq col (vlax-create-object (strcat "AutoCAD.AcCmColor." (substr (getvar "ACADVER") 1 2)))) ;;Setting the table background colours (vla-SetRGB col 240 0 240) ; set the true colour; ;;In the row below note the (+ ac..... ) which is what row types to include (vla-SetBackgroundColor o (+ acTitleRow acHeaderRow acDataRow) col) ;; colour row types ;; Clear the background colors (vla-SetBackgroundColorNone o (+ acTitleRow acHeaderRow acDataRow) :vlax-true) ; no colour in row types ;; Set the border color (vla-SetRGB col 12 34 56) ; set the colour ;;Note 1 you can also do each row type individually (2 rows here) or combined as above (row 1 below) ;;Note 2 the (+ acHorzTop.....) which is which border to adjust (vla-SetGridColor o (+ acHorzTop acHorzBottom acHorzInside acVertLeft acVertRight acVertInside) (+ acHeaderRow acTitleRow) col) ;;Note here that you can use the colour object, col, or the colour index (from RonJon), co. (vla-put-colorindex co 256) ; 0 for ByBlock, 256 for ByLayer (vla-SetGridColor o (+ acHorzTop acHorzBottom acHorzInside acVertLeft acVertRight acVertInside) (+ acDataRow ) co) ;; Release the color object (vlax-release-object col) ) ; end cond ) ; end conds ) Edited April 13, 2023 by Steven P 1 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 14, 2023 Share Posted April 14, 2023 Tables are a bit like dims heaps of variables. You can reset the look of nearly any table after its made can be easier than perhaps trying to make a Table Style. This may help, I just google the VL command for examples. Last one I found was (vla-SetBackgroundColor which set 1 cell similar to the post by Stephen P. In this case a layer color. (setq acm (vla-getinterfaceobject (vlax-get-acad-object) (strcat "Autocad.AcCmcolor." (substr (getvar 'acadver) 1 2)))) (vla-put-colorindex acm lcol) (vla-setcellbackgroundcolor objtable row 2 acm) list of methods for a table.txt 1 Quote Link to comment Share on other sites More sharing options...
Steven P Posted April 14, 2023 Share Posted April 14, 2023 I'd listen to BigAl here - it was his code from about 7 years ago that helped me with mine above Quote Link to comment Share on other sites More sharing options...
ILoveMadoka Posted April 14, 2023 Author Share Posted April 14, 2023 Funny thing... I have this very code open in notepad right now... (setq acm (vla-getinterfaceobject (vlax-get-acad-object) (strcat "Autocad.AcCmcolor." (substr (getvar 'acadver) 1 2)))) (vla-put-colorindex acm lcol) (vla-setcellbackgroundcolor objtable row 2 acm) Have you ever heard the term "A dog with a new pan" or "A cow at a new gate?" I looked at it and had no idea what to do with it... I remember thinking "What does Autocad version have to do with it??" - I suppose that reveals my lack of understanding.. Steven P, your code works perfectly (unless someone has done a manual over-ride in the properties tab.) I can live with that. If I could change anything I'd remove all the RGB references unless there is a setting to make a Truecolor = ByLayer. I'm going to try to figure that out... To keep everything Bylayer I replaced (vla-SetRGB col 12 34 56) or with (vla-put-colorindex col 256) (that seems to have worked) Anyway. Big thank you. (to you both) Appreciate your time and your commented code This was is a biggie in my work process... 1 Quote Link to comment Share on other sites More sharing options...
Steven P Posted April 14, 2023 Share Posted April 14, 2023 Yes, that colour works - I put both in as examples (someone might like a true colour in the future) I'll see if I can think how to reset a properties override - I'd started looking at the border types yesterday but ran out of time to give a good answer for them (would have made my code more complete) Nice to see it is working mostly well Quote Link to comment Share on other sites More sharing options...
ILoveMadoka Posted April 17, 2023 Author Share Posted April 17, 2023 It is working perfectly well... Autocad just makes it so easy to go outside the lines with multiple ways and back doors to change things. Users who don't know what they are doing find a way to modify things that make standardization difficult to maintain. I am so grateful for this. This was a holy grail routine for me. Thank you! Thank you! Thank you!! 1 Quote Link to comment Share on other sites More sharing options...
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.