Set Table Cell Color

Set Table Cell Color

DGCSCAD
Collaborator Collaborator
1,261 Views
7 Replies
Message 1 of 8

Set Table Cell Color

DGCSCAD
Collaborator
Collaborator

Hello all,

 

This code snippet will change a given cell BG color to white, but how do I change it to green? I can't sort out where the color code is being defined. The "acm" variable holds: #<VLA-OBJECT IAcadAcCmColor 0000021676ef03a0> and changes each time I run it.

 

How would I set it to Green or Red?

 

(setq acm
                    (vla-getinterfaceobject
                        (vlax-get-acad-object)
                        (strcat "autocad.accmcolor." (substr (getvar 'acadver) 1 2))
                    )
                )
(vla-setcellbackgroundcolor table 2 5 acm)

 

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Accepted solutions (2)
1,262 Views
7 Replies
Replies (7)
Message 2 of 8

komondormrex
Mentor
Mentor
Accepted solution

hey,

try this

(setq acm
    (vla-getinterfaceobject
        (vlax-get-acad-object)
        (strcat "autocad.accmcolor." (substr (getvar 'acadver) 1 2))
    )
)
(vla-put-colorindex acm 1) ;	that's for red
(vla-setcellbackgroundcolor table 2 5 acm)
Message 3 of 8

DGCSCAD
Collaborator
Collaborator

That's exactly what I needed!

 

I almost understand whats happening with VLA things, but a lot of it is over my head at the moment.

 

Thank you so much komondormrex!

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 4 of 8

Sea-Haven
Mentor
Mentor

You can also set RGB colors. Similar sequence.

(setq colObj (vlax-create-object (strcat "AutoCAD.AcCmColor." (substr (getvar "ACADVER") 1 2))))
(vla-setRGB colObj 123 123 123)
(vla-setcolor cuStobj acTitleRow colObj)
0 Likes
Message 5 of 8

DGCSCAD
Collaborator
Collaborator

One more question: What is the color code for "None"?

 

I found "." as a string solution, but need a non-string value.

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 6 of 8

komondormrex
Mentor
Mentor
Accepted solution

check this

 

 

(setq acm (vlax-create-object (strcat "AutoCAD.AcCmColor." (substr (getvar 'acadver) 1 2))))
(vla-put-entitycolor acm -939524096) ; that's colormethod 200, r0g0b0
(vla-setcellbackgroundcolor table 2 5 acm)

 

 

Message 7 of 8

DGCSCAD
Collaborator
Collaborator

Thank you again, komondormrex!

 

 

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 8 of 8

Sea-Haven
Mentor
Mentor

Another. Similar sequence.

 

 

(setq colObj (vlax-create-object (strcat "AutoCAD.AcCmColor." (substr (getvar "ACADVER") 1 2))))

    (vla-setRGB colObj 255 0 0)
    (vla-setcolor cuStobj acTitleRow colObj)

    (vla-setRGB colObj 255 0 255)
    (vla-setcolor cuStobj acHEADERRow colObj)

 

 

0 Likes