Leaderboard
Popular Content
Showing content with the highest reputation on 07/02/2026 in Posts
-
Here's a simple Lisp routine for obtaining data from an integrated GNSS receiver. It works by sending a small script to PowerShell, which writes the data to a file named 'pos.txt' saved in the Documents folder. I've only tested it on a single device, but it should work on any device equipped with an integrated GNSS receiver. The data is stored in latitude/longitude format, so each user will need to transform those coordinates into the desired coordinate reference system. To stop logging the data, simply close the PowerShell window This is just a starting point for anyone who wants to adapt it to their own needs. ;************************ G L A V C V S ************************* ;************************** F E C I T *************************** ;;;THIS CODE STARTS GNSS RECEIVER AND WRITES DATA TO A FILE CALLED 'pos.txt' IN THE My Docments FOLDER (defun startGNSS (/ cmd sh dir cad ur) (setq dir (VL-REGISTRY-READ "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders" "Personal" ) ) (if (setq sh (vlax-create-object "WScript.Shell")) (progn (if (and (or (setq ur (getint "\nUpdate rate (milliseconds) <1000>/2000/3000/5000 : ")) (not ur)) (member ur '(nil 1000 2000 3000 5000))) (progn (setq cad (strcat "Add-Type -AssemblyName System.Device" (chr 13) (chr 10) "# 1) Conectar con AutoCAD abierto" (chr 13) (chr 10) "$outFile = \'" dir "\\pos.txt\'" (chr 13) (chr 10) "try {" (chr 13) (chr 10) " $acad = [Runtime.InteropServices.Marshal]::GetActiveObject(\'AutoCAD.Application." (itoa (atoi (getvar "ACADVER"))) "\')" (chr 13) (chr 10) "}" (chr 13) (chr 10) "catch {" (chr 13) (chr 10) " Add-Type -AssemblyName System.Windows.Forms" (chr 13) (chr 10) " [System.Windows.Forms.MessageBox]::Show(" (chr 13) (chr 10) " \'Por alguna razón no se pudo conectar con AutoCAD mediante COM.\' + [Environment]::NewLine + $_.Exception.Message," (chr 13) (chr 10) " \'GNSS-}AutoCAD: Error de conexión\'," (chr 13) (chr 10) " [System.Windows.Forms.MessageBoxButtons]::OK," (chr 13) (chr 10) " [System.Windows.Forms.MessageBoxIcon]::Error" (chr 13) (chr 10) " )" (chr 13) (chr 10) " exit" (chr 13) (chr 10) "}" (chr 13) (chr 10) "# 2) Crear y arrancar receptor de ubicación Windows/GNSS" (chr 13) (chr 10) "$w = New-Object System.Device.Location.GeoCoordinateWatcher" (chr 13) (chr 10) "$w.Start()" (chr 13) (chr 10) "# 3) Bucle continuo: comprobar estado, obtener posición y escribir en USERS5" (chr 13) (chr 10) "while ($true) {" (chr 13) (chr 10) " $doc = $acad.ActiveDocument" (chr 13) (chr 10) " $status = $w.Status" (chr 13) (chr 10) " $p = $w.Position.Location" (chr 13) (chr 10) " $time = Get-Date -Format \'dd-MM-yyyy HH:mm:ss\'" (chr 13) (chr 10) " if ($status -eq \'Disabled\') {" (chr 13) (chr 10) " $line = \'*** GNSS ERROR: GNSS disabled ***\';;;;;;\"" (chr 13) (chr 10) " }" (chr 13) (chr 10) " elseif ($status -eq \'Initializing\') {" (chr 13) (chr 10) " $line = \'*** GNSS ERROR: Searching... ***\';;;;;;\"" (chr 13) (chr 10) " }" (chr 13) (chr 10) " elseif ($status -eq \'NoData\') {" (chr 13) (chr 10) " $line = \'*** GNSS ERROR: Without data ***\';;;;;;\"" (chr 13) (chr 10) " }" (chr 13) (chr 10) " elseif ($p.IsUnknown) {" (chr 13) (chr 10) " $line = \'*** ERROR GNSS: Unknown position ***\';;;;;;\"" (chr 13) (chr 10) " }" " else {" (chr 13) (chr 10) " $line = $p.Latitude + ';' + $p.Longitude + ';' + $p.Altitude + ';' + $p.HorizontalAccuracy + ';' + $p.VerticalAccuracy" (chr 13) (chr 10) " }" (chr 13) (chr 10) " try {" (chr 13) (chr 10) " Set-Content -Path $outFile -Value $line" (chr 13) (chr 10) " }" (chr 13) (chr 10) ;;; " catch {" ;;; (chr 13) ;;; (chr 10) ;;; " Write-Host 'ERROR escribiendo...: $($_.Exception.Message)'" ;;; (chr 13) ;;; (chr 10) ;;; " }" (chr 13) (chr 10) (strcat " Start-Sleep -Milliseconds " (if ur (itoa ur) "1000")) (chr 13) (chr 10) "}" ) cmd (strcat "powershell.exe -NoProfile -ExecutionPolicy Bypass -NoExit -Command \"" cad "\"" ) ) (vlax-invoke-method sh 'Run cmd 1 :vlax-false) (grtext -1 "*** GNSS writing file \'pos.txt\' ***") ) (alert "ERROR: \nUpdate rate should be 1000, 2000, 3000 or 5000\n\nExiting...") ) (vlax-release-object sh) ) ) )2 points
-
Thanks, @BIGAL You're right: it's probably necessary to solve the problem of transforming latitude/longitude to UTM. I might review the code to publish a more complete version. Or maybe someone else will do it before me1 point
-
Given that you indicate pre 2000 it is maybe time to upgrade. There is alternatives to Acad like Bricscad, Intellicad, Gstar to mention a few and much cheaper.1 point
-
Adding a few example macros from my Linetypes drop-down added to the Properties ribbon tab of my custom cuix file. As most of us use visual lisp it's easier to add (vl-load-com) to acaddoc.lsp than adding it to every lisp or macro. Keeping all my lin files in the same support folder as acad.lin makes accessing them easier. Loading lin files using Lee Mac's code: Reload Current ^C^C^P(or LM:LoadLinetypes (load "LoadLinetypesV1-3.lsp"))(LM:LoadLinetypes (list(getvar "celtype")) T) Reload All ^C^C^P(or LM:LoadLinetypes (load "LoadLinetypesV1-3.lsp"))(LtRedef) Dots ^C^C^P(or NewStyle (load "NewStyle.lsp"))(NewStyle "Arial" "arial.ttf") (or LM:LoadLinetypes (load "LoadLinetypesV1-3.lsp"))(LM:LoadLinetypes '("ArialDOT" "ArialDOT2" "ArialDOTX2" "PlusPlus") T) LT Curves ^C^C^P(or LM:LoadLinetypes (load "LoadLinetypesV1-3.lsp"))(LM:LoadLinetypes '("C25" "C-25" "C50" "C-50" "TREELINE_L" "TREELINE_R") T) LT Fences Walls ^C^C^P(or LM:LoadLinetypes (load "LoadLinetypesV1-3.lsp"))(LM:LoadLinetypes '("FENCELINE1" "FENCELINE2" "FENCE" "FENCE2" "FENCE5" "RD-Fence" "FENCE-BOX" "FENCE-BOX2" "FENCE-BOX4" "FENCE-BOX8" "FENCE-DIA" "FENCE-DIA2" "FENCE-DIA4" "FENCE-HW" "FENCE-H1" "FENCE-H2" "FENCE-O" "FENCE-X" "FENCE-Alan" "FENCE-X2" "FENCE-X4" "FENCE-O2" "BARBWIRE_1" "BARBWIRE_2" "CHAINLINK_1" "CHAINLINK_2" "STOCKADE_1" "STOCKADE_2" "STONEWALL") T) LT Dir Arrows ^C^C^P(or NewStyle (load "NewStyle.lsp"))(NewStyle "Arial" "arial.ttf") (or LM:LoadLinetypes (load "LoadLinetypesV1-3.lsp"))(LM:LoadLinetypes '("DIRECTION" "DIRECTION2" "DIRECTION5" "DIRECTION-A" "ArialARROW" "ArialAHead" "ArialTriangle") T) LT Danger ^C^C^P(or NewStyle (load "NewStyle.lsp"))(NewStyle "WINGDINGS" "wingding.ttf") (or LM:LoadLinetypes (load "LoadLinetypesV1-3.lsp"))(LM:LoadLinetypes '("Danger") T) Creating linetypes with text with ronjonp's lisp at https://www.theswamp.org/index.php?topic=47058.msg520876#msg520876 Everyone should have this, Thanks ronjonp! ^C^C^P(or C:makelt (load "makelt.lsp"));makelt Editing lin files: Edit Acad.lin ^C^C_start;acad.lin; Edit Arial.lin ^C^C_start;Arial.lin; Edit BOUCLES.lin ^C^C_start;BOUCLES.lin; List all Shape Names from all loaded Shape files using ShapeNames.lsp by lido. Handy if you only have the shx file not the shp. ^C^C^P(if(not ShapeNames)(load "ShapeNames.lsp"))(ShapeNames);; Code I added to bottom of Lee's LoadLinetypesV1-3.lsp for reloading all linetypes: ;Reload All Loaded Linetypes (defun LtRedef ( / acadObj doc ltlay) (setq acadObj (vlax-get-acad-object) doc (vla-get-ActiveDocument acadObj) ) (vlax-for obj (vla-get-linetypes doc) (if (not (wcmatch (vla-get-name obj) "*|*,Continuous,ByBlock,ByLayer")) (setq ltlay (cons (vla-get-name obj) ltlay)) ) ) (LM:loadlinetypes ltlay T) (vla-Regen doc acActiveViewport) ) Required lin, shx, shp and lsp files attached, adding Arial, wingdings and wingdings3 text styles are done with attached NewStyle.lsp wingdings.lin wingdings3.lin Arial.lin boucles.lin acad.lin boucles.shp boucles.shx NewStyle.lsp1 point
