Lecture 7
1 / 40

Lecture 7 - PowerPoint PPT Presentation

  • Updated On :

Lecture 7. The Arc Macro Language. This Lecture. What is AML? Command line ArcGIS. Some basic concepts. Using variables and functions. Controlling program flow. Graphical User Interfaces (GUIs). Textbook.

Related searches for Lecture 7

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Lecture 7' - latona

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Lecture 7 l.jpg

Lecture 7

The Arc Macro Language

This lecture l.jpg
This Lecture

  • What is AML?

  • Command line ArcGIS.

  • Some basic concepts.

  • Using variables and functions.

  • Controlling program flow.

  • Graphical User Interfaces (GUIs)

Textbook l.jpg

  • ESRI’s “ARC Macro Language: Developing ARC/INFO Menus and Macros with AML Self-study Workbook: Version 7.1.1 for UNIX and Windows NT”

What is aml l.jpg
What is AML?

  • A simple programming language in a text file.

    • Interpreted not compiled.

    • Runs in the order that commands, directives, etc. appear in the program.

  • A way to automate tedious tasks in ArcGIS.

  • A way to write (“old skool”) interfaces.

  • Allows you to write programs that:

    • manipulate ArcGIS objects such as Coverages and INFO files;

    • customise ArcGIS applications;

    • increase productivity.

Example tasks l.jpg
Example Tasks

  • Running batch jobs.

  • Automating frequently performed tasks.

  • Combining two or more existing commands to create a new one.

  • Creating menu driven interfaces.

  • Integrating spatial models with ArcGIS.

  • Standardising procedures for other people.

A simple example l.jpg
A Simple Example


&typeCreating coverage topology

build buildings poly

clean buildings

&type Hello World!


Arc: &runprogram.aml

  • At its most basic an AML program is just a list of ArcGIS commands. You can usually guess the Arc command from the ArcDesktop tool’s name.

  • With some ArcDesktop tools there’s a Save to AML button. This gives an AML file you can edit or copy from.

