Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getvar -DWGUNITS

15 REPLIES 15
Reply
Message 1 of 16
ludvig.linderV5RB6
1541 Views, 15 Replies

Getvar -DWGUNITS

Hi, 

 

I'm checking model files for properties and settings, and was wondering if there is a way to get DWGUNITS in the same manner as for exampel INSUNITS, where I get returned with the inserted value (without changing it).

 

I understand that DWGUNITS checks multiple parameters, for example lunits and luprecision. But it still has a value <X>  (3 or 6 for mm and m), which I would like to return.

 

My check of INSUNITS that can be either 4 or 6 looks like this:

(setq TEST_INSUNITS_4 (= 4 (getvar "INSUNITS")))
(setq TEST_INSUNITS_6 (= 6 (getvar "INSUNITS")))

 

(setq RESULT
   (strcat

      (cond
      (TEST_INSUNITS_4
      "\nINSUNITS\t\t = 4 \t- OK")
      (TEST_INSUNITS_6
      "\nINSUNITS\t\t = 6 \t- OK")
      (t (strcat "\nINSUNITS\t\t = " (itoa (getvar "INSUNITS")) "\t- WRONG, SHOULD BE 4 OR 6"))
      )

   )
)

(alert RESULT)

I am then returned with a dialogbox, stating if INSUNITS is 4, 6 och something else (WRONG..).

 

Why is it not possible to do the exact same for DWGUNITS? 

15 REPLIES 15
Message 2 of 16


@ludvig.linderV5RB6 wrote:

....

Why is it not possible to do the exact same for DWGUNITS? 


Because DWGUNITS is not a System Variable.

Kent Cooper, AIA
Message 3 of 16

Thanks for your response.

Yes ok, but then one of the work arounds could be to identify what system variables that DWGUNITS include, no? And then check those instead?

That is;
Linear display format (lunits)
Linear display precision (luprec)
Insertion scale (insunits)
etc.. I'm guessing this list could be quite long.

Would this be a possible work around, or am I missing something?
Message 4 of 16

@ludvig.linderV5RB6 ,

 

Can you explain more what your end goal is? Are you only trying to display certain text to the user? change something in the drawing?

 

We do not know what your definition of "DWGUNITS" is, can you elaborate more on what you're trying to accomplish please.

 

Best,

~DD


Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 5 of 16

I'm just checking the CAD settings of many model files basically. I do not wish to change or modify anything.
As of right now, I'm just checking some parameters, alerted in a dialogue box, to make sure all settings of these model files are the way I want them to be.

Right now, the script checks the setting of, among other, proxygraphics, proxyshow, aunits, lunits, insunits, ltscale, how many objects that are in layer 0, how many objects that has color/linetype/lineweight not "By layer" and if the model file has any xref attached to it.

I wish to add the check of DWGUNITS to this list, or the system variables related to DWGUNITS.
Message 6 of 16

@ludvig.linderV5RB6 ,

 

Well, TBH it looks like you already have a pretty good grasp on what variables you need to check. Here's a complete list just in case you need a couple more.

 

Does this help? do you need anything further?

 

image.png

 

Best,

~DD


Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 7 of 16

Thanks for your reply.

