Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quick Way to Change Background Color 1

Status
Not open for further replies.

idesign73

Mechanical
Sep 25, 2002
28
I am running AutoCAD 14.01 and need a way to quickly change my background color from black to white, and back to black again (without going through all the dialog boxes). Is there a way to change the status of a system variable to edit-able if it is read only (ie: CurrentProfile)? Is there a way to write a lisp routine to go behind the scenes and change that for me with a push of a button. I would like to be able to create two buttons, one for turning the screen white, and one for turning it back to black. Is this do-able?
Thanks!
 
Replies continue below

Recommended for you

Here's a lisp example to change background color, discussed in forum at
---------------------------------------------------

try this..

(setq DisplayObj
(vla-get-Display
(vla-get-Preferences
(vlax-get-acad-object)
)))
(vlax-put-property DisplayObj 'GraphicsWinModelBackgrndColor 131)

(vlax-release-object DisplayObj)


the 131 is your color...so is the value to change if you want..
 
...or You toggle by lisp:

Lothar

(defun C:ToggleColors ()
(cond ((= 1 (getvar "tilemode"))
(ax:ToggleMsBackground)
(ToggleMsCrosshair)
)
((= 0 (getvar "tilemode"))
(ax:TogglePsBackground)
(TogglePsCrosshair)
)
)
(princ)
)
;;
(defun ax:ToggleMSBackground (/ prefDisplay)
(vl-load-com)
(setq
prefDisplay
(vla-get-Display
(vla-get-Preferences (vlax-get-acad-object))
)
color (vlax-variant-value
(vlax-variant-change-type
(vla-get-GraphicsWinModelBackgrndColor prefDisplay)
vlax-vbLong
)
)
)
(vla-put-GraphicsWinModelBackgrndColor
prefDisplay
(vlax-make-variant
(if (= color 0) ; 0 ist schwarz
16777215
0 ; 0 ist schwarz
)
vlax-vbLong
)
)
(princ)
)
;;
(defun ax:TogglePSBackground (/ prefDisplay)
(vl-load-com)
(setq
prefDisplay
(vla-get-Display
(vla-get-Preferences (vlax-get-acad-object))
)
color (vlax-variant-value
(vlax-variant-change-type
(vla-get-GraphicsWinLayoutBackgrndColor prefDisplay)
vlax-vbLong
)
)
)
(vla-put-GraphicsWinLayoutBackgrndColor
prefDisplay
(vlax-make-variant
(if (= color 0) ; wenn er schwarz ist
16777215 ; mach ihn weiß
0 ; mach ihn schwarz
)
vlax-vbLong
)
)
(princ)
)
;;
(defun ToggleMSCrosshair (/ prefDisplay)
(vl-load-com)
(setq
prefDisplay
(vla-get-Display
(vla-get-Preferences (vlax-get-acad-object))
)
color (vlax-variant-value
(vlax-variant-change-type
(vla-get-ModelCrosshairColor prefDisplay)
vlax-vbLong
)
)
)
(vla-put-ModelCrosshairColor
prefDisplay
(vlax-make-variant
(if (= color 0) ; wenn er schwarz ist
16777215 ; mach ihn weiß
0 ; mach ihn schwarz
)
vlax-vbLong
)
)
(princ)
)
(defun TogglePSCrosshair (/ prefDisplay)
(vl-load-com)
(setq
prefDisplay
(vla-get-Display
(vla-get-Preferences (vlax-get-acad-object))
)


color (vlax-variant-value
(vlax-variant-change-type
(vla-get-LayoutCrosshairColor prefDisplay)
vlax-vbLong
)
)
)
(vla-put-LayoutCrosshairColor
prefDisplay
(vlax-make-variant
(if (= color 0) ; wenn er schwarz ist
16777215 ; mach ihn weiß
0 ; mach ihn schwarz
)
vlax-vbLong
)
)
(princ)
)

 
CarlB, I tried copying and pasting the code into Notepad. I saved it as a .lsp file and loaded it into autocad. It loads it, but I get an error:
Command: _appload
Loading C:\colorchange2.lsp ...
Error: null function*Cancel*

Any suggestions?
 
The original poster requested a toggle for AutoCAD 14.01, and I do not have r14 on this computer, but I believe vla-vlax only work in ACAD 2k and up.
Below is a toggle for a black screen with white crosshairs, and vise-versa.

Code:
;;Background color changer 
;;Gary Maze, SMC Corporation of America 
;;11/27/02 
;; 
;;modified by Miklos Fuccaro 
;;mfuccaro@hotmail.com 
;;November 2003 
;;
;; put this in a macro button to toggle screen color:
;; ^C^C(if c:toggle_BackGround_color (princ)(load "toggle_BackGround_color")) toggle_BackGround_color
;;
(defun c:toggle_BackGround_color() 
  (defun wb () ;;white background 
    (setq whitebackground T) 
    (setq acadobject (vlax-get-acad-object)) 
    (setq acadpref (vlax-get-property acadobject 'preferences)) 
    _(setq acaddisp (vlax-get-property acadpref 'display)) 
    _ _ _(vlax-put-property acaddisp 'GraphicsWinmodelBackgrndColor 16777215) 
    _ _ _(vlax-put-property acaddisp 'ModelCrosshairColor 0) 
    ) 

(defun bb () ;; black background 
  (setq whitebackground nil) 
  _(setq acadobject (vlax-get-acad-object)) 
  _(setq acadpref (vlax-get-property acadobject 'preferences)) 
  _(setq acaddisp (vlax-get-property acadpref 'display)) 
  _ (vlax-put-property acaddisp 'GraphicsWinmodelBackgrndColor 0) 
  _ (vlax-put-property acaddisp 'ModelCrosshairColor 16777215) 
  _) 

  (if whitebackground (bb) (wb)) 
  )

Flores
 
I believe smcadman is correct. I have an AutoLisp programming book here, and VL, VLAX is not mentioned anywhere. Does anyone know how to do this without using VL-VLAX?
 
Another way is with environment variables.
To set background to black use (setenv "Background" "0")
and for white (setenv "Background" "16777215"). Note that the variable name is case sensitive. On my machine (using R2002) I had to toggle between modelspace and layout mode for change to take effect, which if needed you could include in the lisp routine/button.
 
The "Background" variable changes just the model space background, so your crosshairs will "disappear" (same color as background). Other variables you'll need:

"Layout background" - background color in layout mode. note the space
"XhairPickboxEtc" - crosshair color in modelspace
"LayoutXhairPickboxEtc" - crosshair color in layout mode
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor