Select to view content in your preferred language

EsriTimeDelta = a string as GetParameterAsText Please Help, I need this answered ASAP

1127
2
Jump to solution
04-14-2013 10:07 PM
courtneygarlock
Emerging Contributor
I'm trying to set units to a string and then as a parameter. The EsriTimeDelta syntax is EsriTimeDelta (interval, units)

When I run the code below in a script tool I keep getting an error message for the units, it will fail to run the script.

If there is an easier way please help! I need this question answered by Monday.


 df.time.currentTime = datetime.datetime(2009, 01, 1, 00, 00)  endTime = datetime.datetime(2009, 01, 1, 23, 59) tsi = arcpy.GetParameterAsText(1) units = "'" + arcpy.GetParameterAsText(2) interval = arcpy.time.EsriTimeDelta(tsi, units)  


In this code I get an error saying that the interval must be a float. But the interval (double) units (string) according to the help.
I also didn't set the units to a string in this instance and the script would actually run. But now I'm getting the error I just mentioned.


 df.time.currentTime = datetime.datetime(2009, 01, 1, 00, 00)  endTime = datetime.datetime(2009, 01, 1, 23, 59) tsi = arcpy.GetParameterAsText(1) units = arcpy.GetParameterAsText(2) interval = arcpy.time.EsriTimeDelta(tsi, units)  count = 0  while df.time.currentTime <= endTime:     fileName = str(df.time.currentTime).split(" ")[0] + str(count) + ".jpg"     arcpy.mapping.ExportToJPEG(mxd, os.path.join(inFolder, fileName), data_frame)     df.time.currentTime = df.time.currentTime + interval     count += 1 
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ArkadiuszMatoszka
Frequent Contributor
Hi,
I've already answered to your question in previous thread:
http://forums.arcgis.com/threads/81296-can-t-export-correct-images-using-script-tool-works-fine-in-r...

getParameterAsText() does exactly what it sounds, it's getting attribute as text (string if you prefer). So if you need any other type of parameter you need to convert it.
tsi = arcpy.GetParameterAsText(1) units = arcpy.GetParameterAsText(2) interval = arcpy.time.EsriTimeDelta(tsi, units)

In this code you pass two string variables to arcpy.time.EsriTimeDelta()
changing line to :
tsi = float(arcpy.GetParameterAsText(1))

Should resolve issue with interval type.
Best Regards
Arek

View solution in original post

0 Kudos
2 Replies
ArkadiuszMatoszka
Frequent Contributor
Hi,
I've already answered to your question in previous thread:
http://forums.arcgis.com/threads/81296-can-t-export-correct-images-using-script-tool-works-fine-in-r...

getParameterAsText() does exactly what it sounds, it's getting attribute as text (string if you prefer). So if you need any other type of parameter you need to convert it.
tsi = arcpy.GetParameterAsText(1) units = arcpy.GetParameterAsText(2) interval = arcpy.time.EsriTimeDelta(tsi, units)

In this code you pass two string variables to arcpy.time.EsriTimeDelta()
changing line to :
tsi = float(arcpy.GetParameterAsText(1))

Should resolve issue with interval type.
Best Regards
Arek
0 Kudos
courtneygarlock
Emerging Contributor
thank you so much, this works fine!
0 Kudos