mallID = arcpy.GetParameterAsText(0) #the first parameter in script tool storeID = arcpy.GetParameterAsText(1) #the second parameter in script tool mxd = arcpy.mapping.MapDocument("current") lyr = arcpy.mapping.ListLayers(mxd, "My Mall Layer")[0] lyr.definitionQuery = '"MallID" = ' + str(mallID) + ' AND "StoreID" = ' str(storeID) arcpy.RefreshActiveView()
def initializeParameters(self): #THIS IS CALLED WHEN THE SCRIPT TOOL OPENS AND AUTO POPULATES THE FIRST PARAMETER """Refine the properties of a tool's parameters. This method is called when the tool is opened.""" #Generate unique list of Mall IDs import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") mlyr = arcpy.mapping.ListLayers(mxd, "My Mall Layer") fieldName = "MallID" rows = arcpy.SearchCursor(mlyr.dataSource) uniqueMallList = [] for row in rows: if row.getValue(fieldName) not in uniqueMallList: uniqueMall.append(row.getValue(fieldName)) uniqueMallList.sort() self.params[0].filter.list = uniqueMallList return def updateParameters(self): #THIS IS CALLED WHEN THE FIRST PARAMETER IS SELECTED AND POPULATES 2ND PARAMETER """Modify the values and properties of parameters before internal validation is performed. This method is called whenever a parmater has been changed.""" import arcpy if self.params[0].value: #Generate unique list of Store IDs slyr = arcpy.mapping.ListLayers(mxd, "My Store Layer") fieldName = "StoreID" rows = arcpy.SearchCursor(slyr.dataSource) uniqueStoreList = [] for row in rows: if row.getValue(fieldName) not in uniqueStoreList: uniqueStoreList.append(row.getValue(fieldName)) uniqueStoreList.sort() self.params[1].filter.list = uniqueStoreList return
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.