Parts of aml l.jpg
Parts of AML

  • Arc Commands

    • build, clean, etc.

  • Variables - delimited by %%

    • %i%, %cover%

  • Functions - delimited by [ ]

    • [exists %cover% -point]

  • Directives - preceded by &

    • &return, &type, &if, &goto, etc.

  • Comments - preceded by /*

    • /* I ‘heart’ ArcGIS (as in ‘stab in the…’).

Syntax l.jpg

  • AML isn’t case sensitive.

  • But remember, some parts of ArcGIS are, so if you are using AML to pass it commands, the commands need to be the right case.

  • Some directives have abbreviations.

    &setvar cover = landuse

    &sv cover = landuse

    &s cover = landuse

Basic layout l.jpg
Basic Layout

/* bldcln.aml

&echo &on

build roads line

clean roads ~

roads_c # # line

build stations point

build urban poly

clean urban


Arc: &run bldcln.aml

  • &return ends the program and returns to the command line.

  • &echo &on will write the commands on the screen as they are done. &echo &off will stop this.

  • “~” continues commands onto the next line. The bold lines above are all one command.

Variables l.jpg

  • Like a name you can attach to a value or set of text.

  • Variables are set using &setvar directive.

    &sv cover := landuse

    &sv cover = landuse

    &sv cover landuse

  • Variables store 4 data types.

    • Character string, e.g. “buildings”

    • Integer number, e.g. 23

    • Real number, e.g. 4.242

    • Boolean value, can be .TRUE. or .FALSE.

  • &listvar(&lvor&l) displays list of currently assigned variables.

Using variables l.jpg
Using Variables

  • When using Variables they’re delimited by % %except when being assigned.

    &sv cover = landuse


  • Variables can be used together.

    &sv cover = landuse

    &sv infotab = pat

    &sv item = landuse_type

    dropitem %cover%.%infotab% %cover%.%infotab% %item%

    Which is the same as...

    dropitem landuse.pat landuse.pat landuse_type

Local vs global variables l.jpg
Local vs. Global Variables

  • So far we’ve looked at Local Variables that work in a single AML script.

  • However, you can define Global Variables that work throughout an Arc session.

  • Global Variable names begin with a fullstop/period (.)

    &sv .cover = landuse

    build %.cover% poly

  • &listlocal and &listglobal directives do just what they say.

Reserved variables l.jpg
Reserved Variables

  • These contain information held internally by the system including information about:

    • data (DSC$)

    • the graphical cursor/pointer (PNT$)

    • the status of AML programs (AML$)

      DSC$FUZZY : fuzzy tolerance.

      PNT$X : x co-ordinate selected.

      AML$FILE : the current file being run.

  • Don’t assign these yourself.

  • See ArcDocs > Customizing ArcInfo > AML > Using Variables > Reserved Variables

Using reserved variables describe l.jpg
Using Reserved Variables: &DESCRIBE

  • The &describe function takes in a Coverage and sets up various reserve variables containing data on the Extent, number of Tics etc.

  • See ArcDocs > Command References > AML > Describe.

    &describe newBuildings

    &sv numpoly = %DSC$POLYGONS%

    &type %numpoly%

Command line arguments l.jpg
Command Line Arguments

  • So far we’ve looked at running AMLs with no arguments…


  • You can pass arguments to an AML when you run them, for example…

    &run plot roads blue

  • Use the &args directive to get the values. Should be first directive except for &echo.

    &args <variable...variable>{:rest}

  • For example

    &args cover colour:rest

  • :rest sticks any remaining text in the last Variable. ie for this example “colour”.

Using command line arguments l.jpg
Using Command Line Arguments

  • Example…

    Arc: &run plot roads blue

    &args cover colour:rest


    mapextent %cover%

    edit %cover%

    de arc node

    nodecolor node %colour%



Functions l.jpg

  • Functions perform the following operations:

    • prompting for user input;

    • calculating mathematical values;

    • modifying & extracting values from character strings;

    • reporting current conditions;

    • reading and writing files.

  • Functions and their options are enclosed by square brackets [ ].

    &s covername = [getcover]

  • Write your own “functions”: write AMLs taking in arguments and use &run / &amlpath to call them in other AMLs.

Directives controlling program flow l.jpg
Directives: Controlling Program Flow

  • We can put in decision making (branching) and repetition (looping) in AML.

  • Can branch on the basis of user inputs or calculations – if “something” do “something”, otherwise do “something else”.

  • Can repeat to do multiple calculations – given a list, run through each item and do “something” to them.

Branching with if l.jpg
Branching with “If”

If the expression equals .TRUE. then the actions 1 are done, otherwise the actions 2 are done. The rest of code is done whatever.

You don’t need to have the &else section.

Also if you just have one action, you don’t need the &do and &end.

&if <expression>

&then <actions>

<rest of code>

&if <expression>



<actions 1>




<actions 2>


/* Rest of code

Expressions l.jpg

&if [username] = bob &then

&type “hello bobster”

&else &type “do I know you?”

  • The expression [username] = bob equates to either .TRUE. or .FALSE. These are known as Logical Expressions.

  • Examples of logical expressions:

    3 + 6 = 10 equates to .False.

    3 + 6 = 9 equates to .True.

    [date -dow]= Sunday equates to .False.

  • AML makes the comparison using Relational Operators like = or <, <=, >, >=, <>.

Looping l.jpg

  • Iterative steps can be performed in AML using an &do &end loop

  • The &do loop structure

    &do <loop control clause>

    <action 1, 2...n>


  • There are four types of &do &endloop:

    • Counted, List, While, Until.

Counted loops l.jpg
Counted Loops

  • Used when the number of iterations is known

    &do i = <start> &to <stop> &by <increment>

    <action 1,2,...n>


    i = <loop control variable>

&do burgers = 1 &to 3 &by 1

&type Eaten %burgers%


&type Elvis ate %burgers% burgers


Eaten 1

Eaten 2

Eaten 3

Elvis ate 3 burgers

Listed loops l.jpg
Listed Loops

  • Performs a set of identical actions on a list of elements (e.g. coverages)

    &do i &list <list of elements>

    <action 1>

    <action 2>

    …<action n>


  • i= <loop control variable>

  • &do food &list burger squirrel coke

  • &type %food%

  • &end




While and until loops l.jpg
While and Until Loops

  • Used when the number of iterations is not known, but while or until a specified condition is met

    &do &while <logical expression>

    <action 1,2,...n>


    &do &until <logical expression>

    <action 1,2,...n>


&do &until [query 'Do you feel sick yet?']

&type Another burger, thanky’verymuch.


Debugging l.jpg

  • Debugging programs - finding and fixing errors.

  • Three useful commands.

    • &echo &on:writes all commands and outputs to the screen.

    • &test &on : puts Arc in AML test mode – actions aren’t done, but the syntax and possibility of running are checked.

    • &messages &on : sets Arc so it gives messages about what it’s doing (usually this is set as the default).

      &test &on

      &sv cover = landuse

      build %cover% poly


  • Arc also has Error Handling, which lets you determine where errors come from and deal with them. See “Error handling in AML” in the ArcDocs.

Menus building a gui l.jpg
Menus: Building a GUI

  • A menu is a graphical list of options from which the user can select a choice.

  • AML includes easy-to-use tools for creating menus.

  • Menus can be used for:

    • creating GUIs for inexperienced users;

    • eliminating errors by showing only valid options;

    • customising user interfaces;

    • creating highly visual demonstrations;

    • reducing the amount of typing.

  • See, for example, ArcTools.

Menus from aml scripts l.jpg
Menus from AML Scripts

  • AML Functions beginning with [get...] create menus for you.

Examples l.jpg

  • [getcover]

&sv cov = [getcover]

&sv cov = [getcover * -POLYGON 'Choose a Coverage:']

Separate menus l.jpg
Separate Menus

  • [get] functions are OK but you can’t easily control:

    • where they decide to appear on the screen;

    • what they look like;

    • what they do.

  • Menu files are:

    • ASCII files;

    • named with .menu extension;

    • run with &menu directive.

  • Must set display environment with &terminal to let AML know the device type before use (also true for [get]). E.g. &terminal 9999

Menu types l.jpg
Menu Types

  • You’re most likely to use:

    • pulldown;

    • sidebar;

    • form;

    • enhanced pulldown.

  • 8 supported types:

    • 1 : pulldown

    • 2 : sidebar

    • 3 : matrix

    • 4 : key

    • 5 : tablet

    • 6 : digitiser

    • 7 : form

    • 8 : enhanced pulldown

Enhanced menu l.jpg
Enhanced Menu

Makes Landuse

Use Alt-L to use

8 A sample enhanced pulldown menu


&BEGIN_BLOCK "&Landuse"





&BEGIN_BLOCK "&Sewers"




&BEGIN_BLOCK "&Option"






Menuedit l.jpg

  • Started by typing menuedit.

  • Automatically generates your menus and allows you to save them to a .menu file.

This allows you to make submenus with Pull Right.

The test facility brings up a test version.

Forms l.jpg

  • A powerful menu extension allowing dynamic GUIs.

  • Windows based editor (type formedit) allows you to add:

    • Command Buttons;

    • Check boxes(multiple section);

    • Radio buttons (one selection from group);

    • Slider bars (scrollbars);

    • Text boxes;

    • Lists.

  • Add items by clicking on the icons then in the Form.

Form elements l.jpg




Form Elements

  • Three kinds:

    • text control : for displaying descriptive text or labels;

    • display control : for displaying the contents of a variable to the user;

    • input controls : allows user to enter in text or values.

  • All set up with Right click > Properties.

Text control l.jpg
Text Control

  • Used as a piece of descriptive text or in front of an input control.

  • Cannot resize but it will adjust to fit the size of the string you type in.

Display control l.jpg
Display Control

  • Used for holding dynamic text, i.e. things that can change during the course of the program.

  • For example, you might want to process Coverages and then add their names to a display when finished.

  • You can resize this control.

Input control l.jpg
Input Control

Returns you a variable and value (can be global), or starts an action.

Some give you the option of setting up error messages (On Error tab).

For keyboard navigation

(usually the SHIFT key)

Customizing arctools l.jpg
Customizing ArcTools

  • You can add Menus and AML to ArcTools in ArcWorkstation and ArcToolbox.

  • These are just AML/Menu files in particular directories written in a particular format.

  • You can find more details of adding them to ArcTools in the ArcDocs under Customising ARC/INFO > Programming ArcTools.

  • Note: ArcGIS8.x: You can’t add full AML to ArcToolbox, however, you can run AML from it provided…

    • It only uses Arc and Info commands (i.e. no ArcEdit).

    • It doesn’t use Menus.

Further info l.jpg
Further info

  • The ArcDocs aren’t terribly helpful on Forms,but there’s stuff on Menus and AML in Customizing ARC/INFO.