As part of the validation for parameters of a Python toolbox, I need to check if the text in parameter #1 is exists in a layer in a MXD file selected as parameter #2. Currently, I use this code in
mxd = arcpy.mapping.MapDocument(parameters.valueAsText) layer = arcpy.mapping.ListLayers(mxd, "LayerName") condition = u"Field=" + parameters.text with arcpy.da.SearchCursor(layer.dataSource, ["Field"], condition) as cursor: #Do some stuff...
The problem is that this takes very long time since the rather large MXD file has to be opened. It is not acceptable to have a two minute waiting time with ArcMap freezing every time the parameter validation is performed.
So my question is this: Is there any way to find the source of the layer, and search for a value in it, without having to open the MXD?