Perhaps not the most elegant solution, but here is what I went with in the end. Any comments or suggestions greatly appreciated.
# -*- 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
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."