Function Syntax: BG Version: 1 Date: 08.09.2025 AI+https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-change-background-colour-not-working/td-p/11673817 AI+https://www.theswamp.org/index.php?topic=47337.0 Command names • BGDCL (type BGDCL at the AutoCAD command line) • BG (type BG at the AutoCAD command line, alias for BGDCL) • BGGrey (type BGGrey for quick gray 91,91,91) • BGWhite (type BGWhite for quick white) • BGBlack (type BGBlack for quick black) • bgt (type bgt to toggle Model space background black and white) Description This program changes AutoCAD display colors by setting the Model space and Paper space background colors, and also sets related UI colors such as crosshair, auto-tracking vector, and autosnap marker color to maintain contrast. It includes a dialog-based UI with Apply and Cancel behavior that can restore the previous settings. Main purpose • Quickly apply consistent background presets (black, white, and multiple gray shades) without manually editing Options settings. • Automatically adjust cursor and tracking colors for readability on light or dark backgrounds. Prerequisites • Requires Visual LISP COM support via (vl-load-com). • Uses AutoCAD Preferences objects via ActiveX, so the drawing session must support the Display and Drafting preference interfaces. • Requires permission to write a temporary DCL file for the dialog created by vl-filename-mktemp. User interaction • The dialog command BGDCL opens a DCL dialog titled Background Changer. • The user chooses: • A preset background color from a dropdown list. • Where to apply it via toggles: Model space. Paper space. • Buttons: Apply applies changes but keeps the dialog open. OK applies changes and closes the dialog. Cancel closes the dialog and restores the pre-dialog snapshot of settings. High-level workflow • Defines a palette of preset colors (black, white, and several gray values) stored as AutoCAD LONG RGB values. • On opening the dialog, captures a snapshot of current display and drafting colors so Cancel can revert. • Writes the dialog DCL source to a temp file and loads it. • When applying a selection, sets: • Model background color and Model crosshair color (if Model is enabled). • Paper background color and Layout crosshair color (if Paper is enabled). • AutoTracking vector color. • AutoSnap marker color (changes depending on light or dark background). • On Cancel, restores all snapshot values (backgrounds, crosshairs, tracking color, and snap marker). Functionalities • Dialog-based background management with Apply and Cancel restore. • Preset dropdown supports: Black and White. • Multiple gray shades including Gray 91,91,91 plus additional increments. • Applies to Model space, Paper space, or both. • Automatically sets cursor and tracking colors based on background contrast: • Dark backgrounds get a white crosshair and tracking vector. • Light backgrounds get a black crosshair and tracking vector. • Automatically sets AutoSnap marker color: • Light backgrounds use color 6 (yellow). • Dark backgrounds use color 2 (red). Quick commands BGGrey sets both Model and Paper background to Gray 91,91,91 and sets cursor and tracking to white with red autosnap markers. BGWhite sets both backgrounds to white and sets cursor and tracking to black with yellow autosnap markers. BGBlack sets both backgrounds to black and sets cursor and tracking to white with red autosnap markers. bgt toggles Model space background between black and white based on the current Model background value. Important commands and calls highlighted _pref-display and _pref-drafting — access the Preferences Display and Drafting objects. vla-put-GraphicsWinModelBackgrndColor and vla-put-GraphicsWinLayoutBackgrndColor — set Model and Layout background colors. vla-put-ModelCrosshairColor and vla-put-LayoutCrosshairColor — set crosshair colors. vla-put-AutoTrackingVecColor — sets tracking vector color. vla-put-AutoSnapMarkerColor — sets autosnap marker color. _snapshot-current and _restore-snapshot — snapshot and restore settings for Cancel behavior. _apply-bg — central apply routine that chooses contrast colors and applies changes to Model and Paper. vl-filename-mktemp and load_dialog — write and load the temporary DCL UI. Outputs and messages • If both Model and Paper toggles are off and Apply or OK is pressed: alerts Nothing to apply. • If the dialog fails to open: alerts Failed to open dialog. • No explicit success message is printed for Apply or OK; the changes are visible immediately in the graphics window. Operational notes and limitations • This changes user profile display preferences, not just a single drawing setting, so the effect is global for the current AutoCAD profile and session. • Cancel restores only the snapshot captured when the dialog opened; if other tools change these preferences while the dialog is open, Cancel will revert them to the snapshot values. • The bgt command checks only the Model background value to decide black or white toggle behavior. • AutoSnap marker color is chosen using a threshold based on white intensity; the exact threshold is approximate and may not match every user preference.