Hi
The below comes from an old ACAD Guild post (definitely go with Stig's method) -
Code:
;|
The AutoCAD Display colour number can be calculated with this formula:
RGB value = (blue * 65536) + (green * 256) + red
To change the background colour, one could use the function below. It takes
RGB values, each between 0-255. For example, a pure yellow background would
be: (bgcol 255 255 0), or a black one: (bgcol 0 0 0), or a white one: (bgcol
255 255 255) etc...
By exploring the Display properties, you can change any colour that accepts
the OLE Colours. Reason that it doesn't use pure ActiveX is that an OLE
Colour uses a variant type that is currently unknown to Visual Lisp, so
this is just a shortcut.
Stig Madsen
|;
(defun bgcol (r g b / mycol invcol objtxt)
(mapcar '(lambda (c)
(cond ((< (eval c) 0) (set c 0))
((> (eval c) 255) (set c 255))
)
)
'(r g b)
)
(setq mycol (+ (* b 65536) (* g 256) r)
invcol (+ (* (- 255 b) 65536) (* (- 255 g) 256) (- 255 r))
objtxt "Thisdrawing.application.preferences.Display"
)
(command
"VBASTMT"
(strcat objtxt
".GraphicsWinModelBackgrndColor = "
(itoa mycol)
)
)
(command
"VBASTMT"
(strcat objtxt
".ModelCrossHairColor = "
(itoa invcol)
)
)
)
Code:
;|
Toggles ModelSpace BackGround Colour between Black & White.
Colour values are hard-coded.
Am unhappy in the method I had to adopt to *force* Display to update.
Mike Perry
|;
(defun C:ModelSpaceColour ()
(cond
((= (getvar "TileMode") 0) ;Check Space, Exit if not in ModelSpace
(prompt
"\n***Command only works in ModelSpace, TileMode = 1***"
)
)
((= (getenv "Background") "16777215")
;ModelSpace Background colour = White
(setenv "Background" "0") ;Set ModelSpace Background colour = Black
(setenv "XhairPickboxEtc" "16777215")
;Set ModelSpace Crosshair colour = White
(setvar "TileMode" 0) ;Force Display to update
(setvar "TileMode" 1)
(prompt "\n***ModelSpace Background colour set to Black***")
)
((= (getenv "Background") "0") ;ModelSpace Background colour = Black
(setenv "Background" "16777215") ;Set ModelSpace Background colour = White
(setenv "XhairPickboxEtc" "0") ;Set ModelSpace Crosshair colour = Black
(setvar "TileMode" 0) ;Force Display to update
(setvar "TileMode" 1)
(prompt "\n***ModelSpace Background colour set to White***")
)
(T ;Exit if ModelSpace Background colour /= Black or White
(prompt "\n***ModelSpace Background colour not altered***")
)
)
(princ)
)
Have a good one, Mike