Exercise 1: Creating a default configuration file for toolbars (pole inspection)

Exercise 2: Creating custom edit and query formsExercise 3: Deploying customized AXF files

Creating a default configuration file that replaces existing toolbars with custom toolbars

NoteNote:

This exercise describes the same steps outlined in Exercise 1: Creating a default configuration file for toolbars (tree inventory). This exercise demonstrates that configuration files are always the same, regardless of whether you use shapefiles or ArcPad Exchange Files (AXF) to store your data. If you have already completed Exercise 1: Creating a default configuration file for toolbars (tree inventory), you can skip this exercise and proceed to customizing forms for AXF files.

In this exercise, you begin by creating a default configuration file. One of the functions of a default configuration file is to specify which toolbars are shown when ArcPad starts and which toolbars are hidden. For example, you may want to hide or expose one or more of the default toolbars, and include a combination of built-in and custom tools that run your scripts. This exercise introduces the basic techniques for creating custom toolbars, and adding built-in and custom tools.

Creating a default configuration project

Steps:
  1. Start ArcPad Studio. The ArcPad Studio dialog box appears. See the following screen shot:
    Screen shot showing the ArcPad Studio dialog box.
  2. Click the New default configuration project radio button, then click OK. A new configuration file is created with the <ArcPad> root element and the <CONFIG> child element in the ArcPad Studio configuration window. If in a previous session of ArcPad Studio you selected the Do not show this dialog again check box on the previous ArcPad Studio dialog box, you can create a default configuration file by clicking the New Configuration New Configuration button button on the toolbar. The configuration file (like all customization files) displays in a tree view. ArcPad Extensible Markup Language (XML) elements and attributes show as branches in the tree. You can modify the customization files by working in the tree view. See the following screen shot:
    Screen shot showing the ArcPad Studio configuration window.
    TipTip:

    If you only see an <ArcPad> element, but no <CONFIG> element after this step, you need to install the Microsoft XML Parser. You must do this before you can continue with the tutorial. See the ArcPad installation guide (located on your local drive where ArcPad is installed, for example, \\Program Files\ArcGIS\ArcPad\Help) for more information on installing the Microsoft XML Parser.

    Click the Toggle between source and tree view Toggle between source and tree view button button on the toolbar to switch between tree and source view.

  3. Double-click the <CONFIG> element in the tree view to set the configuration file's properties. The Configuration Properties dialog box appears. On the dialog box, retain the Scale Bar tab's check box settings. Click OK on the dialog box. See the following screen shot:
    Screen shot of the Configuration Properties dialog box.
  4. The <STATUSBAR> element is added as a child element to the <CONFIG> element in the tree view. Review the attributes of the <STATUSBAR> element by clicking the plus sign Plus sign node node to expand the branch. Leave all of the <STATUSBAR> attributes with the default settings of true. See the following screen shot:
    Screen shot showing the <STATUSBAR settings.
  5. Click the Save Save button button on the toolbar to save the configuration file (continue to save your work periodically while editing). The Save As dialog box appears.
  6. Type ArcPad.apx in the File name text box. The configuration file must be called ArcPad.apx and be saved in the My Documents\My ArcPad folder for ArcPad to automatically load this file at startup.
  7. Click the Save button.

Hiding default toolbars

Steps:
  1. Click the Toolbars Toolbars button button on the toolbar. The Toolbars dialog box appears without a defined toolbar.
  2. Click Add. See the following screen shot:
    Screen shot showing the Toolbars dialog box.

Creating a custom toolbar

Steps:
  1. After you click Add on the Toolbars dialog box, the Toolbar properties dialog box appears. The Commands column on the right is empty. You will add built-in and custom tools to this column.
  2. Type tlbCustomToolBar1 in the Name text box.
  3. Type Tools in the Caption text box.
  4. Leave the Image text box empty (this toolbar will not have an image).
  5. Leave the Visible check box selected (you want this toolbar to show when ArcPad starts). See the following screen shot:
    Screen shot showing the Toolbar dialog box.

Adding built-in tools to the toolbar

While still on the Toolbar dialog box, select the following under the Command column on the left:

Steps:
  1. Select openmap. Click Add.
  2. Select modezoomin. Click Add.
  3. Select modezoomout. Click Add.
  4. Select modepan. Click Add.
  5. Select modeidentify. Click Add.
  6. Select exit. Click Add. Leave the Toolbar dialog box open to add a custom tool. See the following screen shot:
    Screen shot showing the Toolbar dialog box with commands added.

Adding custom tools to the toolbar

Steps:
  1. In addition to the built-in tools, you want to add a custom tool that calls a script to automate the process of adding a new pole to the Poles layer. Click the Add Custom button. The Tools Properties dialog box appears.
  2. Type tlAddPole in the Name text box.
  3. Type Add Pole in the Tooltip text box.
  4. Type Add a new pole to the Poles layer in the Prompt text box.
  5. You will now select the image for this new tool, but first you need to create a bitmap image. Navigate to C:\Documents and Settings\All Users\Documents\ArcPad\Samples\Layer Icons. On computers running Windows Vista or Windows 7, the sample data folder is installed under Public Documents.
  6. Open the Street_Light.ico file in an graphics software program (for example, Paint) that can save this image as a bitmap. See the following screen shot:
    Screen shot showing Street_Light.ico in Paint.
  7. Save Street_Light.ico as Street_Light.bmp inside your project folder, for example, C:\PoleInspection.
  8. Click Browse on the Tool Properties dialog box. Navigate to the project folder and open Street_Light.bmp. See the following screen shot: Screen shot of the Tool Properties dialog box showing Street_Light.bmp.
  9. Click OK on the Tool Properties dialog box.
  10. On the Toolbar dialog box click the Move Up or Move Down buttons to move your user-defined custom command, click tlAddPole, so that it is at the end of the group of built-in commands (or to wherever you choose to place it). To move a command, select it until it is highlighted, then click Move Up or Move Down. If your command is already at the end of the Command list, move the custom tool up and down to test this feature (you can place the tool in any location on the toolbar). See the following screen shot:
    Screen shot of the Toolbar dialog box showing the Custom command added under the Command column.
  11. Click OK on the Toolbar dialog box to keep the selected commands.
  12. Click OK on the Toolbars dialog box.
  13. Click the Save Save button button on the toolbar to save the configuration file.

