Select to view content in your preferred language

Python script filter doesn't have the expected behavior

386
1
05-31-2023 11:02 AM
Labels (1)
KarolDuarte
New Contributor II

Hello, everyone!

I'm trying to build a new toolbox with one single python scrit to be shared internally. It's a simple script to help export layouts with our specified needs more easely.

That said, I have created a validation script for adding a filter to my layout parameter. The idea is that, first, the user will select the project were the layout are, and then the filter updates with all the layouts available inside that project.

It was succesfull when the project from which I wanted to export the layout was oppened. hower, when I tried running the script from a blank project, selecting one that I had worked on previously, the filter did not show. Is there a way to solve this?

Here's my code:

class ToolValidator(object😞
    def __init__(self):
        self.params = arcpy.GetParameterInfo()
       
    def initializeParameters(self):
        if self.params[0].altered:
            project = self.params[0].value
            aprx = arcpy.mp.ArcGISProject(project)

            layouts_list = aprx.listLayouts()

            self.params[1].filter.list = layouts_list
       
       return
   
    def updateParameters(self):
        return
   
    def updateMessages(self):
        return
0 Kudos
1 Reply
KarolDuarte
New Contributor II

So, I figured out a workaround (probably not the best, but it worked for me).

My layout parameter was set as "type layout". So, instead, I configured as "type string", and used the layouts' names for the filter list.
Inside the script I compare the selected names back with the layouts names inside the project, and export those selected.

Here:

class ToolValidator(object😞
    def __init__(self):
        self.params = arcpy.GetParameterInfo()
       
    def initializeParameters(self):

        resolutions = [100, 150, 200, 250, 300, 600]
        self.params[3].filter.list = resolutions
       
        qualities = ['BEST', 'BETTER', 'NORMAL', 'FASTER', 'FASTEST']
        self.params[4].filter.list = qualities

        return
   
    def updateParameters(self):
        if self.params[0].altered:
            project = self.params[0].value
            aprx = arcpy.mp.ArcGISProject(project)

            layouts_list = aprx.listLayouts()
            layouts_filter_list = [l.name for l in layouts_list]

            self.params[1].filter.list = layouts_filter_list

        return
   
    def updateMessages(self):
        return

 

0 Kudos