Kapitel 8

AutoCad II: Datenbank und Kontrolle


8.1 Database Management

A database is a collection of ordered data. A database management system (DBMS) is a tool to manipulate the data in the collection. Sometimes, data are used to represent something in the real world, namely, to be an abstraction. A real world problem can then be simplified and hopefully be solved by manipulating the abstraction. A database system consists of ordered data and operators which manipulate the data.

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:

Data elements
drawing entities
lines, plines, texts, circles, dimensions....
Data structure
specific to AutoCad developed by programmers
Data operators for retrieval
select, list, zoom, layer, dview, vpoint, vports....
Data operators for modification
line, pline, text, circle, insert....
layer, rotate, move, change, color, break, trim....

8.1.1 AutoCad Blocks

One specific drawing element supported in AutoCad is called a block and it can be used an example to understand the concepts of DBMS. A block is a collection of geometric and non-geometric information. Like a function in LISP, a block has a set of parameters which are assigned values when the block is inserted. Scaling factors, insertion point, and rotation angle are predefined as parameters for all blocks, and they are used to describe the preferred geometric transformation for the original block definition. Additional non-geometric parameters can be defined using attributes, when blocks are to be used as basic elements to build a customized database.

Geometric data
insertion point, rotation, scaling, and body definition.
Non-geometric data attributes
mode: visible, constant, verify, preset.
tag: the name of the attribute
value: the value of the attribute
prompt: the prompt to the user
Data operators retrieve information
attext
Data operators modify information
block, wblock, insert
attdef, attedit

8.1.2 AutoCad System Variables

Additionally, AutoCad environment is globally managed by an extensive number of system variables. These variables and their values may affect drawing operations.

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.

8.2 Developing a Database

In many situations, it is desirable to create a customized database specific to a task at hand. This can be achieved using a few LISP primitives, namely association lists to define and create data elements and their structure, assoc primitive to retrieve data, and subst primitive to modify data.

8.2.1 Association Lists

In LISP programming, we generally use symbols and assign values to them; whenever we refer to the symbol, we actually access its value. We can also group symbols and their values, and access them or modify them together by using association lists.

An association list is a list of embedded sublists, in which the first element of each sublist is a key.

8.2.1.1 Setting up an association list

Following creates an association list assigned to a variable BRICK1, with its sublists made up of a key (also known as property) and its value.

In the above example, color, supported_by and size are keys or properties.

8.2.1.2 Accessing an association list

To access the value of any property of such lists, procedure assoc is used:

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:

Note that assoc returns the entire sublist, not just the value of specified key.

8.2.1.3 Modifying an association list

Association lists can be modified using procedure subst with three arguments:

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:

8.2.2 Dotted Pairs and cons function

So far, we have seen lists expressed as left parenthesis, one or more atoms, and right parenthesis. There is another kind of list in LISP which is made up of what are known as dotted pairs of atoms.

Generally, cons function takes an atom or a list and inserts it into another list:

It is also possible to use cons to join two atoms into a list: This notation is referred to as dotted pairs and should be used carefully.

8.2.3 File I/O in AutoLisp

In order to save and retrieve data, you can use external files. Before you can read or write to an external file, you need to open them as follows:

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. Other useful file related functions are:

8.3 Uebung 8

In this exercise, you will use AutoLisp to define and manipulate a small database of construction elements.

Types of construction elements can be defined by specifying their geometric definitions and setting any predetermined values for their parameters. The program 08_objects.lsp in the ausgabe directory provides a set of functions that create primitive geometric objects such as cubes, cylinders, and wedges. These geometric objects can be used to represent construction elements such as columns and beams.

Your task is to enable users to: 1. Define different types of construction elements and 2. Retrieve the properties of types in order to be able to instantiate them in a model. For example, a user should be able to define a column type with a 30 by 40 cm rectangular section called "column1". The definition of this type will then be used to instantiate numerous instances of column1, without having to specify any of the predetermined properties for each instance. The user should also be allowed to leave the value of any number of parameters undetermined when defining a type. Those undetermined values will be requested at the time of instantiation.

The main task of this program is to store, retrieve and modify the definitions of types. You will need to define an internal representation of the database to store this information. Association lists are recommended for this purpose. It is required that you use the functions in 08_object.lsp to draw the construction elements. You are expected not to modify that program or replace it with your own. Note that it is not necessary to copy the file into your own program. It is better to simply load the program by providing the path and name of the file. An additional challenge that you may attempt, though it is not required, is to consider that new geometric objects may be added to the file 08_object.lsp after you have finished your program. Without having to modify your program, users should still be able to define types of construction elements using those new geometric objects. Hints on how this might be done are provided in the 08_object.lsp file.

At least four functions have to be provided by your program. The first one called c:addtype should allow users to define and add types to the database. The second function is c:removetype, with which users can remove the definition of a type from the types database. (This will have no effect on any instances of that type which may already exist.) The third function, c:listtypes lists the names of all of the defined types and allows users to inquire about details of one or more of these types. Finally, c:construct is the function that enables users to instantiate the predefined types. Develop your program in small steps. Design the list(s) in which you want to store data. Then write functions to access and modify the list(s). Develop the functions that take care of user prompts and input. Name your file: 08_name.lsp and submit it by copying it into the directory: /homes2/prog/abgabe.


To the next chapter

Prog Content Vorwort ..1.. ..2.. ..3.. ..4.. ..5.. ..6.. ..7.. ..8.. ..9.. ..10.. ..11.. ..12.. ..13.. Appendix


@ by Architektur und CAAD 1994.......... The Teacher Team