10

Do ArcGIS Pro tasks support Python Toolbox tools which operate on Map Frames?

The reason I ask is that I am stuck when trying to do the following:

  1. Start ArcGIS Pro 1.1.1
  2. Create a new project - I called mine TestProject and placed in in C:\Temp
  3. Use the Project pane to Add Folder Connection to where I have a shapefile of the countries of the world from Natural Earth ()
  4. Drag and drop ne_10m_admin_0_countries.shp into the Map to create layer called ne_10m_admin_0_countries
  5. Insert a new Layout - I used A3 Landscape
  6. Insert a new Map Frame on the Layout
  7. In the Project pane create a New Python Toolbox in the TestProject folder - I called mine TestPYT
  8. Right-click on TestPYT in the Project pane to Edit it
  9. Replace the code with that below to give the Python Toolbox two tools called Chile and Switzerland
  10. Save the script and Refresh the Python Toolbox to see the two new tools
  11. Run the Chile tool to see the map frame on the layout zoom to Chile
  12. Run the Switzerland tool to see the map frame on the layout zoom to Switzerland
  13. Insert a New Task Item
  14. In the Task Item 1 insert a New Task and call it Chile
  15. In the Chile task insert a New Step and call it Zoom to Chile
  16. For Step Behavior make it Automatic and Hidden
  17. On the Actions tab I try to set Command/Geoprocessing as a Geoprocessing Tool choosing the Chile tool

enter image description here

  1. It seems to stick when I choose OK

enter image description here

  1. It seems to "lose" the tool when I click Done

Specifically, what I am trying to create is a workflow with two tasks that I can click on to Zoom to Chile or Zoom to Switzerland but I am stuck at step 19 above.

What I am trying to do overall is to find an ArcPy (for ArcGIS Pro) equivalent to a Python AddIn toolbar in ArcPy (for ArcGIS 10.x architecture) with two buttons (Chile and Switzerland) to zoom to those countries.

I've run through this procedure a few times, and on one occasion I was able to get the Chile and Switzerland tools to stick as tasks, but even then they did not seem to interact with the Map Frame (no error, just no change to what was displayed in the Map Frame when they ran), even though the tools when run from the Python Toolbox continued to work without a problem.

enter image description here

This is the code to copy/paste into the Python Toolbox (TestPYT).

import arcpy


class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "Toolbox"
        self.alias = ""

        # List of tool classes associated with this toolbox
        self.tools = [Slide1,Slide2]


class Slide1(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Chile"
        self.description = ""
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""
        params = None
        return params

    def isLicensed(self):
        """Set whether tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""
        return

    def execute(self, parameters, messages):
        """The source code of the tool."""
        aprx = arcpy.mp.ArcGISProject("CURRENT")
        mapx = aprx.listMaps()[0]
        lyt = aprx.listLayouts()[0]
        lyr = mapx.listLayers("ne_10m_admin_0_countries")[0]
        lyr.definitionQuery = '"ADMIN" = ' + "'Chile'"
        mFrame = lyt.listElements("MAPFRAME_ELEMENT")[0]
        mFrame.camera.setExtent(mFrame.getLayerExtent(lyr, False, True))
        lyr.definitionQuery = ""
        return

class Slide2(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Switzerland"
        self.description = ""
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""
        params = None
        return params

    def isLicensed(self):
        """Set whether tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""
        return

    def execute(self, parameters, messages):
        """The source code of the tool."""
        aprx = arcpy.mp.ArcGISProject("CURRENT")
        mapx = aprx.listMaps()[0]
        lyt = aprx.listLayouts()[0]
        lyr = mapx.listLayers("ne_10m_admin_0_countries")[0]
        lyr.definitionQuery = '"ADMIN" = ' + "'Switzerland'"
        mFrame = lyt.listElements("MAPFRAME_ELEMENT")[0]
        mFrame.camera.setExtent(mFrame.getLayerExtent(lyr, False, True))
        lyr.definitionQuery = ""
        return
1
  • This doesn't appear to work with any Python toolbox, regardless of what it's doing. Also may be worth noting that toolbox parameters aren't shown when the tool is selected and embed is enabled (in other words, it's not actually loading the toolbox properly). Dec 17, 2015 at 12:11

1 Answer 1

4
+100

*.PYT toolboxes are not supported for tasks in ArcGIS Pro 1.0 and 1.1.

However, they have been supported since ArcGIS Pro 1.2.

As a workaround try to insert your tool into a geoprocessing model, and then use a task step to call the model.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.