Well, in order for me to replace checking of DWGUNITS (since it's not a system variable) with several other variables affected by it, I need to make sure what exact variables are included by DWGUNITS, if there are more than these mentioned and seen in DDUNITS as you showed.
Message 8 of 16

@ludvig.linderV5RB6 ,

 

After more research about -DWGUNITS and how that command works/affects the drawing, I see that I have not fully answered your question. 

 

I will have to do more research and get back with you.

Here's a good start though:

https://forums.autodesk.com/t5/autocad-forum/dwgunits-documentation/td-p/2527820

 

Best,

~DD


Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 9 of 16

@ludvig.linderV5RB6 ,

 

Well, this is a lot deeper than I was expecting to dive today, but here's the results.

 

First, a few things must be established...

- The "-DWGUNITS" command I do not believe is available in Vanilla AutoCAD, I think it's only specific to certain verticals.

- The "-DWGUNITS" command is also an AEC command: -AECDWGSETUP (...under the "Units" option)

- In addition to a Command Line interface (the default you're used to seeing) we also have a Dialog Box option to interact with these settings, with this command: AECDWGUNITSETUP (image below).

 

Now, I will dig into how we can access some of these items. I will have a couple Code Samples below, but ALL of the code samples will reference a global variable ("*docC3D*") that I establish with this code (I believe it is compliments of user: Jeff_M, who hangs out over in the Civil 3D Customization forum a lot):

;; Returns the AeccXUiLandLib Interface object (as vla object)
;; (the primary object that allows us to edit 'Civil' related items [alignment, surface, points, etc.])
;; Also sets as global var
(defun C3D-GetC3D ( / C3D)
  (setq	C3D (strcat "HKEY_LOCAL_MACHINE\\"
                    (if vlax-user-product-key
                      (vlax-user-product-key)
                      (vlax-product-key)
                    );if
            );strcat
        C3D (vl-registry-read C3D "Release")
        C3D (substr
              C3D
              1
              (vl-string-search "." C3D (+ (vl-string-search "." C3D) 1))
            );substr
        *C3D* (vla-getinterfaceobject
                (vlax-get-acad-object)
                (strcat "AeccXUiLand.AeccApplication." C3D)
              );vla-getinterfaceobject
  );setq
);defun

;; Returns the active C3D document (as vla object)
;; Also sets as global var
(defun C3D-GetC3DActiveDocument ( / )
  (setq *docC3D* (vla-get-activedocument *C3D*))
);defun

 

 

Here is a screenshot for reference. I will Not be going through all of the tabs because I believe this is enough information to get you on the right track.

image.png

 

 

Code Sample: 1

Reference (aeccDrawingUnitFeet = 1): http://docs.autodesk.com/CIV3D/2012/ENU/API_Reference_Guide/com/AeccXLandTypesLib__AeccDrawingUnitTy... 

(setq tmp *docC3D*
      dwgUnits
        (foreach x '("Database" "Settings" "DrawingSettings" "UnitZoneSettings" "DrawingUnits")
          (setq tmp (vlax-get tmp x))
        );foreach
);setq

 

Code Sample: 2

Reference: http://docs.autodesk.com/CIV3D/2012/ENU/API_Reference_Guide/com/AeccXLandLib__IAeccSettingsArea.htm 

(setq tmp *docC3D*
      areaType
        (foreach x '("Database" "Settings" "DrawingSettings" "AmbientSettings" "AreaSettings" "Unit" "Value")
          (setq tmp (vlax-get tmp x))
        );foreach
);setq
(setq tmp *docC3D*
      areaPrecision
        (foreach x '("Database" "Settings" "DrawingSettings" "AmbientSettings" "AreaSettings" "Precision" "Value")
          (setq tmp (vlax-get tmp x))
        );foreach
);setq

 

Code Sample: 3

Reference: http://docs.autodesk.com/CIV3D/2012/ENU/API_Reference_Guide/com/AeccXLandLib__IAeccSettingsUnitZone.... 

(setq tmp *docC3D*
      dwgUnits
        (foreach x '("Database" "Settings" "DrawingSettings" "UnitZoneSettings" "ScaleObjectsFromOtherDrawings")
          (setq tmp (vlax-get tmp x))
        );foreach
);setq

 

Code Sample: 4

Reference: http://docs.autodesk.com/CIV3D/2012/ENU/API_Reference_Guide/com/AeccXLandLib__IAeccSettingsVolume.ht... 

(setq tmp *docC3D*
      volumeType
        (foreach x '("Database" "Settings" "DrawingSettings" "AmbientSettings" "VolumeSettings" "Unit" "Value")
          (setq tmp (vlax-get tmp x))
        );foreach
);setq
(setq tmp *docC3D*
      volumePrecision
        (foreach x '("Database" "Settings" "DrawingSettings" "AmbientSettings" "VolumeSettings" "Precision" "Value")
          (setq tmp (vlax-get tmp x))
        );foreach
);setq

 

 

Hope this helps!

 

Best,

~DD


Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 10 of 16
yianemma
in reply to: CodeDing

Hi,

I have a similar problem to the original post. I need to read the LUNITS in autocad 2013. 

Your answer was the best that i have found so far, but it will not work with autocad version 2013.

Although the -dwgunits is available as a command, AECDWGSETUP is missing cause, as you 've already said, it seems that is not available in vanilla autocad.

I have no experience with Visual LISP extention and ActiveX methods, just a basic undrestanding of autolisp (enough to do basic thinks by copying - pasting some code).

Any ideas will be mostly appreciated.

 

Thanks in advance,

Yiannis

 

 

Message 11 of 16
CodeDing
in reply to: yianemma

@yianemma ,

 

It sounds like you should be using the (getvar ...) function to retrieve the LUNITS variable.

Maybe something like this:

(defun c:TEST ( / LU LUdesc)
  (setq LU (getvar 'LUNITS))
  (setq LUdesc
    (cdr (assoc LU
      '((1 . "Scientific") (2 . "Decimal") (3 . "Engineering") (4 . "Architectural") (5 . "Fractional"))
    ))
  )
  (alert
    (strcat "\nYour units are currently: " LUdesc)
  )
  (princ)
)

 

Best,

~DD


Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 12 of 16

Thanks trying it this afternoon 

Message 13 of 16
Kent1Cooper
in reply to: yianemma

Another approach [no variables needed, nor an association list since the values are a contiguous series of integers]:

 

(defun C:LUR (); = Linear Units Report
  (alert
    (strcat
      "\nLinear units are currently set to "
      (nth (1- (getvar 'LUNITS)) '("Scientific" "Decimal" "Engineering" "Architectural" "Fractional"))
      "."
    )
  )
  (prin1)
)

 

Kent Cooper, AIA
Message 14 of 16
andkal
in reply to: ludvig.linderV5RB6

Hi
Here is a lisp to extract DWGUNITS
http://autolisps.blogspot.com/p/getdwgunits.html 


• www.autolisps.blogspot.com - Productivity plugins for Autocad and Autocad MEP
• Autodesk AppStore
Message 15 of 16
LDShaw
in reply to: ludvig.linderV5RB6

I may be late to the game and you're past this point but perhaps using the brute force way if you don't know what your looking for or just want an education on all it will do.
Use sysvdlg and save out the svf file make your changes or open up another file then save out another svf file with sysvlg. Do a compare and see what vars changed. That will give you at least a jumping off point finding those pesky hidden vars no one thinks about. 


Message 16 of 16
yianemma
in reply to: andkal

Excellent! Works like a charm. Clever enough for me..

Thanks a lot!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report