What is the easiest way to learn MapViewer's Scripter?

This article explains the easiest and best ways to learn how to script with MapViewer's Scripter.

Scripter is an Active-X Automation scripting program that uses a Visual Basic-like model. This means that objects are "drilled down" to get to the commands.  If you are completely new to scripting, I would recommend looking into getting a Visual Basic book like Visual Basic for Dummies to give you an understanding of how VB works, but it's not required. For many people, it is easier to learn scripting by jumping right in and writing a script, rather than reading about scripting.

Before writing a script, you will want to know the steps you want to perform in the user-interface. Almost anything you can do in the program, you can do in a script. The workflow will be very similar. Once you know the sequence of steps you want to perform, the next step is actually writing the script. The best ways to start writing the script are to 1) use the Help menu, and 2) look at the example scripts.

  • Help menu

If you click Help | MapViewer Automation Help from within Scripter, or Home | Help | Automation from within MapViewer, the help file will open. In the Contents tab, open the MapViewer Automation book. Under this book, there are three additional books that are very helpful: Object Overview, Objects, and Methods and Properties.

Specifically, within the Object Overview book, the Object Hierarchy Graphic page is extremely helpful. To see how, let's take the following example. Say you want to create a hatch map and change the gradient colors that are used.

  1. Open the Object Overview book.
  2. Click on Object Hierarchy Graphic.
  3. On the Object Hierarchy page, click on HatchMap under Application | Documents | Plot Document | Layers | Layer | Map Type.

  4. The HatchMap Object page displays. This shows all of the methods and properties that apply to that object.
  5. Copy and paste the Example script at the bottom into Scripter. This portion of the script creates the hatch map. This will be the base from which we can add more lines to adjust properties and perform other actions. Note: any line that begins with a single quotation mark is a comment.
  6. Scroll up in the help on the HatchMap Object page and click on FgColorSpectrum in the Properties list.

  7. This opens the FgColorSpectrum Property page. Copy and paste the Example from here into your script, just before the End Sub line at the bottom.

If you start your script with the property and want to work backwards to then put together the script to create the map the property applies to, you can look below the example(s) on a property page, in the Used by section, for links to the pages for the objects that use that property.

Similarly, if you're on an object page (click the Back button to get to the HatchMap one) and the action you want to perform isn't listed (like adding a legend), look above the Properties section for a description of what object this one is derived from. The HatchMap object is derived from the Map object, so all of the methods and properties of the Map object apply to the HatchMap object.

One of the methods of the Map object is CreateLegend, so you can use this in your script to add a legend to your hatch map. We'll do that in just a moment.

To see how the Objects book is helpful, let's continue on from the previous example. Since we know we can add a legend to our hatch map, let's do so, and then let's display the class names instead of the data ranges in the legend.

  1. Open the Objects book.
  2. Click on the Legend Object.
  3. The Legend Object page displays. Again, this shows all of the methods and properties that apply to that object.
  4. The majority of the script is redundant to what we already have in our script, since we already have a hatch map created, so just copy the last section, which adds the legend, and paste it into your script above End Sub.
  5. Back in the help, click on ShowClassName in the Properties list.
  6. This opens the ShowClassName Property page. Copy and paste the example from here into your script, just before the End Sub line.

To see how the Methods and Properties book is helpful, let's again add to our existing example. Let's say you now want to export your map.

  1. Open the Methods and Properties book.
  2. Scroll down and click on Export - Automation.
  3. On the Export - Automation page, scroll down to the example. Since we already have the Plot set in our script, we just need to copy the second half of the example (starting with the 'Export the map as a bitmap comment). Paste this into your script before End Sub.

Following these steps, the example script looks like this:

Sub main

'Creates an instance of the MapViewer Application
'object and assigns it to the variable named "mvApp"
Set mvApp = CreateObject("MapViewer.Application")

'Makes the application main window visible
mvApp.Visible = True

'Assigns the location of the samples folder
'to the variable "InPath"
InPath$ = mvApp.ApplicationFolder + "samples\"

'Creates a map document object, and assigns it
'to the variable named "Plot"
Set Plot = mvApp.Documents.Add(DocType:=mvDocPlot)

'Creates a hatch map object and assigns it to the
'variable named "HatchMap"
Set HatchMap = Plot.CreateHatchMap( BoundaryFileName:=InPath$ + _
 "co2010.gsb", DataFileName:=InPath$ + "co2010.dat", PIDCol:=1, _
 VarCol:=5, NumClasses:=4)


'Create a map legend and assign it to the
'variable named "Legend"
 Set Legend = HatchMap.CreateLegend( Left:=-2, Top:=6 )

'Show the counts for each class in the legend for the hatch map layer
Legend.ShowClassHits("Layer #1") = True

'Export the map as a bitmap
Plot.Export(FileName:=mvApp.ApplicationFolder + "Samples\export.tif", _
 Options:="Width=972, Height=422")

End Sub

Click Script | Run to run the script. It should run as-is, but you can update it as desired to fit your specific needs.


  • Example scripts

Example scripts are also very useful. A number of standalone sample scripts can be found in the \Samples\Scripts\ folder in the MapViewer installation directory. You can also find more sample scripts on the MapViewer scripts download page.


See also:



Updated March 6, 2015


Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Please sign in to leave a comment.