<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Arcpy parameter for ArcGIS Pro Document in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-parameter-for-arcgis-pro-document/m-p/1039457#M38855</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Why not to specify File as Data Type with .aprx extension? Does it work for you?&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Adam&lt;/P&gt;</description>
    <pubDate>Mon, 22 Mar 2021 19:30:45 GMT</pubDate>
    <dc:creator>nita14</dc:creator>
    <dc:date>2021-03-22T19:30:45Z</dc:date>
    <item>
      <title>Arcpy parameter for ArcGIS Pro Document</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-parameter-for-arcgis-pro-document/m-p/1039453#M38854</link>
      <description>&lt;P&gt;Is there a way to specify a Pro-Doc as a &lt;A title="arcpy page" href="https://pro.arcgis.com/en/pro-app/latest/arcpy/geoprocessing_and_python/defining-parameter-data-types-in-a-python-toolbox.htm" target="_blank" rel="noopener"&gt;parameter input&lt;/A&gt; to a Python Toolbox?&amp;nbsp;I'm writing a tool that iterates over different layouts, and exports to PDF. It would be nice to allow users of the tool the ability to specify a ProDoc (e.g. "//file/path/prodoc.aprx" or "current"). It seems that arcpy for Pro has not been updated, as it still has an ArcMap option (dataType="DEMapDocument").&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Snag_14f61161.png" style="width: 944px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/9114i33B35D5FA0C2D2B1/image-size/large?v=v2&amp;amp;px=999" role="button" title="Snag_14f61161.png" alt="Snag_14f61161.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Mar 2021 19:28:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-parameter-for-arcgis-pro-document/m-p/1039453#M38854</guid>
      <dc:creator>KennethEggering1</dc:creator>
      <dc:date>2021-03-22T19:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy parameter for ArcGIS Pro Document</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-parameter-for-arcgis-pro-document/m-p/1039457#M38855</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Why not to specify File as Data Type with .aprx extension? Does it work for you?&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Adam&lt;/P&gt;</description>
      <pubDate>Mon, 22 Mar 2021 19:30:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-parameter-for-arcgis-pro-document/m-p/1039457#M38855</guid>
      <dc:creator>nita14</dc:creator>
      <dc:date>2021-03-22T19:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy parameter for ArcGIS Pro Document</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-parameter-for-arcgis-pro-document/m-p/1039474#M38856</link>
      <description>&lt;P&gt;Datatypes of "DEFile" and "GPString" can both work with limitations. Each allow users to enter errant inputs (e.g. .txt files, or random strings), which throws an error on subsequent parameter inputs that build off it. Easily enough for users to figure out I suppose. Would still be nice if ESRI added an ArcPro datatype, allowing users to open the folder icon pre-filtered with only .aprx files.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Snag_15194d08.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/9120i452172A4381CC67C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Snag_15194d08.png" alt="Snag_15194d08.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Mar 2021 20:02:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-parameter-for-arcgis-pro-document/m-p/1039474#M38856</guid>
      <dc:creator>KennethEggering1</dc:creator>
      <dc:date>2021-03-22T20:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy parameter for ArcGIS Pro Document</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-parameter-for-arcgis-pro-document/m-p/1039505#M38859</link>
      <description>&lt;P&gt;Perhaps use &lt;SPAN&gt;DEFile and only allow aprx files using a &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/geoprocessing_and_python/defining-parameters-in-a-python-toolbox.htm#:~:text=lyrx%27)-,Applying%20filters%20to%20a%20parameter,-Applying" target="_blank" rel="noopener"&gt;filter&lt;/A&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def getParameterInfo(self):
    param0 = arcpy.Parameter(
        displayName="Input Project",
        name="in_project",
        datatype="DEFile",
        parameterType="Required",
        direction="Input")

    #  set the filter list to a list of file extension names
    param0.filter.list = ['aprx']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Mar 2021 21:02:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-parameter-for-arcgis-pro-document/m-p/1039505#M38859</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-03-22T21:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy parameter for ArcGIS Pro Document</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-parameter-for-arcgis-pro-document/m-p/1039618#M38882</link>
      <description>&lt;P&gt;Thanks for the tip&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/10780"&gt;@Luke_Pinner&lt;/a&gt;. The tool needed to be able to work in the "current" pro-document, so filtering by the aprx file extension didn't fully work for this situation. I opted to go with a parameter type of GPString and trap any errors in the updateParameters/updateMessages below.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Mar 2021 01:49:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-parameter-for-arcgis-pro-document/m-p/1039618#M38882</guid>
      <dc:creator>KennethEggering1</dc:creator>
      <dc:date>2021-03-23T01:49:32Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy parameter for ArcGIS Pro Document</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-parameter-for-arcgis-pro-document/m-p/1039635#M38885</link>
      <description>&lt;P&gt;Perhaps not the most elegant solution, but here is what I went with in the end. Any comments or suggestions greatly appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# -*- coding: utf-8 -*-
