TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: FELIX on April 25, 2024, 05:40:35 PM

Title: Modify DWGUNITS
Post 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
Title: Re: Modify DWGUNITS
Post by: BIGAL on April 25, 2024, 08:16:33 PM
Something like this

Code: [Select]
(command "-dwgunits" 6 2 3 "N" "Y")
Title: Re: Modify DWGUNITS
Post by: ScottMC on April 26, 2024, 09:55:58 AM
With my ancient A2K, this works: (setvar "LUNITS" 2) <- for decimal
Title: Re: Modify DWGUNITS
Post by: Lonnie on April 26, 2024, 11:45:03 AM
With my ancient A2K, this works: (setvar "LUNITS" 2) <- for decimal

Untested but?

Code: [Select]
(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
Title: Re: Modify DWGUNITS
Post by: huiz on April 26, 2024, 03:52:42 PM
With my ancient A2K, this works: (setvar "LUNITS" 2) <- for decimal
DWGUNITS can have another setting, it is optional to match AutoCAD units settings.
Title: Re: Modify DWGUNITS
Post by: PKENEWELL on April 26, 2024, 04:37:07 PM
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.
Title: Re: Modify DWGUNITS
Post by: huiz on April 27, 2024, 03:39:39 AM
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.
Title: Re: Modify DWGUNITS
Post by: FELIX on May 17, 2024, 11:44:21 PM
With my ancient A2K, this works: (setvar "LUNITS" 2) <- for decimal

Untested but?

Code: [Select]
(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
Title: Re: Modify DWGUNITS
Post by: FELIX on May 17, 2024, 11:46:23 PM
Something like this

Code: [Select]
(command "-dwgunits" 6 2 3 "N" "Y")

How to do it without COMMAND to look elegant within a program?
Title: Re: Modify DWGUNITS
Post by: JasonB on May 18, 2024, 04:58:21 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

This part of the command relates to INSUNITS
https://help.autodesk.com/view/ACDLT/2025/ENU/?guid=GUID-A58A87BB-482B-4042-A00A-EEF55A2B4FD8
Code - Auto/Visual Lisp: [Select]
  1. (setvar 'INSUNITS 6)

PKENEWELL has listed this and the other system variables related to this command.

Title: Re: Modify DWGUNITS
Post by: FELIX on May 18, 2024, 09:13:17 PM
The command is -DWGUNITS and not INSUNITS or LUNITS.

Please pay more attention before responding.
Title: Re: Modify DWGUNITS
Post by: JasonB on May 19, 2024, 01:54:55 AM
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
Code - Auto/Visual Lisp: [Select]
  1. (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
Code - Auto/Visual Lisp: [Select]
  1. (setvar 'INSUNITS 6)
  2. (setvar 'LUNITS 2)
  3. (setvar 'LUPREC 4)