Wednesday, March 18, 2009

Change AutoCAD screen background color based on OSNAPZ

I got a request for a program that could have the screen background color change when Z LOCK is on. Here is what it look like in AutoCAD Architecture. “Replace Z value with current elevation” is the button the application status bar.

It is the system variable OSNAPZ that holds this setting. OSNAPZ was introduced in AutoCAD 2006 and with OSNAPZ set to 1 anything you snap to only uses the current elevation as z value. OSNAPZ controls whether object snaps are automatically projected onto a plane parallel to the XY plane of the current UCS at the current elevation

You can download it from here: http://www.jtbworld.com/download/osnapz.LSP

Feel free to make changes to the code to suite your purpose or ask for help to do it.

;;; By Jimmy Bergmark
;;; Copyright (C) 2009 JTB World, All Rights Reserved
;;; Website: www.jtbworld.com
;;; E-mail: info@jtbworld.com
;;; 2009-03-17 - First release
;;; Tested on AutoCAD 2010

;;; changes the background depending on the state of OSNAPZ

; activate the reactor with the (chz) command
; remove the semicolon befor on the last row to automatically activate this upon loading this lisp
; you can load this in each drawing with acaddoc.lsp
; http://www.jtbworld.com/lisp/acaddoc.htm
: background colors can easily be changed below in the code.

(vl-load-com)
(defun chz ()
    (if    (not ct_rea)
    (setq
        ct_rea (vlr-sysvar-reactor
               nil
               '((:vlr-sysVarChanged . reactonosnapz))
           )
    )
    ) 
)

(defun reactonosnapz (event parameter)
    (if (= (car parameter) "OSNAPZ")
      (if (= (cadr parameter) T)
 (if (= (getvar "OSNAPZ") 1)
          (BGGrey)
          (BGWhite)
 )
      )
    )
)

; Set the background in model and paper space to grey
(defun BGGrey ()
  (setq disp (vla-get-display (vla-get-preferences (vlax-get-acad-object))))
  (setq drafting (vla-get-drafting (vla-get-preferences (vlax-get-acad-object))))
  (vla-put-GraphicsWinModelBackgrndColor disp 5987163)
  (vla-put-GraphicsWinLayoutBackgrndColor disp 5987163)
  (vla-put-LayoutCrosshairColor disp 16777215)
  (vla-put-ModelCrosshairColor disp 16777215)
  (vla-put-AutoTrackingVecColor disp 16777215)
  (vla-put-AutoSnapMarkerColor drafting 2)
)

; Set the background in model and paper space to white
(defun BGWhite ()
  (setq disp (vla-get-display (vla-get-preferences (vlax-get-acad-object))))
  (setq drafting (vla-get-drafting (vla-get-preferences (vlax-get-acad-object))))
  (vla-put-GraphicsWinModelBackgrndColor disp 16777215)
  (vla-put-GraphicsWinLayoutBackgrndColor disp 16777215)
  (vla-put-LayoutCrosshairColor disp 0)
  (vla-put-ModelCrosshairColor disp 0)
  (vla-put-AutoTrackingVecColor disp 0)
  (vla-put-AutoSnapMarkerColor drafting 6)
)

; Set the background in model and paper space to black
(defun BGBlack ()
  (setq disp (vla-get-display (vla-get-preferences (vlax-get-acad-object))))
  (setq drafting (vla-get-drafting (vla-get-preferences (vlax-get-acad-object))))
  (vla-put-GraphicsWinModelBackgrndColor disp 0)
  (vla-put-GraphicsWinLayoutBackgrndColor disp 0)
  (vla-put-LayoutCrosshairColor disp 16777215)
  (vla-put-ModelCrosshairColor disp 16777215)
  (vla-put-AutoTrackingVecColor disp 16777215)
  (vla-put-AutoSnapMarkerColor drafting 2)
)

;(chz)

Here is one trick to find out the colors to match exactly your preferences. Change the colors as you want them. Load this code and run the ListColor command.

(defun c:ListColors ()
  (vl-load-com)
  (setq disp (vla-get-display (vla-get-preferences (vlax-get-acad-object))))
  (setq drafting (vla-get-drafting (vla-get-preferences (vlax-get-acad-object))))
  (princ "\nGraphicsWinModelBackgrndColor: ")
  (princ (vlax-variant-value (vlax-variant-change-type (vla-get-GraphicsWinModelBackgrndColor disp) vlax-vbLong)))
  (princ "\nGraphicsWinLayoutBackgrndColor: ")
  (princ (vlax-variant-value (vlax-variant-change-type (vla-get-GraphicsWinLayoutBackgrndColor disp) vlax-vbLong)))
  (princ "\nLayoutCrosshairColor: ")
  (princ (vlax-variant-value (vlax-variant-change-type (vla-get-LayoutCrosshairColor disp) vlax-vbLong)))
  (princ "\nModelCrosshairColor: ")
  (princ (vlax-variant-value (vlax-variant-change-type (vla-get-ModelCrosshairColor disp) vlax-vbLong)))
  (princ "\nAutoTrackingVecColor: ")
  (princ (vlax-variant-value (vlax-variant-change-type (vla-get-AutoTrackingVecColor disp) vlax-vbLong)))
  (princ "\nAutoSnapMarkerColor: ")
  (princ (vla-get-AutoSnapMarkerColor drafting))
  (princ)
)

For more on OSNAPZ usage in AutoCAD Architecture see Beside the Cursor.

You might also like our OsnapzBG freeware.

No comments:

Post a Comment