Download Auto LISP Application Documentation - Lecture Notes | GY 461 and more Exams Geology in PDF only on Docsity!
by David T. Allison
Introduction
This document explains the purpose and usage of several AutoLISP applications designed by
David Allison for generating diagrams useful in the Earth Sciences. These applications can be
easily modified for other purposes outside of the realm of Earth Science. The specific purpose and
usage of each application is described below, however, there is a certain degree of modification
necessary to the AutoCAD operating environment before they are ready to use. Each application
may call procedures contained in several “libraries” of commonly used functions. A variable
containing the file path to the directory where these files are located must be defined before one of
the applications can be executed.
Installing the Applications
When you download the AutoLISP applications from the web site your are actually downloading
a single compressed file named “DTA_AutoLISP.zip” that contains all of the individual source
code files. Create a folder where you wish for the applications to reside, copy the ZIP file to this
folder, and then double-click on the ZIP file while in file explorer to un-compress and extract the
files to that folder. For example, I keep all of the LISP applications in this folder:
e:\acadmapdata\lisp
For the purposes of this document I will use this path as an example.
If file explorer does not extract the files you may not have ZIP file capability installed on your
computer. If so, search for the keyword “WinZip” with your web browser until you locate this
utility, and then install it.
The LISP applications described in this document have been tested using AutoCAD 2000.
Different versions of AutoCAD are generally compatible with LISP applications, however, you
may have to modify the setup procedures described below if you are using a different version. For
demonstration purposes I will assume AutoCAD 2000 is installed on the computer.
When AutoCAD 2000 is started, it looks for a file named “acad2000.lsp” (release 14 looks for
“acadr14.lsp”) and automatically loads and executes the statements in it. For this reason, this file
is an ideal mechanism for initializing the file path variable that will point to files used by the LISP
applications. Use Windows file explorer to search for the “acad2000.lsp” file. When found,
double-click on the file name. This will load the source code into notepad. Add the following line
as the last line in the file:
by David T. Allison
(Load “c:/acadmapdata/lisp/acadinit.lsp”)
Of course, you should modify the above file path to match your particular situation. For example,
your primary hard disk drive may be “e:” rather than “c:”. Save the changes to this
“acad2000.lsp” file, and then use the notepad “File > New” menu to clear the screen. We now
need to create the “acadinit.lsp” file. Type the following line:
(setq #LispDir "c:/acadmapdata/lisp/")
Note that AutoLISP uses the forward slash “/” to separate folder names in a file path. The above
line instructs AutoCAD to save the directory path to the LISP files into a variable named
“#LispDir”. The LISP applications use this variable to find the various library files, therefore, it
must be initialized when AutoCAD starts. Now you should save this file as “acadinit.lsp”, and
save it to the folder indicated in the “acad2000.lsp” file (in this example “c:/acadmapdata/lisp/”).
The next time AutoCAD Map is started the “Acad2000.lsp” file is automatically executed. The
load statement that has been inserted into this file will cause “Acadinit.lsp” to be loaded also, and
that initializes the “#LispDir” variable.
As a test, start AutoCAD and wait for the command prompt. Type the below expression:
command: !#LispDir
You should see AutoCAD respond with the path entered into the “acadinit.lsp” file:
"c:/acadmapdata/lisp/" {i.e. whatever path you entered into Acadinit.lsp}
You are now ready to run the applications included in this package. If you have trouble setting up
the applications on your system, try contacting me for help.
David Allison
Dept. of Earth Sciences
136 Life Sciences Bld.
University of South Alabama
Mobile AL 36688
phone: (251)460-
Executing AutoLISP Applications
Starting AutoLISP applications begins with the “Tools > Load Application” menu sequence. The
by David T. Allison
query, and the application will insert geological planar and linear structures as oriented symbols
into a geologic drawing file. The application can also insert markers that locate a sample position,
and annotate the symbol with the sample I.D. code. The symbols are inserted as blocks, so the
user has full control over the design of the symbols, and their size in the drawing.
In interactive mode the user may save the coordinates of projected geodetic values to a series of
variables that can be used in the current session, or saved to disk to be recalled in a later session.
For example, suppose you need to calibrate a 1:24,000 quadrangle into the UTM coordinate
system. The base map does not have UTM grid lines, only the standard blue tic marks on the
border. Therefore, unless you draft the grid yourself, there are no calibration points on the map
where both UTM x and y coordinates are precisely known. In this situation MAPPRO can be used
to calculate and store the UTM coordinates of precisely known geodetic coordinates, for
example, the corners of the quadrangle map border. If MAPPRO is run in interactive mode, and
the user indicates that he or she wishes to store calculations in variables, a series of variables
named pt1, pt2, pt3, etc., will be created containing the x and y values in the same order as
entered. If you type in the geodetic coordinates of the SW corner first, pt1 will contain the
projected coordinates. Whenever you need to refer to those coordinates in an AutoCAD Map
command, simply preface the variable name with the exclamation mark (!). For example, the
“TABLET > CAL” command could use the point variable values when the coordinates of the
digitized control point are requested. This has the distinct advantage of avoiding the typing of
large UTM coordinate values where typographical errors are easily made.
MAPPRO uses the following library LISP files:
PROJLIB.LSP- map projection functions
MATHLIB.LSP- common mathematical functions
FILELIB.LSP- file handling functions
STRLIB.LSP- string handling functions
The MAPPRO program, and the above library files should reside in the subdirectory pointed to by
the “#LispDir” variable. This variable is normally set in the “acadr14.lsp” or “acad2000.lsp” file,
or a LISP file loaded by “acad2000.lsp” (see discussion of installing the applications above).
Supported map projections include:
Universal Transverse Mercator
Lambert Conformal Conic
Transverse Mercator
Alber's Equal Area
Polyconic
Mercator
by David T. Allison
Latitude-Longitude data formats include:
1. Degrees, minutes, and seconds ("DMS") > ex. "-33 15 30.2"
2. Decimal degrees ("DD") > ex. "-123.56798"
3. Radians ("R") > ex. "1.578943"
MAPPRO Example Sessions
Interactive Mode
Load the MAPPRO application using the “Tools > Load Application” menu. Find the
“mappro.lsp” file in the folder where you deposited the downloaded LISP files. Load the file with
the “Load” button in this dialog. Make sure that the “#LispDir” variable points to the directory
containing LISP library files (“ProjLib.lsp”, “FileLib.lsp”, etc.). You can test the “#LispDir”
variable by typing this command at the AutoCAD Map command line:
Command: !#LispDir
“c:/acadmapdata/lisp/” (this is the response by AutoCAD Map)
If the response is “nil”, or points to the incorrect folder, the setup of the “Acad2000.lsp” file is
not correct. You can set the value manually with a LISP expression:
Command: (setq #LispDir “c:/acadmapdata/lisp/”)
However, you should fix any “Acad2000.lsp” setup problems so that the path is correct whenever
AutoCAD Map starts (see above description).
Below is the input and responses of an interactive MAPPRO session. In this session 4 point
variables are set to the UTM coordinates of the corners of a 1:24,000 quadrangle. After this
session the variables pt1, pt2, pt3, and pt4 could be used, for example, to calibrate this map to the
UTM coordinate system using the geodetic corners of the quadrangle map. Note that input typed
by the user is in boldface type. The “” represents the pressing of the “Enter” key (also
known as the “Return” key).
Command: mappro
| MAPPRO Utility Program | | Map projection program to plot station locations or structural geology | | data upon base maps digitized with one of the supported map projection | | coordinate systems. | | | | Copyright (c) 2001 | | by David T. Allison |
by David T. Allison
--> X: +558,468.84 Y: +3,637,411.
Current format is [+/-]DDD MM SS.SS [+/-]DDD MM SS.SS. Enter latitude and longitude: 32 52 30 -86 15 0
--> X: +570,162.86 Y: +3,637,488. Current format is [+/-]DDD MM SS.SS [+/-]DDD MM SS.SS. Enter latitude and longitude: ****
Variables are stored as pt1, pt2, etc., in file: E:/ACADMAPDATA/Ala-geo/rc-calib.lsp Load point variables (Y/N) [Y]: y
Variables are saved in file: E:/Acadmapdata/Ala-geo/RC-geo.lsp You can now use the point variables in AutoCAD expressions. Preface a variable such as pt1 with an exclamation mark, for example [zoom !pt1 !pt4] would zoom window to the coordinates of pt1 and pt4. You can re-call the point variable definitions by using the LOAD command and indicating E:/Acadmapdata/Ala-geo/RC-geo.lsp as the LISP file to load. This will initialize the point variables for the current edit session. any key continues... ****
(P)ost data, (I)nteractive session, or (Q)uit[I]: q
Run MAPPRO again (Y/N) [N]: n
Command: !pt1 (558551.0 3.62355e+006)
The last typed command simply recalls the value of point variable #1. At this point the user could
use the 4 point variables to calibrate the map to the UTM coordinate system. Note that the
coordinates of each point entered interactively is stored to disk as a LISP (.lsp) file that may be
loaded at any time. For example, the next time the above map needs to be calibrated to a digitizer,
the file “E:/ACADMAPDATA/Ala-geo/rc-calib.lsp” could be loaded as a LISP application, at
which time the point variables stored in the file (pt1, pt2, etc.) become defined and usable.
Point variables, like any LISP variables, persist only through the current session. Therefore, if you
load a different file into the current active window, or shut down AutoCAD Map, the variables
will be undefined.
Post from File Mode
MAPPRO was primarily designed to post large batches of data onto digital base maps.
Furthermore, if the data consists of planar or linear geological structure data, MAPPRO rotates
the structure symbol into the proper attitude and labels the dip/plunge attribute with the proper
value. MAPPRO can also simply post a symbol at a location and label it with an identifier. Most
often, the location and structure data are stored in database or spreadsheet applications such as
Microsoft Access® and Excel®. In this way the user can conveniently construct a database
by David T. Allison
“query” to collect a subset of the data. For more information please visit the below web sites:
http://www.usouthal.edu/usa/geography/allison/gy461/gy461_DatabaseCreation.pdf
http://www.usouthal.edu/usa/geography/allison/gy461/GY461_InsertingStructure.pdf
When a query file has been saved as a text file (usually with WordPad), you can then run
MAPPRO in “post from file” mode. Before doing so, however, you should check to make sure
that any block references made by the text file are defined in the current drawing. There are
several ways to do this. Perhaps the best way is to use the template file “Map_Prototype.dwg”
(included in the download file) to start your file. If you have already begun the base map, save the
template as a regular drawing file (.dwg), and then insert it into the base map. The block
definitions contained in the template will then be available in the current base map drawing.
Below is a session in MAPPRO where the data in the file “RC-S1.TXT” is inserted into the
Richville, Alabama, 1:24,000 scale quadrangle. The text file was created by a query within Access
and the first several lines are listed below:
;Latitude Longitude ATTITUDE Station
32.797278 -86.250444 N 7 E 27 E E
32.795028 -86.252222 N 43 W 23 W E
32.792583 -86.256556 N 40 E 45 W E
32.817361 -86.250361 N 77 E 41 E E
32.751139 -86.264889 N 24 E 42 E E
32.845833 -86.262944 N 10 W 50 W R
32.846667 -86.261417 N 25 W 77 W R
Note that the first line is a comment line because of the “;” (ignored by MAPPRO), and that the
locations are in decimal degrees latitude (first) and longitude. The attitudes are for S1 foliation
(planar). Below are the prompts and responses for posting this data file onto the digital base map.
Command: mappro
============================================================================ | MAPPRO Utility Program | | Map projection program to plot station locations or structural geology | | data upon base maps digitized with one of the supported map projection | | coordinate systems. | | | | Copyright (c) 2001 | | by David T. Allison | | Dept. of Earth Sciences | | University of South Alabama 36688 | | (251)460-6381 |
by David T. Allison
Specify rotation angle : 79. Command: "processing line:3" INSERT Enter block name or [?] : S1 Specify insertion point or [Scale/X/Y/Z/Rotate/PScale/PX/PY/PZ/PRotate]: Enter X scale factor, specify opposite corner, or [Corner/XYZ] <1>: 200.0000000000000 Enter Y scale factor : 200. Specify rotation angle : 15. Command: "processing line:4" INSERT Enter block name or [?] : S1 Specify insertion point or [Scale/X/Y/Z/Rotate/PScale/PX/PY/PZ/PRotate]: Enter X scale factor, specify opposite corner, or [Corner/XYZ] <1>: 200.0000000000000 Enter Y scale factor : 200. Specify rotation angle : 155. Command: . . . {until end of data}
Command: zoom Specify corner of window, enter a scale factor (nX or nXP), or [All/Center/Dynamic/Extents/Previous/Scale/Window] : extents Command: REGEN Regenerating model.
Command: (P)ost data, (I)nteractive session, or (Q)uit[P]: q
Run MAPPRO again (Y/N) [N]: n
You should now see the structure symbols appear in the current layer of the drawing. Figure 4
displays a zoomed in view of several of the S 1 structure symbols. Note that the structure symbols
are automatically oriented according to the attitude in the input file.
LLGRID Application
The LLGRID application is designed to construct a latitude and longitude grid based on common
map projections (Polyconic, Mercator, etc.). For example, if you need to construct 7.5 minute
quadrangle boundaries over the latitude range of 32 through 34 degrees, and longitude range -
to -84 degrees, this application can do the job. When active LLGRID will prompt for the
“resolution” of the grid- this controls the segment length of each grid line. In the above example,
if 2.5 minutes is set as the resolution, then each side of each 7.5 minute quadrangle is composed
of a polyline made of 3 segments of 2.5 minutes.
Below is a session with LLGRID. You should first load LLGRID as you would any other LISP
application (see description above for MAPPRO loading):
Command: llgrid
| LLGRID UTILITY | | |
by David T. Allison
| Utility program for constructing a latitude-longitude grid system based | | upon the supported map projections: 1) Polyconic; 2) Transverse mercator; | | Universal transverse mercator; 4) Mercator; 5) Alber's equal area; and 5) | | Lambert conformal conic. All are based on NAD27 map datum. | | | | by: David Allison Copyright (c) 2001 | | Dept. of Earth Sciences | | University of South Alabama | | Mobile, AL 36688 | | E-mail: [email protected] | | (251)460-6381 | =============================================================================
NOTE: western hemisphere longitudes and southern hemisphere latitudes must be entered as negative values in the degrees field.
(U)TM, (T)M, (P)olyconic, (C)onformal, (M)ercator, or (A)lber's[U]: u
Enter the UTM grid zone [16]: 16
Data in northen or southern hemisphere (N/S) [N]: n
Output coordinates in (M)eters or (F)eet [M]: m
Enter relational fraction for map scale (ex. 1:1) [1:1.00]: 1:1
Enter the long. spacing in [+/-]DDD MM SS.SS format: 0 7 30
Enter the lat. spacing in [+/-]DDD MM SS.SS format: 0 7 30
Enter the long. resolution in [+/-]DDD MM SS.SS format: 0 2 30
Enter the lat. resolution in [+/-]DDD MM SS.SS format: 0 2 30
Enter the lower left (SW) map corner latitude-longitude. [+/-]DDD MM SS.SS [+/-]DDD MM SS.SS]: 32 0 0 -86 0 0
Enter the upper right (NE) map corner latitude-longitude. [+/-]DDD MM SS.SS [+/-]DDD MM SS.SS]: 34 0 0 -84 0 0
{The application will construct the grid at this time}
The map in Figure 5 displays the latitude and longitude grid constructed by LLGRID with the
above settings. Each segment is not joined, however, they can be joined with the “pedit > join”
command from within AutoCAD Map if so desired.
TRIANGULAR Application
The triangular diagram application “TRIANGULAR” is designed to plot data onto a triangular
type of graph. Included with the downloaded ZIP archive are several template files:
Ternary_Diagram.dwt basic ternary graph background
by David T. Allison
Change the base length value (Y/N) [N]: n
The current x,y position of the lower left apex of the ternary diagram is 1.50,0.75, change this (Y/N) [N]: n
Plot ternary diagram border (Y/N) [Y]: n
Plot ternary plotting grid (Y/N) [N]: n
Plot data from file (Y/N) [Y]: y
begin Below should be the names of the data column labels for the selected file.... 1: A% 2: P% 3: Q% 4: SAMPLE If there is an error in the file, type to end program, otherwise, continue to the next prompt by typing any key... ****
NOTE:1st index(x)=lower left; 2nd(y)= lower right; 3rd(z)=upper apex. Default x,y,z column indeces are 1,2,3; change indeces? (Y/N) [N]: n
Use a column to specify size of data symbol (Y/N) [N]: n
Use a column to specify block symbol name (Y/N) [N]: n
Use a column to specify data label (Y/N) [N]: y
Enter column number: 4
Enter the default size of data symbols [0.069]: 0.075
The default data text label scale factor is 1. which would produce labels 0.11 units tall. Change this value (Y/N) [N]: n
Enter the missing value flag [-99.000]: -99
Plot data headers as apex labels (Y/N) [Y]: n
{The application proceeds to plot data at this point}
The user should note that “Triangular “ can easily read a data file with many columns and use any
three as the data. The first column index is always plotted relative to the lower left apex, second
column index relative to the lower right apex, and the third column index relative to the upper
center apex. In this particular case, since the predefined template had “A” as the lower left, “P” as
the lower right, and “Q” as the upper middle apex, the first index should equal the “A” column,
the second index should be the “P” column, and the third index the “Q” column. Since the data
file contained only three numeric columns in A, P, Q order, the default indices of 1, 2, and 3 is
correct for this example. The fourth column contained the data point identifier. Figure 6 displays
the final diagram with data plotted.
by David T. Allison
Figure 1: Load application dialog in AutoCAD 2000.
by David T. Allison
Figure 3: File open dialog for selecting the structure data input file for
MAPPRO.
by David T. Allison
Figure 4: Structure data posted into the 1:24,000 geologic quadrangle base map with
MAPPRO.
by David T. Allison
Figure 6: Triangular diagram with IUGS A-P-Q apices and data plotted.