The following snippit of code is changeing the color of text in a cell of an AcadTable. It will set the color to an RGB value and works great. But what if the color is a normal color 1 through 255 from autocad's pen table. How would I set the cell text color?
(setq objColor (vla-getcellcontentcolor eVLAMT R C)) ;sets a Color Object, whatever that is
(vla-setrgb objColor RED GRN BLU) ;sets the new color of the Color Object
(vla-setcellcontentcolor eVLAMT R C objColor) ;sets that new color object to the cell
@estiles wrote:The following snippit of code is changeing the color of text in a cell of an AcadTable. It will set the color to an RGB value and works great. But what if the color is a normal color 1 through 255 from autocad's pen table. How would I set the cell text color?
(setq objColor (vla-getcellcontentcolor eVLAMT R C)) ;sets a Color Object, whatever that is
(vla-setrgb objColor RED GRN BLU) ;sets the new color of the Color Object
(vla-setcellcontentcolor eVLAMT R C objColor) ;sets that new color object to the cell
Use this:
;; ACI -> RGB - Lee Mac 2011 ;; Args: c - ACI (AutoCAD Colour Index) Colour (defun LM:ACI->RGB ( c / cObj rgb ) (vl-load-com) (if (and (<= 1 c 255) (setq cObj (vla-getInterfaceObject (vlax-get-acad-object) (strcat "AutoCAD.AcCmColor." (substr (getvar 'ACADVER) 1 2)) ) ) (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-put-ColorIndex (list cObj c)) ) ) ) (setq rgb (list (vla-get-Red cObj) (vla-get-Green cObj) (vla-get-Blue cObj))) ) (if cObj (vlax-release-object cObj)) rgb )
Converts "normal color" to RGB
(LM:ACI->RGB 45)
(153 133 76)
(LM:ACI->RGB 223)
(204 102 178)
(LM:ACI->RGB 7)
(255 255 255)
HTH
Wow that was a fast reply. Thanks, that does work. I still would like for the user to be able to set the color to 1 or 256 (bylayer or byblock) but until I figure that out this will make my program usefull.
@estiles wrote:Wow that was a fast reply. Thanks, that does work. I still would like for the user to be able to set the color to 1 or 256 (bylayer or byblock) but until I figure that out this will make my program usefull.
Glad it worked for you
Kudos to Lee Mac for the color conversion routine
Thanks pBe
Here is the full set:
Here is an example for you to study:
(defun c:test ( / *error* _ss->lst _hit-test accmobj col lst pt sel vd ) ;;---------------------------------------------;; ;; Example by Lee Mac 2011 - www.lee-mac.com ;; ;;---------------------------------------------;; (defun *error* ( msg ) (if (and AcCmObj (not (vlax-object-released-p AcCmObj))) (vlax-release-object AcCmObj) ) (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")) (princ (strcat "\nError: " msg)) ) (princ) ) (defun _ss->lst ( ss / i lst ) (if ss (repeat (setq i (sslength ss)) (setq lst (cons (vlax-ename->vla-object (ssname ss (setq i (1- i)))) lst)) ) ) ) (defun _hit-test ( pt lst / vd ) (setq pt (vlax-3D-point (trans pt 1 0)) vd (vlax-3D-point (trans (getvar 'VIEWDIR) 1 0)) ) (vl-some (function (lambda ( obj / row col ) (if (eq :vlax-true (vla-hittest obj pt vd 'row 'col)) (list obj row col) ) ) ) lst ) ) (cond ( (null (setq sel (_ss->lst (ssget "_X" (list '(0 . "ACAD_TABLE") (cons 410 (if (= 1 (getvar 'CVPORT)) (getvar 'CTAB) "Model")) ) ) ) ) ) (princ "\nNo Tables found in Drawing.") ) ( (null (setq col (acad_colordlg 1))) (princ "\n*Cancel*") ) ( t (setq AcCmObj (vla-getInterfaceObject (vlax-get-acad-object) (strcat "AutoCAD.AcCmColor." (substr (getvar 'ACADVER) 1 2)) ) ) (vla-put-colorindex AcCmObj col) (while (setq pt (getpoint "\nPick Cell to Change Colour: ")) (if (setq lst (_hit-test pt sel)) (apply 'vla-setcellcontentcolor (append lst (list AcCmObj))) (princ "\nNo Table Cell Found.") ) ) (vlax-release-object AcCmObj) ) ) (princ) ) (vl-load-com) (princ)