The ArcPad Team Blog

Unofficial stuff from the team behind the World's leading mobile GIS platform

Wednesday, November 16, 2011

ArcPad and Python



As of ArcPad 10.0.3, the Windows (Desktop/Tablet) version now supports the Python (2.6) scripting language in addition to vbScript and Jscript. There is a port of Python to windows Mobile, you might want to try PythonCE - http://sourceforge.net/projects/pythonce/ but do so at your own risk as it is not an "official" port.
  1. You can now write your applets and customizations in python and take advantage of many of the extra libraries that are available to Python users.
  2. Supports the ArcGIS implementation of ArcPy.
    • If you have ArcGIS installed on the same PC as ArcPad they are already there, or
    • Using ArcPad in conjunction with an ArcGIS Runtime license (I currently have this on my laptop).
It is important to note that this does not expose the ArcPad object model to be used in python scripts out side of ArcPad, in case you were thinking you could create ArcPad batch files.

Over the years many people have asked for more "analytical tools" for ArcPad, so now here is a method of accessing all of those lovely jubbly geoprocessing tools that you have all come to care for so dearly.


There is an applet posted on the ArcPad Resources Site that covers the two scenarios mentioned above - ArcPad Python Applet

There are some subtle differences in writing for python with ArcPad:

  • You must capitalize objects, methods and Events: Console.Print(Map.Layers.Count)
  • You must use the full path to the message box: Application.MessageBox("ArcPad Rocks!")
  • If you want to change the style of the message box you must use the index number of the MessageBox constant not the name:  Application.MessageBox("ArcPad Rocks!", 0) instead of  Application.MessageBox("ArcPad Rocks!", apOkOnly)
So now you have another scripting language choice moving forward when customizing ArcPad to fit your data collection/editing workflows.

