TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: FELIX on April 25, 2024, 05:40:35 PM
-
How to modify the value in -DWGUNITS from 3 to 6 by AutoLISP?
Command: -DWGUNITS
Drawing units:
1. Inches
2. Feet
3. Millimeters
4. Centimeters
5. Decimeters
6. Meters
Unit for length <3>: 6
-
Something like this
(command "-dwgunits" 6 2 3 "N" "Y")
-
With my ancient A2K, this works: (setvar "LUNITS" 2) <- for decimal
-
With my ancient A2K, this works: (setvar "LUNITS" 2) <- for decimal
Untested but?
(defun check-and-set-lunits ()
(if (/= (getvar "LUNITS") 6) ; Check if LUNITS is not already set to 6
(progn
(setq change_units (strcat "\nLUNITS is currently set to " (itoa (getvar "LUNITS")) ", do you want to change it to 6? [Y/N]: "))
(if (equal (getstring change_units) "Y")
(setvar "LUNITS" 6) ; Change LUNITS to 6
(prompt "\nLUNITS remains unchanged.")))))
(check-and-set-lunits)
Change for meters
-
With my ancient A2K, this works: (setvar "LUNITS" 2) <- for decimal
DWGUNITS can have another setting, it is optional to match AutoCAD units settings.
-
With my ancient A2K, this works: (setvar "LUNITS" 2) <- for decimal
DWGUNITS can have another setting, it is optional to match AutoCAD units settings.
I would rather note that LUNITS is a sub-setting within the UNITS command, along with ANGDIR, AUNITS, ANGBASE, INSUNITS, LUPREC and AUPREC. Other system Variables that effect units are MEASUREINIT, MEASUREMENT and UNITMODE.
-
I did't say it isn't. DWGUNITS is something different. From origin it comes from a vertical, AutoCAD Architecture I think. Within DWGUNITS you can set some unit settings and it is optional to match them with the AutoCAD units.
Normally you don't notice the DWGUNITS stuff but there are cases you do.
The best setting is to match AutoCAD units and then forget all about DWGUNITS.
-
With my ancient A2K, this works: (setvar "LUNITS" 2) <- for decimal
Untested but?
(defun check-and-set-lunits ()
(if (/= (getvar "LUNITS") 6) ; Check if LUNITS is not already set to 6
(progn
(setq change_units (strcat "\nLUNITS is currently set to " (itoa (getvar "LUNITS")) ", do you want to change it to 6? [Y/N]: "))
(if (equal (getstring change_units) "Y")
(setvar "LUNITS" 6) ; Change LUNITS to 6
(prompt "\nLUNITS remains unchanged.")))))
(check-and-set-lunits)
Change for meters
The command is -DWGUNITS and LUNITS does not accept =6
-
Something like this
(command "-dwgunits" 6 2 3 "N" "Y")
How to do it without COMMAND to look elegant within a program?
-
How to modify the value in -DWGUNITS from 3 to 6 by AutoLISP?
Command: -DWGUNITS
Drawing units:
1. Inches
2. Feet
3. Millimeters
4. Centimeters
5. Decimeters
6. Meters
Unit for length <3>: 6
This part of the command relates to INSUNITS
https://help.autodesk.com/view/ACDLT/2025/ENU/?guid=GUID-A58A87BB-482B-4042-A00A-EEF55A2B4FD8
PKENEWELL has listed this and the other system variables related to this command.
-
The command is -DWGUNITS and not INSUNITS or LUNITS.
Please pay more attention before responding.
-
The command is -DWGUNITS and not INSUNITS or LUNITS.
Please pay more attention before responding.
-DWGUNITS is a command.
INSUNITS (https://help.autodesk.com/view/ACD/2025/ENU/?guid=GUID-A58A87BB-482B-4042-A00A-EEF55A2B4FD8) and LUNITS (https://help.autodesk.com/view/ACD/2025/ENU/?guid=GUID-D7C80D1F-B1C0-44A9-898E-B3100FF391CB) are system variables
As others have pointed out, -DWGUNITS looks to be related to an AutoCAD Vertical. It's not documented anywhere that I could find in the HELP. Also, from other posts it seems geared more towards converting a drawing from one set of units to another. Further to this, the prompting of the command changes depending on whether you've run the command previously in a drawing. So simply calling
(command "._-DWGUNITS" 6 2 3 "_N" "_Y")
may not work in all cases.
If you're simply trying to set the drawing units, then it would be better to explore the -UNITS (https://help.autodesk.com/view/ACD/2025/ENU/?guid=GUID-D396FBFE-6171-4A89-9E68-6CB082EBE0E1) command.
How to do it without COMMAND to look elegant within a program?
All the settings of the -UNITS command can be set via a system variable, which allows you to avoid making a command call from lisp. This is a more elegant approach. e.g