AutoCAD 中的系统变量与环境变量

AutoCAD 中的系统变量与环境变量 (来自官方帮助文件)

About System and Environment Variables (AutoLISP)
 

(1)系统变量

AutoLISP applications can inspect and change the value of AutoCAD system variables with the getvar and setvar functions.
;;系统变量主要是涉及 AutoCAD 的。
 
These functions use a string to specify the variable name. The setvar function requires a second argument that specifies the new value the system variable.
AutoCAD system variables accept and return various data types: integers, reals, strings, 2D points, and 3D points.
一般的系统变量的数据类型有:整数、浮点数(实数)、字符串、 2D 点 和 3D点
 
Values supplied as arguments to set var must be of the expected type. If an invalid type is supplied, an AutoLISP error is generated.
setvar 的参数必须是所能接受的数据类型
 
The following example code demonstrates how to get and set the value of the AutoCAD FILLETRAD system variable:
 
(if(<(getvar"filletrad")1)
 (setvar"filletrad"1)
)
 
 

(2)环境变量

Additional functions, getenv and setenv, provide AutoLISP routines with access to the currently defined operating system environment variables.
;; 环境变量主要涉及 操作系统的。两类变量并没有明显的分类依据(也许是我还没找到)。
 
Unlike system variable names, environment variable names are case specific. For example, MaxHatch and MAXHATCH are not the same. When using the setenvfunction, you always supply the new value as a string even if it might be a numeric value.
 
与系统变量不同,环境变量名是大小写敏感的,且其值总是字符串。
 
Note that changes to settings might not take effect until the next time AutoCAD is started.
对环境变量的设置,有可能不会立即生效,直到AutoCAD重启
 
The following example code demonstrates how to set the MaxHatch environment variable:
(setq curMaxHatch (getenv"MaxHatch"))
(prompt(strcat" Current value of MaxHatch: " curMaxHatch))
(setenv"MaxHatch""50000")
(prompt(strcat" New value of MaxHatch: "(getenv"MaxHatch")))
(setenv"MaxHatch" curMaxHatch)
 
可使用下列方式进行环境设置:
■ 如果使用命令行开关指定环境设置,命令行开关将替代在"选项"对话框或环境变量中指定的设置。
■ 如果未设定命令行开关,将使用"选项"对话框中设定的相应值。
■ 如果既没有设定命令行开关,也没有设定"选项"值,则使用环境变量值。
 
注意:命令行开关和环境变量只替代当前任务的"选项"对话框中设定的值。它们不会改变系统注册表。
 

另外:据测试,用户可以增加任意名称的 “环境变量” ,数据应该是保存在注册表中(暂未找到官方文档说明),测试如下:

 $ (setenv "VS\boxtext-off" (rtos pi 2 2))   ;; "3.14"

$ (getenv "VS\boxtext-off")  ;;"3.14"

 
 
原文地址:https://www.cnblogs.com/InspiringMind/p/4780523.html