Writing a script for the custom tool

Determine how you want this custom tool to work. You want the user to click the tool, click the map location where the new pole will be added, then add the pole's attribute information into your custom edit form. You decide that the script will be called when the tool fires an OnPointerUp event and will do the following:

  • Make sure the Poles layer is in the current map.
  • Make the Poles layer editable if it is not already editable.
  • Get the coordinates of the map location clicked by the user.
  • Add a new pole (point feature) to the Poles layer at the defined coordinates, which automatically displays the custom data entry form that you create in the next exercise.
  • Return the custom tool to its original state (not selected state).

Steps:
  1. Click the Edit Script Edit Script button button on the toolbar. A new VBScript source code file named ArcPad.vbs is created.
    Screen shot showing the Edit Script button.

    This tutorial included script samples in VBScript. If you prefer to use JScript or Python, or if you have previously used a different langauge and need to change back to VBScript, you can change the default script language used by ArcPad Studio by selecting your chosen language on the scripting tab of the Options dialog box listed under the Tools menu. Restart ArcPad Studio for default script language changes to take effect.

  2. Copy and paste the following sample into the script window. If you have formatting issues, paste the script into Notepad, then copy and paste it into the VBScript source code file.

    VBScript

    Sub AddPole
       Dim dblX, dblY, objToolButton, blnLyrExists
       'Get a reference to the tool button object. 
       Set objToolButton = ThisEvent.Object
       'Initialize blnLyrExists flag to False.
       blnLyrExists = False
       'If Poles layer exists, 
       'set the blnLyrExists flag to true.
       Dim objLyr
       For Each objLyr in Map.Layers
     If StrComp (objLyr.Name, "Poles", 1) = 0 Then
           blnLyrExists = True
           Exit For
         End If
       Next
       'If Poles layer does not exist, 
       'notify the user, return the tool button to its original state, and exit.
       If Not blnLyrExists Then
     MsgBox "The Poles layer is not present in the current map.", vbExclamation, "Layer not present"
         objToolButton.Click
         Exit Sub
       End If
       'If the Poles layer does exist,
       'get the coordinates of the map where the user clicked.
       dblX = Map.PointerX
       dblY = Map.PointerY
       'Get a reference to the Poles layer object.
       Dim objLayer
     Set objLayer = Map.Layers("Poles")
       'If the layer can be made editable, make it editable.
       If objLayer.CanEdit Then
         objLayer.Editable = True
         'Add a new pole (point feature) at the clicked location.
         Call Map.AddFeatureXY(dblX,dblY)
         'Return the tool button to its original state.
         objToolButton.Click
       End If
     End Sub
    
  3. After you paste the script, click the Verify syntax Verify syntax button button on the toolbar to perform a syntax check. If the compilation succeeds, you'll hear an audible beep. If you receive an error, review your script. Click Save to save your script. If the compilation fails, compare the script you added to the script shown in the preceding code example and correct any errors, then click Save again. To view both windows, click Tile under the Window menu. See the following screen shot:
    Screen shot showing ArcPad.vbs and ArcPad.apx in tile view.

    You will notice that the <SCRIPT> element gets saved in the ArcPad.apx file. You can return to edit the source file by double-clicking the <SCRIPT> tag (however, you don't need to do this at this time). See the following screen shot:

    Screen shot showing the <SCRIPT> tag.

Attaching the script to the custom tool

Steps:
  1. Activate the ArcPad.apx window by clicking its title bar.
  2. Click the Toolbars Toolbars button button on the toolbar. The Toolbars dialog box appears.
  3. Click the tlbCustomToolBar1 toolbar that you created earlier and click Edit. The Toolbar dialog box appears.
  4. Click the tlAddPole tool that you created earlier and click Edit. The Tool Properties dialog box appears.
  5. Click the Events tab on the Tool Properties dialog box. This displays a list of events that a custom tool or ToolItem object can respond to.
  6. Click onpointerup under the Events column and type Call AddPole in the Event Script text box. See the following screen shot:
    Screen shot showing the Event Script area on the Tool Properties dialog box.
  7. Click OK on the Tool Properties dialog box. You have just configured the custom tool to run the AddPole script when the custom tool (tlAddPole) fires an OnPointerUp event.
  8. Click OK on the Toolbar and Toolbars dialog boxes.

Saving the configuration file

Steps:
  1. Click the Save Save button button on the toolbar.
  2. Click File and click Close to close the default configuration and VBScript source code files.
TipTip:

A default ArcPad.apx file is created inside My Documents\My ArcPad when ArcPad starts for the first time. To show the default toolbars and your custom toolbar in ArcPad, you may want to start this tutorial by opening a default ArcPad.apx file in ArcPad Studio. By doing so, you do not need to create default toolbars from the beginning.

After the tutorial, you may want to remove or rename the default ArcPad.apx configuration file as it is for this tutorial only.


2/7/2013