All Activity
- Past hour
-
Integrating Firing Range Software with AutoCAD for Shooting Range Design
SLW210 replied to oddssatisfy's topic in Autodesk Software General
Indoor or Outdoor? Nothing magical for AutoCAD that I know of. Just use general drafting techniques with what regulations you have, some equipment manufacturers have part models, though they could be only for Revit/BIM. Outdoor not much really to do but check regulations for berm heights, structures, shooting benches, any target supports, permanent targets, etc. The rest is just drafting. Indoor you need bulletproof roof, floors and walls (usually concrete), ventilation, acoustics/soundproofing, bullet traps (should be able to get model/drawing/specs from manufacturer), lighting considerations. Something like AutoCAD MEP and Architecture toolsets might be more useful. You might also want some video monitoring, a moveable target system for indoor might be wanted. Each part of the world and particular locations probably have different requirements, so probably no magic button. -
LISP to select lines and text according to "Z" values
SLW210 replied to shokoufeh's topic in AutoLISP, Visual LISP & DCL
As I posted in the other similar thread, I have found for most cases both FLATTEN and FLATSHOT of very little use. Posted somewhere on here are some TOOLBAR MACROs, which IMO does a better job for not too complex drawings to simply get a lot of basic objects to Z=0, as well as LISPs using the same method of moving everything then moving them all back. Initially it was needed for LT, not sure if something better can be used for newer LT with LISP. I'll repost the other thread which gives more on FLATTEN more complicated objects. Performance helps for Large-Scale Z-Flattening (Z0) AutoLISP Routine? - AutoLISP, Visual LISP & DCL - AutoCAD Forums -
LISP to select lines and text according to "Z" values
Nikon replied to shokoufeh's topic in AutoLISP, Visual LISP & DCL
The FLATTEN command explodes MLeader and does not work with dimensions. -
Tapered Offset/Stretch closed polyline shape
SLW210 replied to SLW210's topic in AutoLISP, Visual LISP & DCL
When my workload allows, I'll give it a good run. - Today
-
Tapered Offset/Stretch closed polyline shape
GLAVCVS replied to SLW210's topic in AutoLISP, Visual LISP & DCL
P.S.: The interface is available in both Spanish and English. If your operating system language is different, the voice messages will be read in English, but with the pronunciation of your language. If this is your situation and it bothers you, you should search the code for all the English phrases and translate them into your language. It shouldn't take you more than half an hour. You can also mute the speakers . Everyone can do what they think is best. - Yesterday
-
Change plotstyles display on all currently open docs?
rlx replied to 3dwannab's topic in AutoLISP, Visual LISP & DCL
you're welcome. The 'secret' when going MDI is using vla commands only. -
Change plotstyles display on all currently open docs?
3dwannab replied to 3dwannab's topic in AutoLISP, Visual LISP & DCL
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 -
Change plotstyles display on all currently open docs?
3dwannab replied to 3dwannab's topic in AutoLISP, Visual LISP & DCL
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) ) -
Tapered Offset/Stretch closed polyline shape
GLAVCVS replied to SLW210's topic in AutoLISP, Visual LISP & DCL
Hola de nuevo, Offsetea.mp4 Dejé una tarea pendiente en este hilo que intentaré cerrar. Adjunto una nueva versión de Offsetea . A continuación, explico el comportamiento y las opciones del comando. Partimos de una lógica de trabajo basada en el enfoque del código de Evgeny Elpanov. De hecho, esta lógica es más fácil de explicar en código que con palabras: proyectar un segmento entre dos vectores guía (definidos por los extremos del segmento y el punto que precede a cada uno de ellos) que se intersecan en un punto, que se convierte en el foco de la proyección. Al proyectar segmentos rectos, el resultado solo puede ser uno. Sin embargo, en el caso de segmentos de arco, ¿qué ocurre si reemplazamos el foco de proyección? En base a esto, se me ocurrieron dos opciones adicionales: el centro y el polo del arco. También consideré la posibilidad de añadir una tercera opción que permitiera al usuario especificar la ubicación del foco en pantalla. Sinceramente, no creo que esto sea útil (espero que al menos una de las otras dos lo sea ). Así, la funcionalidad del comando es la siguiente: - Selección del segmento de polilínea a proyectar: el comando solo funcionará si la polilínea está compuesta por 2 o más segmentos. Si el segmento seleccionado es recto , los vectores guía se definirán por sus extremos y el punto anterior de cada uno (es decir, los segmentos adyacentes). Si uno de los extremos del segmento es también un extremo de la polilínea, el vector guía para ese extremo será la normal a él. Si el segmento es un arco , los vectores guía predeterminados serán los mismos que para los segmentos rectos (propuesta de Evgeny). Sin embargo, aquí es posible cambiar el enfoque del enfoque secante de Evgeny (tecla '2') al enfoque radial (tecla '1') o al enfoque tangente (tecla '3'). En cuanto a las herramientas de control del segmento a proyectar, he implementado un ajuste al estilo GLAVCVS , limitado a los casos posibles para este comando: _end, _mid, _int, _cen, _nod, _ins, _nea. Este ajuste se puede activar o desactivar con F3. La relación entre la posición del cursor y el segmento a proyectar siempre será de seguimiento de segmento en los segmentos rectos. Sin embargo, en los segmentos de arco, puede ser de seguimiento de arco o de cuerda. Para alternar entre ambos, simplemente pulse TAB. El seguimiento de arco está activo mientras el cursor permanece entre los dos vectores de proyección. De lo contrario, cambia automáticamente al seguimiento de cuerda. La diferencia entre ambos radica, por lo tanto, en el comportamiento cuando el cursor se encuentra entre los vectores guía. Estos vectores guía se muestran en pantalla como dos líneas discontinuas rojas. Junto al cursor se muestra texto informativo en tiempo real: Para segmentos rectos (de arriba a abajo): la distancia de desplazamiento desde la ubicación inicial y la longitud del segmento. Para segmentos de arco: distancia de desplazamiento desde la ubicación inicial, radio del arco, longitud del arco y longitud de la cuerda. La visibilidad de esta información se puede activar o desactivar con la tecla "i" . Por último, puedes aumentar o disminuir el tamaño de los indicadores junto al cursor presionando las teclas '+' o '-'. En cuanto al rendimiento del comando, mientras escribía el código, descubrí una mayor variedad de casos de los que inicialmente había pensado. Si el objetivo principal era lograr el seguimiento del segmento de arco según la posición del cursor, creo que este código cubrirá aproximadamente el 90 % de los casos posibles. En los casos donde no sea posible el seguimiento del arco, se realizará a nivel de la cuerda. Espero que a alguien le resulte útil. Offsetea_v2.lsp -
pefi started following LISP to select lines and text according to "Z" values
-
LISP to select lines and text according to "Z" values
pefi replied to shokoufeh's topic in AutoLISP, Visual LISP & DCL
Did you try FLATTEN command? -
rlx started following Change plotstyles display on all currently open docs?
-
Change plotstyles display on all currently open docs?
rlx replied to 3dwannab's topic in AutoLISP, Visual LISP & DCL
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))))) -
mhupp started following tables
-
Do you want step by step undo? I would just wrap it in the start and end of the lisp to have one undo. (defun c:foo () (vl-load-com) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (vla-StartUndoMark doc) ; Begin Undo Group ;code (vla-EndUndoMark doc) ;End Undo Group (princ) )
-
Get length of MLeader/QLeader spline.
SLW210 replied to SLW210's topic in AutoLISP, Visual LISP & DCL
Yes, it could use some more refinement, but plenty close for what I need right now, I would like to get this LISP working on Leaders as well. I did get some headway on drawing a multileader to length, but spent too much time on this already, I have a couple of quick projects at work to knock out, so probably get back to it next week. I also looked at exploding, didn't really seem to be much better. When time allows I will play some more. -
(command "_.undo" "_begin") (setq dbase '()) ; Initialize dbase as empty list (setq selected-ent '()) (while (setq obj (ssget "_:S")) (setq ent (ssname obj 0)) (setq db (entget ent)) (setq tp (cdr (assoc 0 db))) ; Get entity type (if (or (= tp "LINE") (= tp "LWPOLYLINE")) (progn (if (not (member ent selected-ent)) (progn (setq selected-ent (cons ent selected-ent)) (cond ((= tp "LINE") (command "_.undo" "_begin") (setq p1 (cdr (assoc 10 db))) ; Start point coordinates (setq p2 (cdr (assoc 11 db))) ; End point coordinates (setq dist (distance p1 p2)); Calculate distance between p1 and p2 (setq dbase (cons (list dist) dbase)) (command "_.undo" "_end") ) ;cond1 ((= tp "LWPOLYLINE") (princ "\nPolyline selected. Midpoint calculation not implemented for polylines." ) ) ;cond2 ) ;cond main ) ;progn (princ "\nEntity already selected please select a different entity" ) ) ;if ) ;progn (princ "\nSelected entity is not a line or polyline.") ) ;if ) ;while (command "_.undo" "_end") ;;;;;;;;;;;; undo function used for undoing a single line or a polyline within the while function, and undoing a group of lines and polylines at the end of the while function.... active existed while loop by undo
-
Change plotstyles display on all currently open docs?
mhupp replied to 3dwannab's topic in AutoLISP, Visual LISP & DCL
interesting I only used VBA to call a single command at a time from excel. Test if your in blockeditor (getvar 'BLOCKEDITOR) - Last week
-
You're an angel. Works in LT now we have lisp functionality.
-
Change plotstyles display on all currently open docs?
3dwannab replied to 3dwannab's topic in AutoLISP, Visual LISP & DCL
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 -
Change plotstyles display on all currently open docs?
3dwannab replied to 3dwannab's topic in AutoLISP, Visual LISP & DCL
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. -
Change plotstyles display on all currently open docs?
mhupp replied to 3dwannab's topic in AutoLISP, Visual LISP & DCL
shurg. -
Change plotstyles display on all currently open docs?
3dwannab replied to 3dwannab's topic in AutoLISP, Visual LISP & DCL
This thread for RunAll by MP on the swamp wrote this. @BIGAL, that RunAll utility will process all open drawings without having to write a script. -
Change plotstyles display on all currently open docs?
3dwannab replied to 3dwannab's topic in AutoLISP, Visual LISP & DCL
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. -
Change plotstyles display on all currently open docs?
mhupp replied to 3dwannab's topic in AutoLISP, Visual LISP & DCL
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 -
Change plotstyles display on all currently open docs?
BIGAL replied to 3dwannab's topic in AutoLISP, Visual LISP & DCL
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. -
Get length of MLeader/QLeader spline.
BIGAL replied to SLW210's topic in AutoLISP, Visual LISP & DCL
Just a comment, If you compare the length of using vertices against the length of the spline they are different. So that was why I was exploding the mleader and playing with adjusting say the arrow point. The code I posted for 2 point mleaders could be easily changed to work with 3 or 4 vertices, ie a straight segment Mleader. That is why I was looking at making a matching spline and adjust it till correct length with doglegend = 0.0. Just have to work out how to set tangential line start to spline. A when have time task. -
Change plotstyles display on all currently open docs?
Steven P replied to 3dwannab's topic in AutoLISP, Visual LISP & DCL
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