Checkout this thread
how do you want to control it exactly?
My thoughts change the background color, but it is a photographic process without law.
(defun c:ChangeBW (/)
(if (= (getvar "Background") 0)
(progn
(setvar "background" 16777215);Color:White
)
(progn
(setvar "background" 0);Color:Black
)
) ; End if
(princ)
)
Of course that doesn’t work. How come you didn’t try the code that is already done for you in the link I provided before?
For example this one called tbk.lsp can Toggle the Background color between Black. & White:
(defun c:tbk(/ ) ;;(prefDisplay) ;;Toggle background
(setq prefDisplay(vla-get-Display(vla-get-Preferences(vlax-get-acad-object))))
(setq color(vlax-variant-value(vlax-variant-change-type
(vla-get-GraphicsWinModelBackgrndColor prefDisplay)vlax-vbLong)))
(vla-put-GraphicsWinModelBackgrndColor prefDisplay
(vlax-make-variant(if(= color 0) 16777215 0) vlax-vbLong))
(princ))
function cycle_bwo_background cycles thru black and white backgrounds in model and paper spaces
(defun cycle_bwo_background ( / display_settings _space back_color)
(if (= "*Paper_Space" (vla-get-name
(vla-get-block
(vla-get-activelayout
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
)
)
)
)
(setq _space "graphicswinlayoutbackgrndcolor")
(setq _space "graphicswinmodelbackgrndcolor")
)
(setq back_color (vlax-variant-value
(vlax-variant-change-type
((eval (read (strcat "vla-get-" _space)))
(setq display_settings
(vla-get-display
(vla-get-preferences
(vlax-get-acad-object)
)
)
)
)
vlax-vbLong
)
)
)
(if (null (eval (read _space)))
(set (read _space) back_color)
(if (and
(/= back_color (eval (read _space)))
(/= 0 back_color)
(/= 16777215 back_color)
)
(set (read _space) back_color)
)
)
(cond
(
(and
(eval (read _space))
(/= 0 back_color)
(/= 16777215 back_color)
)
((eval (read (strcat "vla-put-" _space))) display_settings 0)
)
(
(zerop back_color)
((eval (read (strcat "vla-put-" _space))) display_settings 16777215)
)
(
(and
(= 16777215 back_color)
(/= 0 (eval (read _space)))
(/= 16777215 (eval (read _space)))
)
((eval (read (strcat "vla-put-" _space))) display_settings (eval (read _space)))
)
(
t
(if (= 16777215 back_color)
((eval (read (strcat "vla-put-" _space))) display_settings 0)
((eval (read (strcat "vla-put-" _space))) display_settings 16777215)
)
)
)
(princ)
)
it is already three-faced. the third (other) is one you've set manually and which is different from black or white. in that case function will cycle backgrounds thru black, white and other background. once you set it yellow, it will cycle it too.
or you want to cycle thru black white and yellow in either background setting?
to cycle thru a black, white,and yellow background
;****************************************************************************************************************************************
(defun split_list_nth (_list _nth)
(if (>= _nth 0) (set 'split_before_nth (cons (car _list) (split_list_nth (set 'split_after_nth (cdr _list)) (1- _nth)))))
)
;****************************************************************************************************************************************
(defun cycle_bwy_background ( / display_settings _space back_color split_after_nth split_before_nth _space display_settings back_color)
(if (= "*Paper_Space" (vla-get-name (vla-get-block (vla-get-activelayout (vla-get-ActiveDocument (vlax-get-acad-object))))))
(setq _space "graphicswinlayoutbackgrndcolor")
(setq _space "graphicswinmodelbackgrndcolor")
)
(setq back_color (vlax-variant-value (vlax-variant-change-type ((eval (read (strcat "vla-get-" _space)))
(setq display_settings
(vla-get-display
(vla-get-preferences
(vlax-get-acad-object)
)
)
)
)
vlax-vblong
)
)
cycle_values (if (null cycle_values)
(if (not (member back_color '(0 16777215 65535)))
(list 0 16777215 65535 back_color)
(progn
(split_list_nth '(0 16777215 65535) (vl-position back_color '(0 16777215 65535)))
(append split_after_nth split_before_nth)
)
)
(progn
(setq cycle_values (vl-remove-if-not '(lambda (list_member) (member list_member '(0 16777215 65535))) cycle_values))
(if (not (member back_color cycle_values))
(progn
(split_list_nth cycle_values (vl-position 65535 cycle_values))
(append split_before_nth (list back_color) split_after_nth)
)
cycle_values
)
)
)
)
((eval (read (strcat "vla-put-" _space))) display_settings (car cycle_values))
(setq cycle_values (append (cdr cycle_values) (list (car cycle_values))))
(princ)
)
;****************************************************************************************************************************************
Am I correct that this only works in 2D model space, and it is not possible to make it work in 3D space?
Read up on this thread
OK. Yeah I thought so. Having to close and reopen the drawing is no good for me.
It would be useful to change the background colour on the fly in 3D space (I use point clouds and the background colour greatly effects the visual appearance of the point cloud).
Thanks.