Next | Titel | Inhalt | Vorwort | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | Appendix | @ CAAD | Teachers |
KAPITEL
7
AutoCAD
II - Datenbanken, geometrische Einheiten, Menues und Dialogboxen
A data element is a unit of information relevant to a task context. A data structure is a selected way to organize data using primitives in the computing system. Typical database operators include (i) retrieval to select some data and translate them into another level of abstraction, and (ii) modification to create, erase, or edit data in the database.
In some respects, a program like AutoCAD can be viewed as a database system which works on a database of drawings as follows:
System variables likes clayer, cmdecho, filedia, etc. are examples of global AutoCAD data elements. Operators like getvar and setvar can be used to retrieve and modify values associated with system variables. Note that you cannot create or erase AutoCAD system variables, only some of them can be modified, i.e. assigned different values or settings.
An association list is a list of embedded sublists, in which the first element of each sublist is a key.
(setq BRICK1 '((color red) (supported_by BRICK2) (size (x y z))) )In the above example, color, supported_by and size are keys or properties.
(assoc <key> <assoc_list>)where the first argument specifies the key, and the second argument specifies the association list that is to be searched for that key.
For example, to find color of BRICK1, following call will be made:
(assoc 'color BRICK1) => (color red)Note that assoc returns the entire sublist, not just the value of specified key.
(subst <new_value> <old_value> <a_list>)where the first argument provides new_value to be substituted wherever old_value occurs (one level deep) in the a_list.
For example, to change value of the key size from (x y z) in the above example to (XX YY ZZ), following call may be made:
(setq BRICK1 (subst '(size (XX YY ZZ)) (assoc 'size BRICK1) BRICK1))
Generally, cons function takes an atom or a list and inserts it into another list:
(cons 'a '(b)) => (a b)and
(cddr '(a b)) => nilIt is also possible to use cons to join two atoms into a list:
(cons 'a 'b) => (a . b)This notation is referred to as dotted pairs and should be used carefully.
(cdr '(a . b)) => b and not (b)and
(cddr '(a . b)) => Causes an error condition!
(open <file name> <mode>)Mode can be r for reading, w for writing, and a for appending data to a file. Once a file is properly open, you can read or write to the opened file as follows. Note that it is advisable to properly close files when they are no longer needed.
(setq infptr (open "telephone.data" "r")) (setq telephone (read (read-line infptr))) (close infptr) (setq outfptr (open "telephone.data" "w")) (print telephone outfptr) (close outfptr)Other useful file related functions are:
(read-char <file descriptor>) (write-line <string> <file descriptor>)
Drawing entities created as part of any AutoCAD drawing are stored internally in a database of information. Whenever you perform any operation- addition of a new entity, modification of an entity, or deletion of an entity, the drawing database is updated with new information. To access this database, AutoLisp provides two special data types, called entity names and selection sets.
(entget (entlast))
((-1 . <Entity name: 60000021>) ;entity name
(0 . "LINE") ;entity type
(8 . "TEST") ;layer
(10 1.0 1.0 0.0) ;starting point
(11 2.0 3.0 0.0) ;ending point
)
(setq linedata (entget (entlast)))
;get definition data for line
(setq linedata
(subst
(cons 8 "test2") ;new layer value
(assoc 8 linedata) ;old layer value
linedata ;old entity data
)
)
(entmod linedata);finally update database
(entupd ename) Entity is updated and regenerated on screen following any modification after above function entmod is executed.
A menu file is a plain text file containing command strings. All menu files must have extension .mnu (compiled version will have extension .mnx). Each menu item may consist of a command, a parameter, or a sequence of commands and parameters. By convention, each menu item resides on a separate line in the menu file.
Example: Following is a simple command menu file.
circle zoom e zoom p
When you select any of these options, AutoCAD will execute corresponding command.
Menu File Section Labels
Section labels in a menu file assign various options/commands to different devices. In the following example,
labels preceded by *** specify sections of command menu to different devices; in this case, first section to screen menu, and the next one to pop up menu 1. Also note that commands may be given descriptive titles enclosed in [] followed by actual commands to be executed when that option is selected.
Submenus and referencing
Menu items can be broken down into logical units and organized to form a hierarchy of main and submenus. Submenus are identified in a menu file by a label of the form **name where name is a valid character string. Submenus can be activated or deactivated using the following construct:
$S = submenu_name ; for screen submenu
$Pn = submenu_name ; for pop up menu where n between 1-10
The latest version of AutoCAD supports another, more sophisticated form of user input device known as a dialog box. Dialog boxes may include: buttons, sliders, small images and further sub-dialog boxes. They are a convenient way for the user to set variables and start functions. As is the case with standard menus, users can also define their own dialog boxes. Files that define dialog boxes must be written in a special programming language called "Dialog Control Language" (file extension .dcl). The following is a short introduction to dialog box description and a simple example. The example is also available in img_dialog.lsp and 07_img_dialog.dcl. (Another example, 07_list_dialog, is also available in the same directory.). Further examples and references can be found in the book "Das grosse AutoCAD 12 Programmierbuch".
Dialog boxes can contain: rows and columns, buttons, toggle switches, sliders, text elements, edit boxes, images and other devices. They can be represented with nested blocks.
+---------+This figure shows the nested hierarchy of the following example (07_img_dialog.dcl). The file describes the contents of the dialog box and how the elements are arranged.| dialog |
| +----+----+
| | row |
| | +----+----+
| | | column |
| | | +----+----+
| | | | image |
| | | | image |
| | | +----+----+
| | +----+----+
| | row |
| | +----+----+
| | | column |
| | | +----+----+
| | | | image |
| | | | image |
| | | +----+----+
| | +----+----+
| |ok_button|
| +----+----+
+---------+
/* Sample dcl file for creating dialog box with images. Actual slide images are set up in the Lisp file. hello: name of the dialog box. */ hello:dialog { label = "Select data category"; /* Title of dialog */ :row { :column { :image_button { key = "img_button1"; /* name of image button */ width = 7; aspect_ratio = 1.0; allow_accept = true; color = 0; } :image_button { key = "img_button2"; /* name of image button */ width = 7; aspect_ratio = 1.0; allow_accept = true; } } :column { :image_button { key = "img_button3"; /* name of image button */ width = 7; aspect_ratio = 1.0; allow_accept = true; } :image_button { key = "img_button4"; /* name of image button */ width = 7; aspect_ratio = 1.0; allow_accept = true; } } } ok_cancel_help; /* predefined tile with three buttons */ }In order to control a dialog box from your program and to get results back from it, some lisp functions must be invoked, usually from a menu option. The next example shows a possible lisp implementation for the previously described dialog box.
(defun c:imageButtonSample ( / dcl_id pickf ret_val prevB) ;dcl_id: dialog ident ;ret_val: result of dialog box (cancel/accept/help) ;pickf: selected image button ;prevB: previous image button (setq dcl_id (load_dialog "07_img_dialog.dcl"));load dcl file (if (not (new_dialog "hello" dcl_id)) ;open the dialog (exit)) ;check if it succeeded ;Get the height and width of image button (setq x (dimx_tile "img_button1") y (dimy_tile "img_button1")) ;Assign slide file to button using the next three functions (start_image "img_button1") ;name of image button (slide_image 0 0 x y "img_sample1") ;slide file name (end_image) ;end of specification (mode_tile "img_button1" 0) ;set the state of tile (start_image "img_button2") (fill_image 0 0 x y 1) (end_image) (start_image "img_button3") (fill_image 0 0 x y 2) (end_image) (mode_tile "img_button1" 0) (start_image "img_button4") (slide_image 0 0 x y "img_sample2") (end_image) (setq prevB nil) ;Selected image button key is assigned to 'pickf' string ;flip_button defined in file: ;/homes5/prog/ausgabe/07_img_dialog.lsp (action_tile "img_button1" "(setq pickf $key) (setq prevB (flip_button 1 prevB))") (action_tile "img_button2" "(setq pickf $key) (setq prevB (flip_button 2 prevB))") (action_tile "img_button3" "(setq pickf $key) (setq prevB (flip_button 3 prevB))") (action_tile "img_button4" "(setq pickf $key) (setq prevB (flip_button 4 prevB))") ;For the predefined tile, use 'done_dialog' ;(predefined) function to return an integer value (action_tile "cancel" "(done_dialog 0)") (action_tile "accept" "(done_dialog 1)") (action_tile "help" "(done_dialog 2)") ;to insert our help file as a dialog box, it will need a ;modification (action_tile "help" ; "(help_dialog1 \"help.hlp\" \"appload\")") (setq ret_val (start_dialog)) ;run the dialog box ;use returned value for further processing (unload_dialog dcl_id) ;close dialog window ;evaluate the results from the dialog box (cond ((= 0 ret_val) (princ "Action cancelled...") (print)) ((= 1 ret_val) (princ "Extracting selected data...") (print))) (if pickf (princ (strcat "Selected items: " pickf)) (princ "No selections made...") ) (print) )
Menu G_Design with following menu options:
You are required to submit your program: 07_name.lsp and all related interface files, including the menu file: 07_name.mnu.
Next | Titel | Inhalt | Vorwort | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | Appendix | @ CAAD | Teachers |
This website has been archived and is no longer maintained.