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:
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.
This is the code to copy/paste into the Python Toolbox (TestPYT).
import arcpyclass 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 = "" returnclass 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
أكثر...
The reason I ask is that I am stuck when trying to do the following:
- Start ArcGIS Pro 1.1.1
- Create a new project - I called mine TestProject and placed in in C:\Temp
- Use the Project pane to Add Folder Connection to where I have a shapefile of the countries of the world from Natural Earth ()
- Drag and drop ne_10m_admin_0_countries.shp into the Map to create layer called ne_10m_admin_0_countries
- Insert a new Layout - I used A3 Landscape
- Insert a new Map Frame on the Layout
- In the Project pane create a New Python Toolbox in the TestProject folder - I called mine TestPYT
- Right-click on TestPYT in the Project pane to Edit it
- Replace the code with that below to give the Python Toolbox two tools called Chile and Switzerland
- Save the script and Refresh the Python Toolbox to see the two new tools
- Run the Chile tool to see the map frame on the layout zoom to Chile
- Run the Switzerland tool to see the map frame on the layout zoom to Switzerland
- Insert a New Task Item
- In the Task Item 1 insert a New Task and call it Chile
- In the Chile task insert a New Step and call it Zoom to Chile
- For Step Behavior make it Automatic and Hidden
- On the Actions tab I try to set Command/Geoprocessing as a Geoprocessing Tool choosing the Chile tool

- It seems to stick when I choose OK

- It seems to "lose" the tool when I click Done
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.

This is the code to copy/paste into the Python Toolbox (TestPYT).
import arcpyclass 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 = "" returnclass 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
أكثر...