The problem I'm encountering is that this filter doesn't seem to actually limit what the end user can see or enter as parameter. For example when they navigate to provide a file geodatabse the dialog allows them to see and enter .lyr files.
I'm assuming that you should be able to limit what the end user can see and enter when it comes to workspaces?
I think your 'getParameterInfo' section is ok. You will want to see all the folders, etc. to be able to navigate to the gdb. You can then use 'updateMessages' to display an error message if a file or personal geodatabase is not selected. To clear the error, the user would need to make the proper choice or exit the tool. EDIT: changed line 31 'and' to 'or'.
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 = "Input Workspace", name = "in_workspace", datatype = "DEWorkspace", parameterType = "Required", direction = "Input") return [param0] def isLicensed(self): return True def updateParameters(self, parameters): return def updateMessages(self, parameters): """Modify the messages created by internal validation for each tool parameter. This method is called after internal validation.""" if parameters.valueAsText is not None: gdb = parameters.valueAsText desc = arcpy.Describe(gdb) if ( desc.dataType != "Workspace" ) or ( gdb[-4:].upper() not in ('.GDB', '.MDB') ): parameters.setErrorMessage("Please select a file or personal geodatabase (.gdb or .mdb)") return def execute(self, parameters, messages): """The source code of the tool.""" return
Thanks for the reply Randy. While it looks like your solution will accomplish my desired outcome. I guess I'm still really wanting to know if the filter options outlined in the documentation are accurate and function as outlined.
I tested your code and it works ust fine, I think it has been solved.
But maybe you can try to do this:
param0 = arcpy.Parameter( displayName="Input Workspace", name="in_workspace", datatype="DEWorkspace", parameterType="Required", direction="Input") # Set the filter to accept only local (personal or file)geodatabases param0.filter.list = ["Local Database",'gdb'] params = [param0]
Check how I added "gdb" to the filter list.