7 Comments:

  • At Friday, January 06, 2012 8:49:00 am, Blogger Patrick said…

    I'm very excited about the addition of Python to the coding possibilities in ArcPad. I'm relatively new to working with ArcPad Studio and need a little more help. I'm not sure where the Python syntax you use in your Python examples comes from. I've looked at this example and the GPS one in the gallery. But having a little 'ArcPad Python Quick Start' guide and tutorial (maybe in ArcPad's Help section) with examples and snippets would be greatly appreciated.

    Thanks for the blog and for getting Python into Arcpad in the first place!

     
  • At Wednesday, January 11, 2012 3:57:00 pm, Blogger Gareth Walters said…

    Hi Patrick and sorry for the delay.

    We are glad you are excited about the release of python support and are eager for more information. For now, I would suggest putting questions on the ArcPad Forum - http://forums.arcgis.com/forums/55-ArcPad for the most immediate help.

    As all things time is limited and we have in our strategy to boost documentation for example scripts however it will just take some time.

    So in the meantime keep posting on the forum where this is a huge user community to help out.

     
  • At Tuesday, January 31, 2012 2:04:00 am, Blogger Hq said…

    Hi
    Great !

    Defining PYTHONPATH with ArcGIS "bin", "arcpy" and "bin" folder in Windows seems to be mandatory.

    Sadly, the tools doesn' seem to work with AXF files (pb in "Input_Features" parameter in "MultipleRingBuffer_analysis" function)

    Bye
    HQ

     
  • At Friday, March 09, 2012 2:46:00 am, Blogger Kris De Coster said…

    Hello,
    I made a python applet for ArcPAD using python in the way described above. This works perfect on a desktop pc using Arcgis 10 and python 2.6. However, I have the following question: How can I install the correct python (including the arcpy module) on our mobile GIS-machine (Trimble GeoXH - Geoexplorer 2008 series), in a way that the python applet also works in ArcPAD on the mobile GISmachine. This mobile GISmachine runs on a windows CE. Can anybody help me?
    Thanks!
    Kris De Coster

     
  • At Friday, March 09, 2012 10:03:00 am, Blogger Hannah Ferrier said…

    Hi Kris!

    The ability to use Python Scripting in ArcPad is restricted to the Windows Desktop Environment.

    This is because there is currently no port of Python for Windows Mobile or CE platforms that utilizes Active X, which is needed to allow Python to communicate with the ArcPad application.

    So Python scripting will work if you are using a Windows 7 Device (eg. Trimble Yuma) - not so much on a Windows Mobile or CE device :(

    See the Read Me in your ArcPad 10.0.3 Install for more information.

     
  • At Monday, March 19, 2012 11:02:00 pm, Blogger Kris De Coster said…

    Dear Hannah,

    Thank you very much for your info. I stopped therefore programming the app in python and started converting it to VBscript. Works already better on the mobile GISmachine (Windows mobile 6.1 and Arcdap 10.0.3). However, I have another question for the tool I'm developping in VBscript. Therefore, I explain what the tool must do:
    We have a point shapefile in Arcpad. Everytime when we add a point, we automaticaly count the new ID by clicking on a button in the toolbar. The new ID is the last ID + 1. I succeeded already in looping through the attributes, finding the last ID and calculating a new ID. However, I can't add the new calculated ID for the added point in the attribute table. It's like I can't open the recordset in edit mode. Below you find my source code. Do you know what I'm doing wrong?
    Thanks for helping!
    Kris

    Sourcecode:
    Sub Test
    Dim objDBF, strLaatstePaalID, NewPaalNR, NewPaalID, Nummer, PaalCode
    Numbre = 0
    Set objLyr = Map.Layers("Palen")
    Set objDBF = objLyr.Records
    'Look for record with the highest ID
    'ID is text format like 'P_00450'
    objDBF.MoveFirst
    Do Until objDBF.EOF
    PaalCode = objDBF.Fields("PAAL_ID").Value
    If PaalCode <> "" Then 'the new added point (which is the last) has no value in the ID
    If Int(Right(PaalCode,(Len(PaalCode)-2)))>Numbre Then
    'Make an integer of the text code
    Numbre = Int(Right(PaalCode,(Len(PaalCode)-2)))
    End If
    End If
    objDBF.MoveNext
    Loop

    NewPaalNR = Numbre + 1

    'Maak een nieuw text ID with the new numbre
    If NewPaalNR < 10 Then
    NewPaalID = "P_0000" & CStr(NewPaalNR)

    ElseIf NewPaalNR < 100 Then
    NewPaalID = "P_000" & CStr(NewPaalNR)

    ElseIf NewPaalNR < 1000 Then
    NewPaalID = "P_00" & CStr(NewPaalNR)

    ElseIf NewPaalNR < 10000 Then
    NewPaalID = "P_0" & CStr(NewPaalNR)

    Else
    NewPaalID = "P_" & CStr(NewPaalNR)

    End If

    MsgBox ("New Id: " & NewPaalID)

    'go to the new added point
    objDBF.MoveLast

    if objDBF.Fields("PAAL_ID").Value ="" Then
    'add the new value
    objDBF.Fields("PAAL_ID").Value = NewPaalID
    objDBF.Update
    MsgBox("Paal_ID " & NewPaalID & " added in Palen.shp")
    Else
    MsgBox("No empty feature added")
    End If

    Set objDBF = Nothing
    End Sub

     
  • At Tuesday, March 20, 2012 3:19:00 pm, Blogger Gareth Walters said…

    Having a quick look at your script I would suggest that you break it up into smaller sections.

    Rather than continually running the loop to find the highest id, how about you run it once when the map opens and store it as an application variable - application.userproperties(yourID). Then everytime you add a new record (Page OnSetActive event) you have it ready. Then overwrite this application variable to the next id once you have added the feature (Map OnFeatureAdded event).

    From your code it is not easily identifiable where you are executing the routine and the actual workflow on feature capture. If you are using the standard point capture tool then ArcPad has already accessed the recordset for you and you could potentially change the way you are communicating with it.

    If you are opening the point features' edit form, then wait until the page has been made active and then run your component of the script (IF Statement) - use the Page SetActive event. This way you write your id to the forms control value (txtYourID.value) rather than trying to write to objRS.fields(yourid).value. If you are not using the edit form, then you can always take advantage of the Map.SelectionBookmark. This will help you access the correct row in the recordset.

    I have previously written about this on another stack exchange [click here][1] question. Also there is an example that comes with ArcPad that in the Tree Register Quick Project template. Have a look at that and see it provides any inspiration.

    I hope this helps and please let me know if you need more clarification.


    Cheers,

    Gareth

    P.S. Rather than commenting on the blog, feel free to continue this conversation on the GIS stack exchange: http://gis.stackexchange.com/questions/21938/arcpad-vbscript-to-update-values-in-attribute-table/21971#21971

    [1]: http://gis.stackexchange.com/questions/16948/create-unique-id-in-arcpad-form-code-issue/17956#17956

     

Post a Comment

<< Home