Chapters 7 and 8. Data entry/File operations

Chapter 7.  Data entry

AutoLISP has a number of user data entry functions using the AutoCAD command line. These functions are identified by their names that start with the prefix get. This is not the only way to communicate with the user. Applications increasingly tend to display dialog boxes where, instead of sequentially entering the data, the user can select the appropriate options from various types of controls such as text boxes, action buttons, image buttons, etc.
We will cover in this chapter the command line entries, which is how AutoCAD commands traditionally operate. Future chapters will discuss the implementation of Graphical User Interfaces (GUI) using two procedures: dialog boxes programmed in DCL language and OpenDCL, an open source application platform for Visual LISP that implements the use of Windows user interface components.
Almost all the get... functions accept changes in their behavior regarding the support of keywords as an alternative to their specific data type and as a way to control the permissible user input. These changes in their behavior are set using the initget function, which must be called immediately before.
There are also techniques that allow the programmer to include default values that are accepted by pressing ENTER.
This Chapter shows how to define user input functions that include either default values or keywords for any of the get... functions in which this behavior is accepted.
Unlike other get... functions, getfiled displays a dialog box instead of command line prompts.
GETFILED dialog box.

Both initget and getfiled support arguments encoded as binary values. This technique is widely used in the definition of AutoCAD object properties. In this chapter we have defined procedures used in working with these binary values that will be used in the following chapters, as the use of binary logical operators has been scarcely explained in AutoCAD’s LISP programming documentation. Its importance and possible applications are inversely proportional to the scarce attention devoted to it. Its use allows controlling a multitude of application parameters encoded as binary numbers of which initget is only one example.
The logical operations on binary numbers available in Visual LISP are four:
  • logand (logical binary AND)
  • logior (logical binary OR)
  • ~ (binary NOT)
  • boole (general binary logical operator)
To these operations we must add the lsh function, binary shift, as a means to calculate the decimal values corresponding to each bit. Of these the most used functions are logand and logior.

Chapter 7 includes the following sections:

7.1. Integrated error control.
7.2. Default values.
7.3. Prompting for data with options.
7.4. Input control through INITGET.
7.5. Data coded as binary values.
7.6. File search dialog box.
7.7. Summary

Chapter 8. File operations

For its use in other work sessions or to transfer data to other applications it may be necessary to store information generated by programs in external files. Visual LISP provides functions to read and write external text files and for locating files or folders in our computer or in a network environment. This chapter is dedicated to exploring these operations.
In this chapter we consider how to write and read text files from Visual LISP. The process begins both for reading and for writing by opening the file using the open function in any of the supported modes, read, write or append. Key aspects to remember are the following:
  • The file descriptor returned by open should be assigned to a variable so it can be used for processing the file. Once the file has been processed it must be closed using the close function. Any new content that is included in the file will not be written to disk until it is closed.
  • File reading is always performed sequentially, either character by character with read-char or line by line with read-line.
  • For writing to files there is a greater variety of functions, which allow writing to a file or to the console or the command line.
The composition of the character sequences to be written requires knowing the string handling functions and those used to convert other data types to strings. Special attention is deserved by the functions that convert numerical data which can affect the accuracy of the calculations made using these values. The use of the rtos function in this context is demonstrated.
Finally we will study the functions related to the construction of valid file and folder names and how to check whether these files already exist in our system.

Chapter 8 includes the following sections:

8.1. Opening files.
8.2. File reading.
8.3. Writing files.
8.4. Files and Folders.
8.5. Summary

Your questions or comments about these Chapters' contents are welcome!

Buy this book from CreateSpace eStore

No comments:

Post a Comment