Jump to content

All Activity

This stream auto-updates

  1. Past hour
  2. It was more of a qualifier... While I'm sure they exist, I've never personally met anyone who used Python and couldn't compile .NET Haha
  3. Today
  4. FYI, it’s not .NET, it’s Python, so no compiling required https://github.com/CEXT-Dan/PyRx Though .NET certainly would work, the function is AcGeCurve3d::project Maybe similar to PROJECTGEOMETRY
  5. This thread was mentioned in a similar discussion, so sharing my reply here in kind. If you can compile .NET, use @Danielm103's code - if you instead use Visual LISP, this may help:
  6. This does: (defun c:FOO (/ *error* _move _set elev acDoc ss objName pt i) (defun *error* (msg) (if ss (vla-delete ss)) (if acDoc (vla-endundomark acDoc)) (cond ((not msg)) ; Normal exit ((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit) ((princ (strcat "\n** Error: " msg " ** "))) ; Fatal error, display it ) (princ) ) (defun _move (prop /) (vla-move x (vlax-3d-point '(0 0 0)) (vlax-3d-point (mapcar '- (list (car (setq pt (vlax-get x prop))) (cadr pt) elev) pt ) ) ) ) (defun _set (prop /) (vlax-put x prop (list (car (setq pt (vlax-get x prop))) (cadr pt) elev ) ) ) (if (and (ssget "_:L" '( (0 . "ARC,ATTDEF,CIRCLE,DIMENSION,ELLIPSE,HATCH,INSERT,*LEADER,LINE,*POLYLINE,MTEXT,POINT,REGION,SOLID,SPLINE,TEXT" ) ) ) ;; someone asked if they could pick a point: ;;(setq elev (getpoint "\nSpecify point for elevation: ")) ;;(setq elev (last elev)) (setq elev (getreal "\nEnter an elevation: ")) ) (progn (vla-startundomark (setq acDoc (vla-get-activedocument (vlax-get-acad-object))) ) (vlax-for x (setq ss (vla-get-activeselectionset acDoc)) (setq pt nil) (cond ((vl-position (setq objName (vla-get-objectname x)) '("AcDbArc" "AcDbCircle" "AcDbEllipse") ) (_set "center") ) ((vl-position objName '("AcDbAttributeDefinition" "AcDbMText" "AcDbText")) (_set "insertionpoint") ) ((wcmatch objName "AcDb*Dimension") (_move "textposition") ) ((= "AcDbBlockReference" objName) ;; <-- test for and ignore xrefs here, if needed (_set "insertionpoint") ) ((= "AcDbLine" objName) (_set "startpoint") (_set "endpoint") ) ((= "AcDbPoint" objName) (_set "coordinates") ) ((vl-position objName '("AcDbHatch" "AcDbPolyline" "AcDb2dPolyline")) (vla-put-elevation x elev) ) ((vl-position objName '("AcDb3dPolyline" "AcDbLeader" "AcDbSolid")) (setq pt (vlax-get x 'coordinates)) (setq i 0) (setq pt (mapcar (function (lambda (n) (setq i (1+ i)) (if (= 0 (rem i 3)) elev n ) ) ) pt ) ) (vlax-put x 'coordinates pt) ) ((= "AcDbMLeader" objName) (setq pt (vlax-invoke x 'GetLeaderLineVertices 0)) (vla-move x (vlax-3d-point (setq pt (list (car pt) (cadr pt) (caddr pt))) ) (vlax-3d-point (list (car pt) (cadr pt) elev)) ) ) ((= "AcDbRegion" objName) (setq pt (vlax-get (car (setq i (vlax-invoke x 'explode))) 'startpoint ) ) (vla-move x (vlax-3d-point (setq pt (list (car pt) (cadr pt) (nth 2 pt))) ) (vlax-3d-point (list (car pt) (cadr pt) elev)) ) (foreach line i (vla-delete line)) ) ((= "AcDbSpline" objName) (if (= :vlax-true (vla-get-isplanar x)) (progn (setq pt (vlax-get x 'controlpoints)) (vla-move x (vlax-3d-point (setq pt (list (car pt) (cadr pt) (nth 2 pt))) ) (vlax-3d-point (list (car pt) (cadr pt) elev)) ) ) (progn (setq x (entget (vlax-vla-object->ename x))) (setq x (mapcar (function (lambda (p) (cond ((and (member (car p) '(10 11 12 13)) (listp (cdr p)) (= 3 (length (cdr p))) ) (list (car p) (cadr p) (caddr p) elev ) ) (t p) ) ) ) x ) ) (entmod x) ) ) ) (T nil) ) ) ) ) (*error* nil) )
  7. 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.
  8. 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
  9. The FLATTEN command explodes MLeader and does not work with dimensions.
  10. When my workload allows, I'll give it a good run.
  11. 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.
  12. Yesterday
  13. you're welcome. The 'secret' when going MDI is using vla commands only.
  14. 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
  15. 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) )
  16. 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
  17. Did you try FLATTEN command?
  18. 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)))))
  19. mhupp

    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) )
  20. 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.
  21. maahee

    tables

    (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
  22. interesting I only used VBA to call a single command at a time from excel. Test if your in blockeditor (getvar 'BLOCKEDITOR)
  23. Last week
  24. You're an angel. Works in LT now we have lisp functionality.
  25. 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
  26. 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.
  27. shurg.
  28. 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.
  29. 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.
  1. Load more activity
×
×
  • Create New...