Hi all
I would like to make a gp tool that return a layer that is a join between a layer and a table Below is a sample of one of my tries in python.
The output parameter is define as derived
The tool run in desktop and published but give error in server.
I do not want the user to give output name so I must define the output as derived.
Should I write my output to %scratchworkspace%?
Do I have to create a real feature class?
What is the right way to do it?
Thanks
Mody
import arcpy
tableName = arcpy.GetParameterAsText(0)
layerName = arcpy.GetParameterAsText(1)
# Local variables:
dbPath = r"C:\tmp\Mody.gdb"
local_table = os.path.join(dbPath ,tableName)
local_layer = os.path.join(dbPath ,layerName)
featureClassSelect = "Year = 2004"
arcpy.MakeFeatureLayer_management(local_layer,"t1",featureClassSelect)
arcpy.AddJoin_management("t1", "ID", local_table, "ID")
arcpy.CopyFeatures_management("t1",r"outFCPersistent")
arcpy.Delete_management("t1")
arcpy.SetParameterAsText(2,r"outFCPersistent")
What errors do you get when publishing? It will probably be best to create an "intermediate" feature class in your scratch workspace as you are doing with outFCPersistent. If the output is part of a Web Service that you are updating dynamically with this script, then you don't need to create a permanent feature class.
No error in publish
Error: Invalid return value: %scratchworkspace%\outFCPersistent with running.
Each run should create its own results (no connection to other results) but I do not like the user to give it a name - it should just returned.
Thanks
I have a GP service that does a similar thing with rasters, but I think the principle is the same. When saving, I include the full path, e.g.
arcpy.CopyFeatures_management("t1", arcpy.env.scratchGDB + r"\outFCPersistent")
Or, even better, if you have imported the os module,
arcpy.CopyFeatures_management("t1", os.path.join(arcpy.env.scratchGDB, "outFCPersistent"))
Be careful with the scratch workspace, as the behaviour is different between desktop and server. On desktop, you must set the scratch workspace, but on server it is automatically created for each job. Trying to set it actually clears the value and causes a lot of problems.
Oh, and if you are returning an actual feature class, you'll need to use SetParameter for the outputs, not SetParameterAsText. I think it should work with just the feature class name as in your example.
Hi
I found that using arcpy.env.scratchGDB is much better then the %scratchworkspace% that I use to use.
It is not replaced by anything when the tool is published.
Using SetParameter when your return value is not text might help too
Thanks all