Package a data file in VLISP31 Jan, 2003 By: Barry Bowen
Compile data in text files along with your Visual LISP applications.
AutoCAD's Visual LISP feature offers the ability to return the text stored in a TXT file when packaged in a VLX application. A VLX file is compiled set of one or more AutoLISP and DCL (dialog control language) files that you can create using AutoCAD's Visual LISP environment. At first I was excited about this capability, but that excitement soon faded when I learned that the text files were returned in their entirety and not, as I had expected, as bits of data from a data file. However, I discovered a method that lets you access discrete data and still take advantage of VLX packaging for your AutoLISP routines.
For the data file to be usable as data when returned by the (vl-get-resource) function, the data file must be formatted in a way that identifies the specific lines of data and allows the program to extract only the required items.
The format is the same as data files I've used in the past, with one exception. The entire data file becomes one long list, instead of each line a list, as shown in the two examples that follow.
PREVIOUS DATA FILE FORMAT
("010" "1.5" "12.75" "0.375")
("020" "3.5" "14.50" "0.675")
("030" "4.5" "16.75" "0.875")
NEW DATA FILE FORMAT FOR VLX PACKAGING
("010" "1.5" "12.75" "0.375"
"020" "3.5" "14.50" "0.675"
"030" "4.5" "16.75" "0.875")
GETTING THE DATA
Once the text file is packaged in the VLX application, data is returned via the (nth) function. First, the routine returns the list and assigns it to a variable:
(setq DATA_LIST (vl-get-resource "datafile"))
(vl-get-resource) returns the data list as a text string, so you must convert it to a usable list with the following line of code:
(setq DATA_LIST (read DATA_LIST))
Now you can use the (nth) function to process the list. To extract the data associated with the item "020," for example, use the following expressions:
(setq ITEM_ID (nth 4 DATA_LIST))
(setq ITEM_01 (nth 5 DATA_LIST))
(setq ITEM_02 (nth 6 DATA_LIST))
(setq ITEM_03 (nth 7 DATA_LIST))
FIND DATA WHEN ITS LOCATION ISN'T KNOWN
Another method for extracting data when the location of the item ID may not be known uses the following loop:
(setq IN 0 ID# "020")
(while (/= ITEM_ID ID#)
(setq ITEM_ID (nth IN DATA_LIST))
(setq IN (1+ IN))
Once the routine locates the item ID in the (while) loop, it extracts the data associated with the specific item ID:
(setq ITEM_01 (nth IN DATA_LIST))
(setq ITEM_02 (nth (1+ IN) DATA_LIST))
(setq ITEM_03 (nth (+ 2 IN) DATA_LIST))
PACKAGING THE FILE
To package the data file in a VLX application, start the New Application wizard found under File | Make Application in AutoCAD's VLISP menu. Select the Expert mode (figure 1), then progress to the Resource Files to Include tab (figure 2).
Figure 1. Be sure to select Expert mode for the Make Application wizard so you can include additional resource files.
Set Text files as the active selection, and then select the data file you want to include.
Continue on in the wizard and make the application, and the data file is packaged in the resulting VLX application file.
Create Professional 3D Models Anywhere - Shapr3D is an industrial-strength CAD tool that runs natively on your iPad. Import and Export files from most major desktop applications. Find out more and download a free copy here!
Running AutoCAD? Test Your Hardware! Designed to test and compare the performance of systems running AutoCAD, Cadalyst's Benchmark Test is a popular and long-time favorite.