POST
|
I believe that this is what I've done. the .getParameterInfo() loads the data, while the .execute() saves the data. As I stated, the data is saved and executed correctly, but it does not assigned as default value, unless I refresh the toolbox.
class select_data(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Select Data"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
cursor = arcpy.da.SearchCursor("Parameters", ['data_set'])
for row in cursor:
ds=row[0]
param0 = arcpy.Parameter(
displayName="File",
name="in_file",
datatype="GPString",
parameterType="Required",
direction="Input")
param0.value=ds
params = [param0]
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."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
arcpy.env.workspace =""
cursor = arcpy.da.UpdateCursor("Parameters", ['data_set'])
for row in cursor:
row[0]=parameters[0].valueAsText
cursor.updateRow(row)
ds="-"+parameters[0].valueAsText
stp1=arcpy.mapping.Layer("direct_xfer_trips")
stp2=arcpy.mapping.Layer("direct_trips")
stp3=arcpy.mapping.Layer("xfer_trips")
stp4=arcpy.mapping.Layer("xfer_pot")
mxd = arcpy.mapping.MapDocument("CURRENT")
stp1.replaceDataSource("shape_files","SHAPEFILE_WORKSPACE","stops"+ds)
stp2.replaceDataSource("shape_files","SHAPEFILE_WORKSPACE","stops"+ds)
stp3.replaceDataSource("shape_files","SHAPEFILE_WORKSPACE","stops"+ds)
stp4.replaceDataSource("shape_files","SHAPEFILE_WORKSPACE","stops"+ds)
del mxd
return
... View more
08-14-2014
03:58 AM
|
0
|
1
|
1469
|
POST
|
I think I was not clear with the problem. Parameter A's value in the file is "0" (from previous execution). Toolbox is being refreshed from the catalog window. First execution of the toolbox. Parameter A default value is being read from the file. On screen default value is "0". Parameter A is set to "1". The rest of execution is with value "1". Value "1" is updated to the file. Second execution of the toolbox. Parameter A default value is being read from the file. On screen default value is "0" (should have been "1"). Parameter A is set to "2". The rest of execution is with value "2". Value "2" is updated to the file. Toolbox is being refreshed from the catalog window. Third execution of the toolbox. Parameter A default value is being read from the file. On screen default value is "2" (due to refresh)...
... View more
08-13-2014
01:02 PM
|
0
|
3
|
1469
|
POST
|
In order to ease the entry of the parameters, whenever the toolbox is opened, the latest parameters are being read from a table, and if changed are saved back. The problem is that the toolbox must be manually refreshed every time for the parameters to be displayed correctly. def getParameterInfo(self): cursor = arcpy.da.SearchCursor("Parameters", ['data_set', 'date_p', 'from_p', 'to_p', 'location_p', 'wait_p', 'distance_p']) for row in cursor: ds=row[0] date_p=row[1] from_p=row[2] to_p=row[3] location_p=row[4] wait_p=row[5] distance_p=row[6] l_ds="results-"+ds param0 = arcpy.Parameter( displayName="Destinations", name="in_destinations", datatype="GPString", parameterType="Required", direction="Input") param0.filter.type = "ValueList" values = [row[0] for row in arcpy.da.SearchCursor(l_ds, ("location"))] param0.value=location_p lst = list(set(values)) lst.sort() param0.filter.list = lst . . . def execute(self, parameters, messages): arcpy.env.workspace ="" location_p=parameters[0].valueAsText date_p=parameters[1].valueAsText from_p=parameters[2].valueAsText to_p=parameters[3].valueAsText wait_p=parameters[4].valueAsText distance_p=parameters[5].valueAsText cursor = arcpy.da.UpdateCursor("Parameters", ['date_p', 'from_p', 'to_p', 'location_p', 'wait_p', 'distance_p']) for row in cursor: row[0]=date_p row[1]=from_p row[2]=to_p row[3]=location_p row[4]=wait_p row[5]=distance_p cursor.updateRow(row) . . .
... View more
08-13-2014
11:46 AM
|
0
|
7
|
7370
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|