3dwannab Posted Tuesday at 12:51 PM Posted Tuesday at 12:51 PM Hi all, Here's a function that doesn't work to set the plot styles for all open drawings. Is there something I'm missing? (defun set-pstyles (showBool / app docs orgDoc) (setq showBool (if showBool :vlax-true :vlax-false)) (setq app (vlax-get-acad-object)) (setq docs (vla-get-Documents app)) (setq orgDoc (vla-get-ActiveDocument app)) ; store the original (vlax-for d docs (vla-Activate d) (vla-put-ShowPlotStyles (vla-get-ActiveLayout d) showBool) (vla-Regen d acActiveViewport) ) (vla-Activate orgDoc) ) (set-pstyles T) ; (set-pstyles nil) Quote
Steven P Posted Tuesday at 02:51 PM Posted Tuesday at 02:51 PM So where is it going wrong? Is it switching between drawings or just switching to one drawing and then stopping? Quote
mhupp Posted Tuesday at 07:25 PM Posted Tuesday at 07:25 PM 6 hours ago, 3dwannab said: Is there something I'm missing? AutoCAD doesn't like multiple drawings. you will either have to do scripts or maybe vl-propagate ? 1 Quote
3dwannab Posted Tuesday at 10:56 PM Author Posted Tuesday at 10:56 PM 3 hours ago, mhupp said: AutoCAD doesn't like multiple drawings. you will either have to do scripts or maybe vl-propagate ? Thanks @mhupp, I'll try that once I finish work tomorrow. @Steven P, when I replaced the vla-put-ShowPlotStyles with just a (princ "test') I think it only done the current doc. Will test tomorrow. 1 Quote
3dwannab Posted Wednesday at 08:35 PM Author Posted Wednesday at 08:35 PM I've tried this and it's still the same. ;; Define a safe toggle function (defun-q my-pstyle-toggle (doc state / layout) (setq layout (vla-get-ActiveLayout doc)) (vla-put-ShowPlotStyles layout (if state :vlax-true :vlax-false)) (vla-Regen doc acActiveViewport) ) ;; Make sure all drawings know about it (vl-propagate 'my-pstyle-toggle) ;; Apply it to all open documents (defun c:AllDocsPstyleOn (/ app docs) (setq app (vlax-get-acad-object) docs (vla-get-Documents app) ) (vlax-for d docs (my-pstyle-toggle d T) ;; pass :vlax-true ) (princ "\nPlot styles ON for all open drawings.") (princ) ) (defun c:AllDocsPstyleOff (/ app docs) (setq app (vlax-get-acad-object) docs (vla-get-Documents app) ) (vlax-for d docs (my-pstyle-toggle d nil) ;; pass :vlax-false ) (princ "\nPlot styles OFF for all open drawings.") (princ) ) @Steven P, it's switching drawings alright. Just not toggling the plotstyles. Quote
3dwannab Posted Wednesday at 08:43 PM Author Posted Wednesday at 08:43 PM Even this simple example doesn't work. ; TILEMODE_MODEL (defun-q RUNTILEMODE_MODEL () (command ".TILEMODE" "1") (princ) ) (vl-propagate 'RUNTILEMODE_MODEL) (defun c:test (/ app docs) (setq app (vlax-get-acad-object) docs (vla-get-Documents app) ) (vlax-for d docs (RUNTILEMODE_MODEL) ) (princ "\nAll drawings set to model space.") (princ) ) Quote
Steven P Posted Wednesday at 09:45 PM Posted Wednesday at 09:45 PM 1 hour ago, 3dwannab said: @Steven P, it's switching drawings alright. Just not toggling the plotstyles. Yup, that sounds about right... LISP generally cannot perform a function on another open drawing. In MHUPPs link Lee Mac explains it in there. The only way I've found you can do it is to make a script for example in Lee Macs Script Write or in Script Writer Pro and use that - the drawings have to be closed though 1 Quote
BIGAL Posted Wednesday at 10:44 PM Posted Wednesday at 10:44 PM You can get a list of currently open documents and change to any of those documents. But your lisp will stop. Not sure and have mot tested using a script with this method. The one thing you must do is re do the current document list each time you change dwg. (defun openblk (blkname / adocs) (setq acDocs (vla-get-documents (vlax-get-acad-object))) (vla-open acDocs blkname) (vla-activate (vla-item acdocs 1)) ) You could load the lisp and run for each dwg name. have a look at 1st line each item inside acdocs for dwg names. Then write a script. script maybe (load "openblk") (openblk "dwg1") ; do your thing Save Close (load "openblk") (openblk "dwg2") ; do your thing Save Close and so on Example (vlax-get (vla-item acdocs 1) 'name) = "section.dwg" the acdoc has property "Count" so know how many dwgs are open. Quote
mhupp Posted Wednesday at 11:00 PM Posted Wednesday at 11:00 PM (edited) That's not how vl-propagate works. it only passes variable and its value between all open drawings. here is how i used it passing VC and SZ between all open drawings. once ZAD is run in one drawing any other drawing you run ZAD in will zoom to the same xy location. it was good to look at old revisions. ;;----------------------------------------------------------------------------;; ;; Zoom Area Across Multiple Drawings (defun C:ZAD (/ a) (initget "Yes No") (setq a (cond ((getkword "\nRedefine Zoom Area? [Yes/No]: ")) ("No") ) ) (if (= "Yes" a) (progn (vl-cmdf "_.Zoom" "W" Pause Pause) (setq vc (getvar 'viewctr)) (setq SZ (getvar 'viewsize)) (vl-propagate 'vc) (vl-propagate 'sz) ) (if (or (= vc nil) (= sz nil)) (prompt "\nPlease Define Zoom Area") (vl-cmdf "_.Zoom" "C" VC SZ) ) ) (princ) ) like i said AutoCAD doesn't like to run one lisp across multiple open drawings. but its been awhile since iv used it. Maybe this would work? -- edit oops didn't hit post Edited Wednesday at 11:02 PM by mhupp 1 Quote
3dwannab Posted Wednesday at 11:02 PM Author Posted Wednesday at 11:02 PM I do know of this prograam that was on the swamp by MP over there. https://www.theswamp.org/index.php?topic=53912.msg586779#msg586779 Just thought that (vlax-for d (vla-get-Documents (vlax-get-acad-object)) would work for this. Quote
3dwannab Posted Wednesday at 11:06 PM Author Posted Wednesday at 11:06 PM (edited) 8 minutes ago, mhupp said: That's not how vl-propagate works This thread for RunAll by MP on the swamp wrote this. Quote Did you know ... AutoCAD will not let you use vl-propagate on functions or commands defined via defun? For example: (defun foo ( ) (princ "\nHi from foo.") (princ)) >> FOO (vl-propagate 'foo) >> (error "Visual LISP: Illegal inter-doc import/export object" #<SUBR @000000002c4dbc00 FOO>) However you can side step this limitation if you define the function via setq or defun-q (merely a wrapper for setq): (setq foo '(( ) (princ "\nHi from foo.") (princ))) >> (nil (PRINC "\nHi from foo.") (PRINC)) or (defun-q foo ( ) (princ "\nHi from foo.") (princ)) >> FOO (vl-propagate 'foo) >> (nil (PRINC "\nHi from foo.") (PRINC)) Which you could then pass to _RunAll: (_RunAll "(foo)") >> RunAll: CMD string "(FOO)" attempted in 2 docs: 1.44 secs (0.12 secs/doc). @BIGAL, that RunAll utility will process all open drawings without having to write a script. Edited Wednesday at 11:09 PM by 3dwannab Quote
3dwannab Posted Wednesday at 11:09 PM Author Posted Wednesday at 11:09 PM (edited) double post deleted. Edited Wednesday at 11:10 PM by 3dwannab Quote
mhupp Posted Wednesday at 11:11 PM Posted Wednesday at 11:11 PM 4 minutes ago, 3dwannab said: This thread for RunAll by MP on the swamp wrote this. shurg. Quote
3dwannab Posted Wednesday at 11:31 PM Author Posted Wednesday at 11:31 PM (edited) 20 minutes ago, mhupp said: shurg. Why shurg? Sorry if you're MP over on there. It can pass defun if they're done like so with defun-q: (defun-q foo ( ) (command "tilemode" 1) (princ)) (vl-propagate 'foo) The running (foo) in the other open drawings will set them to model space. So this is where I was hoping that my code earlier would work. Edited Wednesday at 11:31 PM by 3dwannab Quote
3dwannab Posted Wednesday at 11:46 PM Author Posted Wednesday at 11:46 PM (edited) Here's the program I have now. It requires the RunAll Utility found here: https://www.theswamp.org/index.php?topic=53912 ;; ;; ToggleDisplayColour.lsp ;; ;; Author: 3dwannab + others ;; ;; Version History: ;; v1.0 - 2024-06-11: Initial version. Updated to change the grid colours depending on if the background is black or white. ;; v1.1 - 2025.06.16: Updated to change the grid colours depending on if the background is black or white. ;; v1.2 - 2025.09.04: Updated to set the plot styles display on all open documents with the help of RunAll Utility found here: https://www.theswamp.org/index.php?topic=53912 ;; ;; What this does: ;; - Toggles the AutoCAD background colour between black and white in the current space (model or layout). ;; - If the background is white the plot styles display, if black they don't. ;; - Updates grid colours to suit the background and toggles plot style display. ;; - No effect on the block editor. Refreshes DWG to display correctly. ;; ;; NOTES: ;; - Toggling doesn't work when running the command inside the block editor. Not much I think I can do about ;; apart from perhaps implementing this https://forums.autodesk.com/t5/net-forum/change-the-block-editor-background-color-at-runtime/td-p/9831561. ;; ;; TO DO: ;; – NA ;; (vl-load-com) ;; Converts RGB values to AutoCAD decimal color value (defun rgb-to-dec (r g b) (+ r (* g 256) (* b 65536)) ) ;; Helper to extract RGB from decimal color (defun dec-to-rgb (dec / r g b) (setq r (rem dec 256)) (setq g (rem (/ dec 256) 256)) (setq b (rem (/ dec 65536) 256)) (list r g b) ) ;; Helper to compute brightness (perceived luminance) (defun color-brightness (dec / rgb) (setq rgb (dec-to-rgb dec)) (+ (* 0.299 (float (car rgb))) (* 0.587 (float (cadr rgb))) (* 0.114 (float (caddr rgb))) ) ) ;------------------------------------------------------- ; rm:displayplotstyles ; 04/03/10 ruul at ctr.co.at ; nomen est omen - toggles display of plot styles... ;------------------------------------------------------- ; Updated 110208 by Mike Sweeney ; (defun rm:displayplotstyles (bshow ball / acdoc bvshow layout layouts) (princ "\nDisplay plot styles ") (vl-load-com) (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object))) (setq layouts (vla-get-layouts acdoc)) (setq bvshow (if bshow :vlax-true :vlax-false)) (princ (if bshow "ON" "OFF")) (cond (ball (vlax-for layout layouts (if (/= (vla-get-name layout) "Model") (vla-put-ShowPlotStyles layout bvshow) ) ) (princ " in all layouts\n") ) (T (setq layout (vla-get-ActiveLayout acdoc)) (vla-put-ShowPlotStyles layout bvshow) (princ " in current layout\n") ) ) (vla-regen acdoc acactiveviewport) (princ) ) ;; Returns T if the background is white (defun isWhiteBackground (/ bgColorDark bkColorLight cur inBlockEditor pref previousColLight previousColor tilemde) ;; Assign cur depending on tilemode (setq pref (vla-get-display (vla-get-Preferences (vlax-get-acad-object)))) (setq tilemde (getvar "tilemode")) (if (= tilemde 1) (setq cur (vla-get-GraphicsWinModelBackgrndColor pref)) (setq cur (vla-get-GraphicsWinLayoutBackgrndColor pref)) ) ;; Set up the dark and light colours to toggle (setq bgColorDark (rgb-to-dec 0 0 0)) (setq bkColorLight (rgb-to-dec 255 255 255)) (setq previousColLight bkColorLight) ; for compatibility with existing code ;; Get current background color (setq inBlockEditor (= (getvar "BLOCKEDITOR") 1)) (if inBlockEditor (setq previousColor (atoi (getenv "BEditBackground"))) (setq previousColor (vlax-variant-value (vlax-variant-change-type cur vlax-vblong))) ) ;; Decide if we need to switch to light or dark based on current colour (cond ((= previousColor bgColorDark) T) ; If currently dark, switch to light ((= previousColor bkColorLight) nil) ; If currently light, switch to dark (T ; Fallback: use brightness as before (> (color-brightness previousColor) (/ (+ (color-brightness bgColorDark) (color-brightness bkColorLight)) 2.0) ) ) ) ) ;; Toggles the display from black to white ;; If black the plot styles are not shown ;; If white the plot styles are shown (defun c:TG (/ bgColorDark bkColorLight doc gridcol-major gridcol-minor gridcolDarkMajor gridcolDarkMinor gridcolLightMajor gridcolLightMinor inBlockEditor pref previousColLight tilemde whiteBackground) (setq doc (vla-get-activedocument (vlax-get-acad-object))) ;; Define grid color lists (setq gridcolLightMajor (rgb-to-dec 100 200 200)) (setq gridcolLightMinor (rgb-to-dec 240 240 240)) (setq gridcolDarkMajor (rgb-to-dec 10 60 60)) (setq gridcolDarkMinor (rgb-to-dec 35 35 35)) ;; Assign cur depending on tilemode (setq pref (vla-get-display (vla-get-Preferences (vlax-get-acad-object)))) (setq tilemde (getvar "tilemode")) ;; Set up the dark and light colours to toggle (setq bgColorDark (rgb-to-dec 0 0 0)) (setq bkColorLight (rgb-to-dec 255 255 255)) ; (setq previousColLight bkColorLight) ; for compatibility with existing code ;; Get current background color (setq inBlockEditor (= (getvar "BLOCKEDITOR") 1)) (setq whiteBackground (isWhiteBackground)) ;; Set grid colors based on background (if whiteBackground ;; Was light or lighter background, so toggle to dark background (progn (setq gridcol-major gridcolLightMajor) (setq gridcol-minor gridcolLightMinor) ) ;; Was dark or darker background, so toggle to light background (progn (setq gridcol-major gridcolDarkMajor) (setq gridcol-minor gridcolDarkMinor) ) ) ;; Model space and Block Editor (if (not (zerop tilemde)) ; Model space (progn ;; Toggle background color for model space (if (not inBlockEditor) (progn (vla-put-GraphicsWinModelBackgrndColor pref (vlax-make-variant (if whiteBackground bkColorLight bgColorDark) vlax-vblong)) (setenv "2D Model grid major lines color" (itoa gridcol-major)) (setenv "2D Model grid minor lines color" (itoa gridcol-minor)) ) ) ;; Toggle Block Editor background color in registry (if inBlockEditor (progn ; (setenv "BEditBackground" (itoa (if whiteBackground bgColorDark previousColLight))) ; (setenv "BEdit grid major lines color" (itoa gridcol-major)) ; (setenv "BEdit grid minor lines color" (itoa gridcol-minor)) (alert "\nNote:\nBackground cannot be updated inside the block editor\n") ) ) ) ;; progn - Model space ;; Paper space (Layout) (progn (vla-put-GraphicsWinLayoutBackgrndColor pref (vlax-make-variant (if whiteBackground bkColorLight bgColorDark) vlax-vblong)) (setenv "Layout grid major lines color" (itoa gridcol-major)) (setenv "Layout grid minor lines color" (itoa gridcol-minor)) ) ;; progn - Paper space ) ;; Toggle plot styles in paper space (if (not inBlockEditor) (progn (if whiteBackground ;; Toggles all open docs to display correctly (_RunAll "(rm:displayplotstyles t nil)") ;; Turn on display of plot styles with external RunAll Ultity found here: https://www.theswamp.org/index.php?topic=53912 (_RunAll "(rm:displayplotstyles nil nil)") ;; Turn off display of plot styles with external RunAll Ultity found here: https://www.theswamp.org/index.php?topic=53912 ;; Old code that doesn't toggle the plot styles on all open drawings ; (rm:displayplotstyles t nil) ;; Turn on display of plot styles ; (rm:displayplotstyles nil nil) ;; Turn off display of plot styles ) ) ) (vlax-release-object pref) (princ) ) ; (c:TG) ;; Unblock for testing Edited Wednesday at 11:48 PM by 3dwannab 1 Quote
mhupp Posted 23 hours ago Posted 23 hours ago interesting I only used VBA to call a single command at a time from excel. Quote - Toggling doesn't work when running the command inside the block editor. Not much I think I can do about Test if your in blockeditor (getvar 'BLOCKEDITOR) Quote
rlx Posted 11 hours ago Posted 11 hours ago I really haven't tested this : ;;; setvar on allopen (defun c:soa ( / aod var val) (vlax-for doc (vla-get-documents (vlax-get-acad-object))(setq aod (cons doc aod))) (setq var "ORTHOMODE" val (vlax-make-variant 0 vlax-vbInteger))(foreach doc aod (vla-SetVariable doc var val))) ;;; or with save (defun c:soas ( / aod var val) (vlax-for doc (vla-get-documents (vlax-get-acad-object))(setq aod (cons doc aod))) (setq var "ORTHOMODE" val (vlax-make-variant 0 vlax-vbInteger)) (foreach doc aod (vla-SetVariable doc var val)(vl-catch-all-apply 'vla-saveas (list doc (vla-get-fullname doc))))) ;;; show allopen plotstyle (defun c:saps ()(vlax-for d (vla-get-documents (vlax-get-acad-object))(vlax-for l (vla-get-layouts d) (if (not (eq (vla-get-name l) "Model")) (vlax-put-property l 'ShowPlotStyles :vlax-true))))) ;;; hide allopen plotstyle (defun c:haps ()(vlax-for d (vla-get-documents (vlax-get-acad-object))(vlax-for l (vla-get-layouts d) (if (not (eq (vla-get-name l) "Model")) (vlax-put-property l 'ShowPlotStyles :vlax-false))))) 1 Quote
3dwannab Posted 2 hours ago Author Posted 2 hours ago 20 hours ago, mhupp said: Test if your in blockeditor (getvar 'BLOCKEDITOR) It's this line that's the issue. It doesn't automatically stick. (setenv "BEditBackground" (itoa (if whiteBackground bgColorDark previousColLight))) Brilliant @rlx, I knew there was a way. vla-get-Layouts is the key. Thank you so much. Here's a defun for anyone wanting complete control over their plot styles. ;; ;; ShowPlotStyles ;; Written by 3dwannab on 2025.09.04 with the help of rlx ;; https://www.cadtutor.net/forum/topic/98675-change-plotstyles-display-on-all-currently-open-docs/#findComment-676027 ;; ------------------ ;; Toggles Plot Style display (ON/OFF) at three levels of scope: ;; scope = 0 → current layout only ;; scope = 1 → all layouts in current drawing ;; scope = 2 → all layouts in all open drawings ;; ;; Usage examples: ;; (ShowPlotStyles :vlax-true 0) ;; ON, current layout only ;; (ShowPlotStyles :vlax-false 1) ;; OFF, all layouts in current drawing ;; (ShowPlotStyles :vlax-true 2) ;; ON, all layouts in all open drawings ;; (defun ShowPlotStyles (showBool scope / doc lay msg var_cmdecho) ;; scope: 0 = current layout, 1 = all layouts in current drawing, 2 = all layouts in all open drawings (setq var_cmdecho (getvar 'cmdecho)) (setvar 'cmdecho 0) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (cond ;; Case 0: Current layout only ((= scope 0) (setq lay (vla-get-ActiveLayout doc)) (vla-put-ShowPlotStyles lay showBool) (setq msg (strcat "Plot Styles " (if (= showBool :vlax-true) "'ON'" "'OFF'") " for current layout only...")) (vla-Regen doc acActiveViewport) ) ;; Case 1: All layouts in current drawing ((= scope 1) (vlax-for l (vla-get-Layouts doc) (vla-put-ShowPlotStyles l showBool) ) (setq msg (strcat "Plot Styles " (if (= showBool :vlax-true) "'ON'" "'OFF'") " for all layouts in current drawing...")) (vla-Regen doc acActiveViewport) ) ;; Case 2: All layouts in all open drawings ((= scope 2) (vlax-for d (vla-get-Documents (vlax-get-Acad-Object)) (vlax-for l (vla-get-Layouts d) (vla-put-ShowPlotStyles l showBool) ) (vla-Regen d acActiveViewport) ) (setq msg (strcat "Plot Styles " (if (= showBool :vlax-true) "'ON'" "'OFF'") " for all layouts in all open drawings...")) ) ) (setvar 'cmdecho var_cmdecho) ;; Comment this out if you want silent behaviour (princ (strcat "\n" msg)) (princ) ) Quote
3dwannab Posted 2 hours ago Author Posted 2 hours ago Updated program for toggling the display colour between white (plot styles on) and black (plot styles off). Thanks once again @rlx (vl-load-com) ;; ;; ToggleDisplayColour.lsp ;; ;; Author: 3dwannab + rlx ;; ;; Version History: ;; v1.0 - 2024.06.11: Initial version. Added background toggle + grid colour sync. ;; v1.1 - 2025.06.16: Improved grid colour handling for black/white backgrounds. ;; v1.2 - 2025.09.04: Added ability to set plot styles display across all open drawings ;; (using RunAll Utility concept). ;; v1.2a - 2025.09.05: Refined ShowPlotStyles to iterate over open drawings directly ;; with rlxs' help . Ref: https://www.cadtutor.net/forum/topic/98675 ;; ;; What this does: ;; - Toggles the AutoCAD background colour between black and white in the current space (model/layout). ;; - Updates grid colours to match the chosen background (light or dark theme). ;; - Toggles the visibility of plot styles (ShowPlotStyles) depending on background colour: ;; * Black background → Plot styles OFF ;; * White background → Plot styles ON ;; - Can update plot style visibility for: ;; * Current layout only ;; * All layouts in the current drawing ;; * All layouts in all currently open drawings ;; - Refreshes drawings to display changes immediately. ;; - Skips background toggle if running inside the Block Editor (with a note). ;; ;; NOTES: ;; - Background colour cannot be toggled while inside the Block Editor ;; (AutoCAD limitation – possible workaround noted here: ;; https://forums.autodesk.com/t5/net-forum/change-the-block-editor-background-color-at-runtime/td-p/9831561). ;; ;; TO DO: ;; - Currently none. ;; ;;------------------------------------------------------- ;; HELPER FUNCTIONS START ;;------------------------------------------------------- ;; Converts RGB values to AutoCAD decimal color value (defun rgb-to-dec (r g b) (+ r (* g 256) (* b 65536)) ) ;; Helper to extract RGB from decimal color (defun dec-to-rgb (dec / r g b) (setq r (rem dec 256)) (setq g (rem (/ dec 256) 256)) (setq b (rem (/ dec 65536) 256)) (list r g b) ) ;; Helper to compute brightness (perceived luminance) (defun color-brightness (dec / rgb) (setq rgb (dec-to-rgb dec)) (+ (* 0.299 (float (car rgb))) (* 0.587 (float (cadr rgb))) (* 0.114 (float (caddr rgb))) ) ) ;; ;; ShowPlotStyles ;; Written by 3dwannab on 2025.09.04 with the help of rlx ;; https://www.cadtutor.net/forum/topic/98675-change-plotstyles-display-on-all-currently-open-docs/#findComment-676027 ;; ------------------ ;; Toggles Plot Style display (ON/OFF) at three levels of scope: ;; scope = 0 → current layout only ;; scope = 1 → all layouts in current drawing ;; scope = 2 → all layouts in all open drawings ;; ;; Usage examples: ;; (ShowPlotStyles :vlax-true 0) ;; Plot styles ON, current layout only ;; (ShowPlotStyles :vlax-false 1) ;; Plot styles OFF, all layouts in current drawing ;; (ShowPlotStyles :vlax-true 2) ;; Plot styles ON, all layouts in all open drawings ;; (defun ShowPlotStyles (showBool scope / doc lay msg var_cmdecho) ;; scope: 0 = current layout, 1 = all layouts in current drawing, 2 = all layouts in all open drawings (setq var_cmdecho (getvar 'cmdecho)) (setvar 'cmdecho 0) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (cond ;; Case 0: Current layout only ((= scope 0) (setq lay (vla-get-ActiveLayout doc)) (vla-put-ShowPlotStyles lay showBool) (setq msg (strcat "Plot Styles " (if (= showBool :vlax-true) "'ON'" "'OFF'") " for current layout only...")) (vla-Regen doc acActiveViewport) ) ;; Case 1: All layouts in current drawing ((= scope 1) (vlax-for l (vla-get-Layouts doc) (vla-put-ShowPlotStyles l showBool) ) (setq msg (strcat "Plot Styles " (if (= showBool :vlax-true) "'ON'" "'OFF'") " for all layouts in current drawing...")) (vla-Regen doc acActiveViewport) ) ;; Case 2: All layouts in all open drawings ((= scope 2) (vlax-for d (vla-get-Documents (vlax-get-Acad-Object)) (vlax-for l (vla-get-Layouts d) (vla-put-ShowPlotStyles l showBool) ) (vla-Regen d acActiveViewport) ) (setq msg (strcat "Plot Styles " (if (= showBool :vlax-true) "'ON'" "'OFF'") " for all layouts in all open drawings...")) ) ) (setvar 'cmdecho var_cmdecho) ;; Comment this out if you want silent behaviour (princ (strcat "\n" msg)) (princ) ) ;; Returns T if the background is white (defun isWhiteBackground (/ bgColorDark bkColorLight cur inBlockEditor pref previousColLight previousColor tilemde) ;; Assign cur depending on tilemode (setq pref (vla-get-display (vla-get-Preferences (vlax-get-acad-object)))) (setq tilemde (getvar "tilemode")) (if (= tilemde 1) (setq cur (vla-get-GraphicsWinModelBackgrndColor pref)) (setq cur (vla-get-GraphicsWinLayoutBackgrndColor pref)) ) ;; Set up the dark and light colours to toggle (setq bgColorDark (rgb-to-dec 0 0 0)) (setq bkColorLight (rgb-to-dec 255 255 255)) (setq previousColLight bkColorLight) ; for compatibility with existing code ;; Get current background color (setq inBlockEditor (= (getvar "BLOCKEDITOR") 1)) (if inBlockEditor (setq previousColor (atoi (getenv "BEditBackground"))) (setq previousColor (vlax-variant-value (vlax-variant-change-type cur vlax-vblong))) ) ;; Decide if we need to switch to light or dark based on current colour (cond ((= previousColor bgColorDark) T) ; If currently dark, switch to light ((= previousColor bkColorLight) nil) ; If currently light, switch to dark (T ; Fallback: use brightness as before (> (color-brightness previousColor) (/ (+ (color-brightness bgColorDark) (color-brightness bkColorLight)) 2.0) ) ) ) ) ;;------------------------------------------------------- ;; HELPER FUNCTIONS END ;;------------------------------------------------------- ;; ;;------------------------------------------------------- ;; MAIN CODE STARTS ;;------------------------------------------------------- ;; Toggles the display from black to white ;; If black the plot styles are not shown ;; If white the plot styles are shown (defun c:TG (/ bgColorDark bkColorLight doc gridcol-major gridcol-minor gridcolDarkMajor gridcolDarkMinor gridcolLightMajor gridcolLightMinor inBlockEditor pref previousColLight tilemde whiteBackground) (setq doc (vla-get-activedocument (vlax-get-acad-object))) ;; Define grid color lists (setq gridcolLightMajor (rgb-to-dec 100 200 200)) (setq gridcolLightMinor (rgb-to-dec 240 240 240)) (setq gridcolDarkMajor (rgb-to-dec 10 60 60)) (setq gridcolDarkMinor (rgb-to-dec 35 35 35)) ;; Assign cur depending on tilemode (setq pref (vla-get-display (vla-get-Preferences (vlax-get-acad-object)))) (setq tilemde (getvar "tilemode")) ;; Set up the dark and light colours to toggle (setq bgColorDark (rgb-to-dec 0 0 0)) (setq bkColorLight (rgb-to-dec 255 255 255)) ; (setq previousColLight bkColorLight) ; for compatibility with existing code ;; Get current background color (setq inBlockEditor (= (getvar "BLOCKEDITOR") 1)) (setq whiteBackground (isWhiteBackground)) ;; Set grid colors based on background (if whiteBackground ;; Was light or lighter background, so toggle to dark background (progn (setq gridcol-major gridcolLightMajor) (setq gridcol-minor gridcolLightMinor) ) ;; Was dark or darker background, so toggle to light background (progn (setq gridcol-major gridcolDarkMajor) (setq gridcol-minor gridcolDarkMinor) ) ) ;; Model space and Block Editor (if (not (zerop tilemde)) ; Model space (progn ;; Toggle background color for model space (if (not inBlockEditor) (progn (vla-put-GraphicsWinModelBackgrndColor pref (vlax-make-variant (if whiteBackground bkColorLight bgColorDark) vlax-vblong)) (setenv "2D Model grid major lines color" (itoa gridcol-major)) (setenv "2D Model grid minor lines color" (itoa gridcol-minor)) ) ) ;; Toggle Block Editor background color in registry (if inBlockEditor (progn ; (setenv "BEditBackground" (itoa (if whiteBackground bgColorDark previousColLight))) ; (setenv "BEdit grid major lines color" (itoa gridcol-major)) ; (setenv "BEdit grid minor lines color" (itoa gridcol-minor)) (alert "\nNote:\nBackground cannot be updated inside the block editor\n") ) ) ) ;; progn - Model space ;; Paper space (Layout) (progn (vla-put-GraphicsWinLayoutBackgrndColor pref (vlax-make-variant (if whiteBackground bkColorLight bgColorDark) vlax-vblong)) (setenv "Layout grid major lines color" (itoa gridcol-major)) (setenv "Layout grid minor lines color" (itoa gridcol-minor)) ) ;; progn - Paper space ) ;; Toggle plot styles in paper space (if (not inBlockEditor) (progn (if whiteBackground ;; Toggles all open docs to display correctly ;; For example, when you have two drawings side by side, you need this to work on those too. (ShowPlotStyles :vlax-true 2) ;; Plot styles ON, all layouts in all open drawings (ShowPlotStyles :vlax-false 2) ;; Plot styles OFF, all layouts in all open drawings ) ) ) (vlax-release-object pref) (princ) ) (princ "\nToggleDisplayColour.lsp v1.2a loaded...") ; (c:TG) ;; Unblock for testing Quote
rlx Posted 2 hours ago Posted 2 hours ago you're welcome. The 'secret' when going MDI is using vla commands only. 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.