×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Quick Way to Change Background Color

Quick Way to Change Background Color

Quick Way to Change Background Color

(OP)
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!

RE: Quick Way to Change Background Color

Here's a lisp example to change background color, discussed in forum at http://www.cadalog.com/phpbb2/viewtopic.php?t=15692&sta....

---------------------------------------------------

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..

RE: Quick Way to Change Background Color

...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)
)

RE: Quick Way to Change Background Color

(OP)
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?

RE: Quick Way to Change Background Color

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.  

;;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

RE: Quick Way to Change Background Color

(OP)
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?

RE: Quick Way to Change Background Color

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.

RE: Quick Way to Change Background Color

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources