SETENV and GETENV Equivalents in AutoCAD

SETENV and GETENV Equivalents in AutoCAD

Anonymous
Not applicable
5,328 Views
12 Replies
Message 1 of 13

SETENV and GETENV Equivalents in AutoCAD

Anonymous
Not applicable

My firm has been using AutoCAD LT 2012 but a few stations are moving to the full version of AutoCAD 2017/2018 so we are trying to move all of the custom features from LT2012 to CAD2017/18. We have several blocks that we have made macros for so that we can insert them and they are automatically scaled based on the scale we have the drawing set at. To set this scale we have another macro that uses SETENV to create a variable and set the value based on the scale (1/8"=1, 1/4"=0.5, 1/2"=0.25, etc.). The blocks that are created are created so that in a 1/8"=1' drawing, they do not have to be scaled. This allows us to have the block insertion macro to scale all the blocks by the value we saved in that previous variable. (Hopefully all that makes sense). 

 

The problem we have now is that it looks like SETENV and GETENV are no longer valid commands in AutoCAD. Is there a similar command that I could use? 

0 Likes
Accepted solutions (1)
5,329 Views
12 Replies
Replies (12)
Message 2 of 13

Kent1Cooper
Consultant
Consultant

They may not be available as commands, but they are as AutoLisp functions -- (setenv) and (getenv).  A few of examples of their use are in some routines I did that store multiple User-specifiable Fillet radii and Chamfer distances and Offset Distances.

Kent Cooper, AIA
0 Likes
Message 3 of 13

Anonymous
Not applicable

@Anonymous wrote:

My firm has been using AutoCAD LT 2012 but a few stations are moving to the full version of AutoCAD 2017/2018 so we are trying to move all of the custom features from LT2012 to CAD2017/18. We have several blocks that we have made macros for so that we can insert them and they are automatically scaled based on the scale we have the drawing set at. To set this scale we have another macro that uses SETENV to create a variable and set the value based on the scale (1/8"=1, 1/4"=0.5, 1/2"=0.25, etc.). The blocks that are created are created so that in a 1/8"=1' drawing, they do not have to be scaled. This allows us to have the block insertion macro to scale all the blocks by the value we saved in that previous variable. (Hopefully all that makes sense). 

 

The problem we have now is that it looks like SETENV and GETENV are no longer valid commands in AutoCAD. Is there a similar command that I could use? 


DIMSCALE is the setvar that would control that scale, and in the macro you'd use (getvar to get the dimscale as in (getvar "dimscale")

0 Likes
Message 4 of 13

Anonymous
Not applicable

Either I don't understand your suggestion or you are misunderstanding what I am doing. When we are working on a plan at 1/8"=1' scale, we have a 1/8" Macro that uses SETVAR to set a variable to the value of 1. Then we insert a block (again using a macro). That macro automatically adjusts the scale of the block by a factor of the variable we originally set (using getvar). Again, assuming 1/8" drawing scale, the block insertion macro would scale the block by a factor of 1. If we use our scale macro for a 1/4"=1' scale, the variable is set to 0.5. When using the block inserting macro, that block is automatically adjusted by a factor of 0.5, so that is is half the size of the original block.

0 Likes
Message 5 of 13

Anonymous
Not applicable

We have been using LT for so long, we have absolutely no experience using LISP since we had no use for it. Everything has been done with command line macros. I have a strong feeling that 99% of the issues that I am going to run into with this migration could be resolved if I redo everything with LISP; however, completely redoing 15 years worth of macros is something I am desperately trying to avoid. I will take a look at the examples that you gave me to get an idea of how painful converting these macros to LISP actually is.

0 Likes
Message 6 of 13

Anonymous
Not applicable

@Kent1Cooper wrote:

They may not be available as commands, but they are as AutoLisp functions -- (setenv) and (getenv).  A few of examples of their use are in some routines I did that store multiple User-specifiable Fillet radii and Chamfer distances and Offset Distances.


We have been using LT for so long, we have absolutely no experience using LISP since we had no use for it. Everything has been done with command line macros. I have a strong feeling that 99% of the issues that I am going to run into with this migration could be resolved if I redo everything with LISP; however, completely redoing 15 years worth of macros is something I am desperately trying to avoid. I will take a look at the examples that you gave me to get an idea of how painful converting these macros to LISP actually is.

0 Likes
Message 7 of 13

Anonymous
Not applicable

@Anonymous wrote:

DIMSCALE is the setvar that would control that scale, and in the macro you'd use (getvar to get the dimscale as in (getvar "dimscale")


Either I don't understand your suggestion or you are misunderstanding what I am doing. When we are working on a plan at 1/8"=1' scale, we have a 1/8" Macro that uses SETENV to set a variable to the value of 1. Then we insert a block (again using a macro). That macro automatically adjusts the scale of the block by a factor of the variable we originally set (using GETENV). Again, assuming 1/8" drawing scale, the block insertion macro would scale the block by a factor of 1. If we use our scale macro for a 1/4"=1' scale, the variable is set to 0.5. When using the block inserting macro, that block is automatically adjusted by a factor of 0.5, so that is is half the size of the original block.

0 Likes
Message 8 of 13

Anonymous
Not applicable
Accepted solution

AutoCAD LT doesn't use lisp, so they added a few controls (GETENV, SETENV, etc.) to allow macros to work while pulling environment variables.  Full Auto CD has lisp/vlisp and has no need for the extra functions as they are accessed via lisp  (getvar and (setvar and MANY more tools.  Full AutoCAD opens up a whole new world in customization.

 

instead of SETENV, use (setvar "dimscale" 96), then instead of GETENV use (getvar "dimscale") to set the insertion scale. The parens are required.

0 Likes
Message 9 of 13

Anonymous
Not applicable

Odds are lisp function replacement for your macros already exist.  Check out the lisp forum here or theSwamp or LeeMac.

 

LeeMac also has a series of tutorials on lisp that are excellent.

0 Likes
Message 10 of 13

scot-65
Advisor
Advisor
There are three items that come into mind...

Setting the scale factor is as easy as setting one of the USER keys
then accessing that key for the scale factor. If you are using a Integer,
set one of the USERI1 thru USERI5.
(getvar "USERI1")
Look into USERR1 (Reals) for decimal format of saved information.
Also available are the USERS1 thru USERS5 (Strings - however these
are not saved in the DWG file).
Downside is these user keys were originally designed for DIESEL
display of the users' custom variables. They can easily be overwritten
by another 3rd party program (BTDT).

Next, if what you are saving is file specific, look into VLAX-LDATA-PUT.
This is a dictionary item that can store user information inside the file.

If what you are saving is NOT file specific, look into VL-REGISTRY-WRITE.
These are registry items. Commonly used for user settings such as
OSMODE.

Obsolete method is SETCFG / GETCFG. The registry method has replaced
these items (INI structured external file)

As rculp suggested, most of us agree that using DIMSCALE as the
basis of a scale factor is the preferred method. For example, DIMSCALE
divided by 12.0 gives us our "regular" text height.

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 11 of 13

Anonymous
Not applicable

@Anonymous wrote:

 

 

instead of SETENV, use (setvar "dimscale" 96), then instead of GETENV use (getvar "dimscale") to set the insertion scale. The parens are required.


Ahh... I understand now. I was trying to write a script in CUI using what you mentioned above. When it comes time to ask for the scale of the drawings I had: (/ (getvar "dimscale") 96) so that it would divide the value of dimscale by 96 to get the 1 or 0.5 that I would need to scale the block by. When I do this manually stepping through the commands line by line it works fine but in the script it looks like AutoCAD is removing the quotes around dimscale. Is there something I am missing here?

CUI Capture.JPGCommand Line Capture.JPG

0 Likes
Message 12 of 13

Kent1Cooper
Consultant
Consultant

tnealey wrote:.

...in the script it looks like AutoCAD is removing the quotes around dimscale. Is there something I am missing here?


That is odd, but if it has anything to do with the use of double-quotes in a macro, there's an alternative.  System variables can be addressed with an apostrophe before the name [only before], rather than double-quotes at both ends:

 

(/ (getvar 'dimscale) 96)

 

See whether that makes it work.  But it might be simply that not all AutoLisp functions can be used in macros, though I've never seen a breakdown of which can and which can't.

Kent Cooper, AIA
Message 13 of 13

Anonymous
Not applicable

Works perfectly with the apostrophe. Thanks for the help!! 

0 Likes