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. Description 🎨 ChangeBackgroundColor is an AutoCAD and Civil 3D AutoLISP utility for changing Model Space, Paper Space, and Block Editor background colors from commands or a DCL dialog. 🖱️ It also adjusts crosshair, AutoTracking vector, and AutoSnap marker colors so the interface remains readable after the background change. Function Syntax 🚀 Command: BG 🚀 Command: BGDCL 🚀 Command: BGGrey 🚀 Command: BGWhite 🚀 Command: BGBlack 🚀 Command: BGT SEO Optimized Overview 🎨 ChangeBackgroundColor is an SEO-friendly AutoCAD background color manager for CAD users who switch between black, white, grey, and custom workspace visibility setups. 🧰 The BGDCL dialog is created dynamically as a temporary DCL file and lets the user apply one global color or assign different colors to Model Space, Paper Space, and Block Editor. 👁️ The routine updates display readability by changing crosshair color, AutoTracking vector color, and AutoSnap marker color according to the selected background. 🧱 Block Editor background is handled through the BEditBackground environment setting using a BGR decimal value, avoiding ARG file patching or registry edits. ↩️ The dialog stores a snapshot of the current colors and restores it if the user cancels. Key Functionalities ✅ Change Model Space background color. ✅ Change Paper Space / Layout background color. ✅ Change Block Editor background color. ✅ Use global color mode or separate colors per space. ✅ Use quick commands for black, white, and grey backgrounds. ✅ Toggle black/white background with BGT. ✅ Automatically adapt crosshair, AutoTracking vector, and AutoSnap marker colors for contrast. ✅ Apply changes live, accept them with OK, or restore the original settings with Cancel. Important AutoLISP / API Calls 🧩 _rgb->long converts RGB values to AutoCAD long color values. 🧩 _rgb->bgr converts RGB long values to BGR values for BEditBackground. 🧩 _snapshot-current records Model Space, Paper Space, Block Editor, crosshair, tracking, and AutoSnap colors before dialog changes. 🧩 _restore-snapshot restores the previous display settings when the dialog is canceled. 🧩 _apply-space applies selected background colors to the chosen drawing spaces. 🧩 _bg-dcl-source and _write-dcl-unique generate the temporary DCL interface. 🧩 _bg-sync-enable enables or disables individual color controls when Global Color is toggled. 🧩 _be-get-bg and _be-put-bg read and write the Block Editor background setting. Result 🎨 The drawing display background is updated for the selected spaces. 👁️ Cursor and drafting marker colors are adjusted to stay visible. ↩️ If the dialog is canceled, the saved color snapshot is restored. 🧹 The temporary DCL file is deleted after the dialog closes. Operational Notes ⚙️ The routine depends on Visual LISP ActiveX access to AutoCAD Preferences Display and Drafting objects. 🧱 Block Editor color uses the BEditBackground environment variable and may depend on the AutoCAD version supporting that setting. 📌 This tool modifies AutoCAD interface preferences, not drawing geometry. Tags 🏷️ AutoCAD, 🏷️ AutoLISP, 🏷️ Civil 3D, 🏷️ Background Color, 🏷️ Model Space, 🏷️ Paper Space, 🏷️ Block Editor, 🏷️ DCL Dialog, 🏷️ CAD UI, 🏷️ BG