import arcpy, os

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 = [Tool]

class Tool(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Tool"
        self.description = ""
        self.canRunInBackground = False
    
    currentList = ["CURRENT", "current"]

    def getParameterInfo(self):
        """Define parameter definitions"""
        
        param0 = arcpy.Parameter(displayName="Pro-Document", 
                                 name="proDocument", 
                                 datatype="GPString", 
                                 parameterType="Required", 
                                 direction="Input")
        
        param1 = arcpy.Parameter(displayName="Layout", 
                                 name="inlayout", 
                                 datatype="GPString", 
                                 parameterType="Required", 
                                 direction="Input")
        
        params = [param0, param1]
        
        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."""
        
        if parameters[0].value:
            p0Val = parameters[0].valueAsText
            if (p0Val.endswith(".aprx") and os.path.exists(p0Val)) or p0Val in self.currentList:
                aprx = arcpy.mp.ArcGISProject(parameters[0].valueAsText)
                layout_list = [l.name for l in aprx.listLayouts()]
                parameters[1].filter.list = layout_list

        return parameters
    
    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool parameter. 
        This method is called after internal validation."""
        
        if parameters[0].value:
            p0Val = parameters[0].valueAsText
            if not ((p0Val.endswith(".aprx") and os.path.exists(p0Val)) or p0Val in self.currentList):
                parameters[0].setErrorMessage("Not a valid ArcPro Document")

        return

    def execute(self, parameters, messages):
        """The source code of the tool."""
        aprx = arcpy.mp.ArcGISProject(parameters[0].valueAsText)
        arpxPath = str(os.path.normpath(aprx.filePath))
        arcpy.AddMessage(f"Pro-Doc Path: {arpxPath}")

        return&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The main limitation is that the "Pro-Document" input parameter does not have the nifty folder icon (see red arrow) for users to click and navigate to the document. Users have to build/write a path string if not using "current."&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Snag_1484366.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/9161iDFFEBC82AE0217DC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Snag_1484366.png" alt="Snag_1484366.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Mar 2021 03:32:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-parameter-for-arcgis-pro-document/m-p/1039635#M38885</guid>
      <dc:creator>KennethEggering1</dc:creator>
      <dc:date>2021-03-23T03:32:12Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy parameter for ArcGIS Pro Document</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-parameter-for-arcgis-pro-document/m-p/1039657#M38887</link>
      <description>&lt;P&gt;One suggestion is to use 2 parameters, one a DEFile and the other&amp;nbsp;&lt;SPAN&gt;GPBoolean. Have&amp;nbsp;parameter validation set to clear one when the other is altered. Something like:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# -*- coding: utf-8 -*-
import arcpy, os
 
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 = [Tool]
 
class Tool(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Tool"
        self.description = ""
        self.canRunInBackground = False
 
    def getParameterInfo(self):
        """Define parameter definitions"""
 
        param0 = arcpy.Parameter(displayName="Current Pro-Document",
                                 name="currentProDocument",
                                 datatype="GPBoolean",
                                 parameterType="Optional",
                                 direction="Input")
 
        param1 = arcpy.Parameter(displayName="Other Pro-Document",
                                 name="otherProDocument",
                                 datatype="DEFile",
                                 parameterType="Optional",
                                 direction="Input")
        param1.filter.list = ['aprx']
 
        param2 = arcpy.Parameter(displayName="Layout",
                                 name="inlayout",
                                datatype="GPString",
                                 parameterType="Required",
                                 direction="Input")
 
        params = [param0, param1, param2]
 
        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."""
 
        if parameters[1].altered and not parameters[1].hasBeenValidated:
            parameters[0].value = False
            parameters[2].value = None
            parameters[2].filter.list = []
            prodoc = parameters[1].valueAsText
        elif parameters[0].value and parameters[0].altered and not parameters[0].hasBeenValidated:
            parameters[1].value = None
            parameters[2].value = None
            parameters[2].filter.list = []
            prodoc = 'CURRENT'
        else:
            prodoc = None
 
        if prodoc is not None:
            aprx = arcpy.mp.ArcGISProject(prodoc)
            layout_list = [l.name for l in aprx.listLayouts()]
            parameters[2].filter.list = layout_list
 
        return parameters
 
    def execute(self, parameters, messages):
        """The source code of the tool."""
        aprx = arcpy.mp.ArcGISProject(parameters[0].valueAsText)
        arpxPath = str(os.path.normpath(aprx.filePath))
        arcpy.AddMessage(f"Pro-Doc Path: {arpxPath}")
 
        return&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Mar 2021 04:46:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-parameter-for-arcgis-pro-document/m-p/1039657#M38887</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-03-23T04:46:07Z</dc:date>
    </item>
  </channel>
</rss>

