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

المشرف العام

Administrator
طاقم الإدارة
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


  1. It seems to stick when I choose OK


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



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

أكثر...
 
أعلى