Author Topic: Creating Tables  (Read 2157 times)

0 Members and 1 Guest are viewing this topic.

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Creating Tables
« on: March 11, 2020, 11:35:32 AM »
Trying to add cell color to the table style when being created, what I have is not working....

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun Mk-Tbl-Style ( tbl-name / *doc* tblstyls tblstyl)        
  3.       (setq
  4.         *doc*     (vla-get-activedocument (vlax-get-acad-object))
  5.         tblstyls  (vla-item (vla-get-dictionaries *doc*) "acad_tablestyle")
  6.       )  
  7.       (if
  8.         (vl-catch-all-error-p ;;try to get the existing Style
  9.           (vl-catch-all-apply
  10.              '(lambda ()
  11.                (setq tblstyl (vla-item tblstyls tbl-name))
  12.               )              
  13.           )
  14.         )
  15.         (progn
  16.           (setq        tblstyl  (vla-addobject tblstyls tbl-name "AcDbTableStyle"))
  17.           (vlax-put    tblstyl 'Description  "SA-Table")
  18.           (vlax-put    tblstyl 'FlowDirection     0);;top to bottom or bottom to top
  19.           (vlax-put    tblstyl 'HeaderSuppressed  0);;header on = 0 off = -1
  20.           (vlax-put    tblstyl 'HorzCellMargin 0.06)
  21.           (vlax-put    tblstyl 'TitleSuppressed   0);;Title on = 0 off = -1
  22.           (vlax-put    tblstyl 'VertCellMargin 0.06)                              
  23.           (vlax-invoke tblstyl 'SetTextStyle  acTitleRow  "SA-Table-Name")  
  24.           (vlax-invoke tblstyl 'SetAlignment  acTitleRow  acMiddleCenter)
  25.           (vlax-invoke tblstyl 'SetTextStyle  acHeaderRow "SA-Table-Clmn-Title")
  26.           (vlax-invoke tblstyl 'SetAlignment  acHeaderRow acMiddleCenter)
  27.           (vlax-invoke tblstyl 'SetTextStyle  acDataRow   "SA-Table-Cell")     
  28.           (vlax-invoke tblstyl 'SetAlignment  acDataRow   acMiddleCenter)
  29.           (Update_Xrecord tbl-name 140 2.25 0)
  30.           (Update_Xrecord tbl-name 140 4.00 1)
  31.           (Update_Xrecord tbl-name 140 2.25 2)
  32.  ;         (Update_Xrecord tbl-name  91    6 0)
  33.  ;         (Update_Xrecord tbl-name 238    0 0)
  34.  ;         (Update_Xrecord tbl-name  63   18 0) ; cell background color
  35.           (foreach x '(274 275 276 277 278 279); border line weights
  36.             (Update_Xrecord tbl-name x 13 0)   ; data rows
  37.             (Update_Xrecord tbl-name x 50 1)   ; title row
  38.             (Update_Xrecord tbl-name x 30 2)   ; header row
  39.           )
  40.           (foreach x '(64 65 66 67 68 69); border line colors
  41.             (Update_Xrecord tbl-name x 9 0)   ; data   rows            ;   (Update_Xrecord tbl-name 64 6 0)
  42.             (Update_Xrecord tbl-name x 2 1)   ; title  rows
  43.             (Update_Xrecord tbl-name x 2 2)   ; header rows
  44.           )
  45.         )
  46.       )    
  47.     ); defun (Mk-Tbl-Style "SA-Elev-Table") (setq tbl-name "SA-Elev-Table")
  48.  
  49.  

I know the "Update_Xrecord" sub is not here, it is quite long and works flawlessly, I have many other functions that use it without issue, including this one.

Thanks,

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Creating Tables
« Reply #1 on: March 11, 2020, 11:50:24 AM »
A sample table created with the above text is attached.

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Creating Tables
« Reply #2 on: March 11, 2020, 01:48:30 PM »
Update;

I've tried these individually as I'm populating the table, to no avail.

Code - Auto/Visual Lisp: [Select]
  1.  
  2.      (vla-SetText row 0 "Testing") ; Is how the cell fields get populated.
  3.  
  4.      (vla-SetColor SaTable row 0 18)  ; SaTable is table name - row is row# - 0 is column number and 18 is color number
  5.      (vla-SetBackgroundColor SaTable row 0 18)
  6.      (vla-SetCellBackgroundColor SaTable row 0 18)
  7.  
  8.  

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Creating Tables
« Reply #3 on: March 11, 2020, 03:58:14 PM »
Forgive me if I'm misunderstanding but this quick & dirty works for me ...

Code: [Select]
(progn

    (vl-load-com)
   
    (setq
        name "gangnam-style"
        doc  (vla-get-activedocument (vlax-get-acad-object))
        dict (vla-item (vla-get-dictionaries doc) "acad_tablestyle")
        stl  (vla-addobject dict name "AcDbTableStyle")
        clr  (vlax-create-object (strcat "AutoCAD.AcCmColor." (itoa (atoi (getvar 'acadver)))))
    )
   
    ;; red title 
    (vla-setrgb clr 128 0 0)
    (vla-setbackgroundcolor stl acTitleRow clr)

    ;; green header
    (vla-setrgb clr 0 128 0)
    (vla-setbackgroundcolor stl acHeaderRow clr)

    ;; blue data
    (vla-setrgb clr 0 0 128)
    (vla-setbackgroundcolor stl acDataRow clr)

    (princ "voila")
    (princ)   
   
)

Cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Creating Tables
« Reply #4 on: March 11, 2020, 06:38:58 PM »
Thanks MP,

Works like a charm, by making cell backgrounds same as paperspace background color, it looks like there's a wipeout behind table.


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Creating Tables
« Reply #5 on: March 11, 2020, 06:54:53 PM »
Awesome, glad I could contribute. Cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Creating Tables
« Reply #6 on: March 11, 2020, 07:08:08 PM »
O.o
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Creating Tables
« Reply #7 on: March 11, 2020, 07:47:38 PM »
OnSite Water Treatment System -  Technical term for Septic Sytem

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Creating Tables
« Reply #8 on: March 11, 2020, 08:07:30 PM »
lol I should know that - I programmed (PLCs) Water Treatment Plants for over 5 years. :D
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Creating Tables
« Reply #9 on: March 12, 2020, 12:08:16 AM »
PS: If you're setting all cell types to black you should be able to shorten the code to:

Code: [Select]
...

;; all black
(vla-setrgb clr 0 0 0)
(vla-setbackgroundcolor stl (logior acTitleRow acHeaderRow acDataRow) clr)

...

(done from my iPad but should work)

Cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst