My Favorite Avenue Snippet Ever.

I worked in Avenue for many years but do not expect to do too much more. Before my Avenue skills erode to nothing, thought I would share my favorite Avenue snippet. Really, it involves two “function” scripts that clients scripts can use.

What I got use to doing is instead of using a mess of global variables is using one global variable–a dictionary–that was used to store what essentially became global variables. The main advantage of doing this is that I started storing the parameters passed to each script as a global variable named after the script. This came in EXTREMELY useful for debugging purposes because when I was having trouble with a script I could write out my global dictionary to an ODB file at the beginning of that script, thereby storing the application’s state prior to the problem.

The first script, MyApplication_Routine_AddSelfDict, is used to add/modify a dictionary entry:

theScript = self.get(0)
theSelf = self.get(1)

if ( then
_MyApplication_SelfDict = dictionary.make(25)

if (self <> nil) then

The second script, MyApplication_Routine_GetSelfDict,  is used to retrieve a value from the global dictionary.

if ( then
_MyApplication_SelfDict = dictionary.make(25)

return (_MyApplication_SelfDict.get(self))

Then I can have client scripts first add an entry (primary key = script name)to the global dictionary storing the parameters passed in (self).  Then I set a local variable to the entry just added.   Then, if I need to debug later, I can throw an exit (shown in red) into the script, run the process and after it exits, I can step through the script and pull the parameters passed in from the global dictionary.

If (self<>nil) then“MyApplication_Routine_AddSelfDict”,{“MyApplication_ClientScript”,self})

theSelf =“MyApplication_Routine_GetSelfDict”,”MyApplication_ClientScript”)

‘**** The following EXIT is added for debugging purposes.  This gets temporarily added so I can capture ‘the application  state.  After running the process and getting to this point, I remove the exit and can step ‘through this script.  The snippet above retrieves the parameters as passed into this script.


And that’s it.  Took me several years to refine this technique–for a long time I just stuck a check in at the beginning of each script to see if there were any parameters passed and if so, store them in a separate global.  But what I like abut this is I can write the whole global dictionary out to an ODB, quit out of ArcView and then return to the project, read in the ODB and reset my global dictionary and pick up from where I left off.

The one addition that I added later was to remove entries from the global dictionary once a script ends.  I didn’t show it here.

Having all this data in one global dictionary is probably a horrendous design approach to anyone with an Object-Orientated mindset but, as they say, it got the job done.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s