设置 AutoCAD 系统变量的值。 支持的平台:仅窗口 签名工 务 局: object.SetVariable Name, Value
返回值(RetVal)无返回值。 言论设置系统变量时,AutoCAD 可能需要整数、文本或双精度值。传递错误的数据类型(例如,在需要整数时传递双精度类型的变体)将生成错误。避免这种情况的最简单方法是使用其中一个函数,例如,在传递数据之前显式键入数据。CxxxCInt() 有关所有 AutoCAD 系统变量及其类型的列表,请参阅 AutoCAD 帮助系统中的“系统变量”。 例子工 务 局: Sub Example_SetVariable() ' This example sets various system variables, each of ' a different data type. Dim sysVarName As String Dim sysVarData As Variant Dim DataType As Integer ' Set FILEDIA system variable (data type Integer) to 1. NOTE that ' you need to declare a variable as the data type of system variable, ' assign data to that variable and then make it variant type Dim intData As Integer sysVarName = "FILEDIA" intData = 1 sysVarData = intData ' Integer data ThisDrawing.SetVariable sysVarName, sysVarData ' Check the variable using GetVariable sysVarData = ThisDrawing.GetVariable(sysVarName) MsgBox sysVarName & " = " & sysVarData, , "SetVariable Example" ' Set DCTCUST system variable (data type String) to "My Custom Dictionary" Dim strData As String sysVarName = "DCTCUST" strData = "My Custom Dictionary" sysVarData = strData ' String data ThisDrawing.SetVariable sysVarName, sysVarData ' Check the variable using GetVariable sysVarData = ThisDrawing.GetVariable(sysVarName) MsgBox sysVarName & " = " & sysVarData, , "SetVariable Example" ' Set CHAMFERA system variable (data type Double) to 1.5 Dim dataDouble As Double sysVarName = "CHAMFERA" dataDouble = 1.5 sysVarData = dataDouble ' Double data ThisDrawing.SetVariable sysVarName, sysVarData ' Check the variable using GetVariable sysVarData = ThisDrawing.GetVariable(sysVarName) MsgBox sysVarName & " = " & sysVarData, , "SetVariable Example" ' Set INSBASE system variable (data type array) to (1.0,1.0,0) Dim arrayData3D(0 To 2) As Double sysVarName = "INSBASE" arrayData3D(0) = 1#: arrayData3D(1) = 1#: arrayData3D(2) = 0 sysVarData = arrayData3D ' 3D array data ThisDrawing.SetVariable sysVarName, sysVarData ' Check the variable using GetVariable sysVarData = ThisDrawing.GetVariable(sysVarName) MsgBox sysVarName & " = " & sysVarData(0) & ", " & sysVarData(1) & ", " & sysVarData(2), , "SetVariable Example" End Sub Visual LISP: (vl-load-com) (defun c:Example_SetVariable() ;; This example sets various system variables, each of ;; a different data type. ;; Set FILEDIA system variable (data type Integer) to 1. NOTE that ;; you need to declare a variable as the data type of system variable, ;; assign data to that variable and then make it variant type (setq sysVarName "FILEDIA" intData 1 sysVarData intData) ;; Integer data (vla-SetVariable doc sysVarName sysVarData) ;; Check the variable using GetVariable (setq sysVarData (vlax-variant-value (vla-GetVariable doc sysVarName))) (alert (strcat sysVarName " = " (itoa sysVarData))) ;; Set DCTCUST system variable (data type String) to "My Custom Dictionary" (setq sysVarName "DCTCUST" strData "My Custom Dictionary" sysVarData strData) ;; String data (vla-SetVariable doc sysVarName sysVarData) ;; Check the variable using GetVariable (setq sysVarData (vlax-variant-value (vla-GetVariable doc sysVarName))) (alert (strcat sysVarName " = " sysVarData)) ;; Set CHAMFERA system variable (data type Double) to 1.5 (setq sysVarName "CHAMFERA" dataDouble 1.5 sysVarData dataDouble) ;; Double data (vla-SetVariable doc sysVarName sysVarData) ;; Check the variable using GetVariable (setq sysVarData (vlax-variant-value (vla-GetVariable doc sysVarName))) (alert (strcat sysVarName " = " (rtos sysVarData 2))) ;; Set INSBASE system variable (data type array) to (1.0,1.0,0) (setq sysVarName "INSBASE" arrayData3D (vlax-3d-point 1 1 0) sysVarData arrayData3D) ;; 3D array data (vla-SetVariable doc sysVarName sysVarData) ;; Check the variable using GetVariable (setq sysVarData (vlax-variant-value (vla-GetVariable doc sysVarName))) (alert (strcat sysVarName " = " (rtos (vlax-safearray-get-element sysVarData 0) 2) ", " (rtos (vlax-safearray-get-element sysVarData 1) 2) ", " (rtos (vlax-safearray-get-element sysVarData 2) 2))) ) |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:47
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.