AUGIWorld Magazine September/October 2007 - (Page 14) AutoCAD Accessing Values: Now or Later Being able to store values or information in a drawing, permanently or temporarily, has its advantages. As you use many of the commands in AutoCAD®, you might notice that they store values in a variety of ways, thus the most recently used option or value might be used the next time the command is used. Values can be stored locally in a drawing with system variables or temporary variables used in AutoLISP® routines, xdata associated with an object, or xrecords and dictionaries. Values that might be used across multiple drawings and AutoCAD sessions are stored in the Windows registry. While this article doesn’t cover all the different ways of storing and retrieving values for use with your AutoLISP or Visual LISP routines, I will show you how to store values locally using temporary variables and user system variables, and globally using the Windows Registry. function, you must make sure the Visual LISP functions are available by using the statement (vl-load-com) at the top of the file that defines the routines that will be using any of the Visual LISP functions. To retrieve a value from the Blackboard, you use the VL-BB-REF function. The following example code shows how to retrieve the value of the variable MyVar1 from the Blackboard. ;; Retrieves the value of the MyVar1 variable ;; on the Blackboard (vl-bb-ref ‘MyVar1) through USERI5, and USERR1 through USERR5. To assign a value to a User system variable, you use the SETVAR function. To retrieve the value that is assigned to a User system variable, you use the GETVAR function. If you want to list the current values of the User system variables you can use the SETVAR command. The following code shows how to assign and retrieve a value from a system variable. ;; Assign a value to the USERS1 system variable (setvar “USERS1” “Val1”) ;; Retrieve the value from the USERS1 system variable (getvar “USERS1”) Storing values temporarily with variables If you use AutoLISP or Visual LISP, you most likely know about the function SETQ, which allows you to assign a value to a variable. The SETQ function is limited to creating a variable in the current drawing only. However, if you want to have access to a value assigned to a variable all open drawings and new drawings within the current session of AutoCAD, you can use the function VL-BB-SET. The VL-BB-SET function uses the Blackboard namespace to pass values to all drawings open in the current AutoCAD session. The following example code shows how to assign the value “Val1” to a variable named MyVar1 using the Blackboard. So based on where you need to have access to a variable and its value, you can either use the SETQ or VL-BB-SET functions. After a value is assigned to the variable, use the appropriate method to retrieve the value. In the case of a variable that was created with the SETQ function, you just need to use the variable in another function as one of the available parameters or use the VL-BB-REF function to retrieve a value assigned to a variable with the VL-BB-SET function. ;; Example of storing a value with SETQ ;; and using the variable (setq var1 “Hello World!”) (alert var1) ;; Example of storing a value with VL-BB-SET ;; and using the variable (vl-bb-set ‘var1 “Hello World!”) (alert (vl-bb-ref ‘var1)) Note: Values assigned to the User system variables USERS1 through USERS5 are not stored in the drawing when it is saved. If you want to store string values with a drawing that can be retrieved in the future, you will want to use either xdata or xrecords with dictionaries. For more information on xdata, xrecords, and dictionaries see the topic “AutoLISP, Visual LISP, and DXF” in the AutoCAD online help system. Windows Registry System variables ;; Assign a value to the MyVar1 variable on the Blackboard (vl-bb-set ‘MyVar1 “Val1”) Note: Before you use the VL-BB-SET 14 System variables are not the most useful when it comes to storing temporary values, but there are three different types of user variables that can be used to hold values. There are a total of 15 User system variables that can hold strings, integer (whole) numbers, and real (double) numbers. The names of the User system variables that are accessible for temporary values are USERS1 through USERS5, USERI1 Windows operating systems such as Windows 2000 or Windows XP support a centralized repository for application settings and values in what is called the Windows Registry. The Windows Registry allows you to store values under elements known as keys. Think of the Windows Registry like the file system on your computer with paths, files, and folders. You can create new keys with the VL-REGISTRYWRITE function or use the VL-REGISTRY-READ function to retrieve a value from a key in the Windows Registry. If a key is no longer needed you can use the VL-REGISTRY-DELETE function. Note: Before you use the VL-REGISTRY-WRITE, VL-REGISTRY-READ, or w w w. A U G I . c o m http://www.AUGI.com
Table of Contents Feed for the Digital Edition of AUGIWorld Magazine September/October 2007 Contents The CAD Manager Feature: A Good First Impression ADT and SketchUp Team for Presentations Accessing Values: Now or Later Finding the 3D in Map 3D: Surface Visualization Rocks & Rock Walls Autodesk University 2007 Preview The Missing Link On the Back Page AUGIWorld Magazine September/October 2007 AUGIWorld Magazine September/October 2007 - (Page Cover1) AUGIWorld Magazine September/October 2007 - (Page Cover2) AUGIWorld Magazine September/October 2007 - (Page 1) AUGIWorld Magazine September/October 2007 - Contents (Page 2) AUGIWorld Magazine September/October 2007 - Contents (Page 3) AUGIWorld Magazine September/October 2007 - The CAD Manager (Page 4) AUGIWorld Magazine September/October 2007 - The CAD Manager (Page 5) AUGIWorld Magazine September/October 2007 - Feature: A Good First Impression (Page 6) AUGIWorld Magazine September/October 2007 - Feature: A Good First Impression (Page 7) AUGIWorld Magazine September/October 2007 - Feature: A Good First Impression (Page 8) AUGIWorld Magazine September/October 2007 - Feature: A Good First Impression (Page 9) AUGIWorld Magazine September/October 2007 - Feature: A Good First Impression (Page 10) AUGIWorld Magazine September/October 2007 - Feature: A Good First Impression (Page 11) AUGIWorld Magazine September/October 2007 - ADT and SketchUp Team for Presentations (Page 12) AUGIWorld Magazine September/October 2007 - ADT and SketchUp Team for Presentations (Page 13) AUGIWorld Magazine September/October 2007 - Accessing Values: Now or Later (Page 14) AUGIWorld Magazine September/October 2007 - Accessing Values: Now or Later (Page 15) AUGIWorld Magazine September/October 2007 - Finding the 3D in Map 3D: Surface Visualization (Page 16) AUGIWorld Magazine September/October 2007 - Finding the 3D in Map 3D: Surface Visualization (Page 17) AUGIWorld Magazine September/October 2007 - Finding the 3D in Map 3D: Surface Visualization (Page 18) AUGIWorld Magazine September/October 2007 - Finding the 3D in Map 3D: Surface Visualization (Page 19) AUGIWorld Magazine September/October 2007 - Rocks & Rock Walls (Page 20) AUGIWorld Magazine September/October 2007 - Rocks & Rock Walls (Page 21) AUGIWorld Magazine September/October 2007 - Rocks & Rock Walls (Page 22) AUGIWorld Magazine September/October 2007 - Rocks & Rock Walls (Page 23) AUGIWorld Magazine September/October 2007 - Autodesk University 2007 Preview (Page 24) AUGIWorld Magazine September/October 2007 - Autodesk University 2007 Preview (Page 25) AUGIWorld Magazine September/October 2007 - Autodesk University 2007 Preview (Page 26) AUGIWorld Magazine September/October 2007 - Autodesk University 2007 Preview (Page 27) AUGIWorld Magazine September/October 2007 - The Missing Link (Page 28) AUGIWorld Magazine September/October 2007 - The Missing Link (Page 29) AUGIWorld Magazine September/October 2007 - The Missing Link (Page 30) AUGIWorld Magazine September/October 2007 - The Missing Link (Page 31) AUGIWorld Magazine September/October 2007 - The Missing Link (Page 32) AUGIWorld Magazine September/October 2007 - The Missing Link (Page 33) AUGIWorld Magazine September/October 2007 - On the Back Page (Page 34) AUGIWorld Magazine September/October 2007 - On the Back Page (Page Cover3) AUGIWorld Magazine September/October 2007 - On the Back Page (Page Cover4)
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.