Hi, I need to know the scale of an mxd in a web application. For that I am running a geoprocessing service. I need to know the scale when there is a definition query and the map zooms in to that feature. I can see in the message that the scale changes, but the output in the web application is always the same scale, although the input feature changes. What am I doing wrong? Thank you for any help.
import arcpy
import os
import uuid
# Input Layout template
Layout_Template = arcpy.GetParameterAsText(0)
if Layout_Template == '#' or not Layout_Template:
Layout_Template = "StewardshipTractBoundaryMap"
layouttemplatemxd = Layout_Template
templatePath = 'D:/ArcGISData/Geoprocessing_Examples/Advanced_HighQualityPrinting3'
Selecting_Features = arcpy.GetParameterAsText(1)
Input_Polygons = "Stewardship"
mxd0 = arcpy.mapping.MapDocument(r"D:\ArcGISData\Geoprocessing_Examples\Advanced_HighQualityPrinting3\\" + layouttemplatemxd + ".mxd")
df1 = arcpy.mapping.ListDataFrames(mxd0, "DataFrame1")[0]
mxd0.activeView = df1
lyr1 = arcpy.mapping.ListLayers(mxd0, Input_Polygons, df1)[0]
lyr1.definitionQuery = ""
lyr1.definitionQuery = '"PlanID" = \'%s\'' % Selecting_Features
df1.panToExtent(lyr1.getSelectedExtent())
lyr1.getExtent()
lyr1extent = lyr1.getExtent()
df1.extent = lyr1extent
Scale = str(df1.scale)
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
mxd0.save()
arcpy.SetParameterAsText(2, Scale)
lyr1.definitionQuery = ""
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
arcpy.AddMessage(Scale)
mxd0.save()
del mxd0, df1, lyr1
Set the output parameter?
arcpy.SetParameterAsText(1, Scale)
But since I have :
Layout_Template = arcpy.GetParameterAsText(0)
Selecting_Features = arcpy.GetParameterAsText(1)
Shouldn't it be arcpy.SetParameterAsText(2, Scale) like it is now?
I suppose if that is the second output parameter. I didn't notice the first output parameter in the code sample you posted.
Also: do you get any output result when you execute the task from the services url?
No, there is only one output parameter, but I thought the input and output parameters shared indexes, no? So, even thought it is the first output parameter, it should have an index of 2, not of 0, because there are two input parameters. This example shows that the output parameter is indexed as 1 because there is a input parameter first.
Perhaps I'm misunderstanding it myself but I read it as this being the index of the output parameters only.
In any case, if there's only one output, set it to 1 like I showed! --- in looking at my own codebase, the only example I have is where I am setting a single output parameter not a list of them. This returns a JSON output string that is the result of some geoprocessing:
arcpy.SetParameterAsText(1, json.dumps(data))
How many inputs do you have on this example?
1 LOL!
Then that explains why your gp works, if you have one input parameter its index should be 0 and if you also have an output parameter then the index should be 1, because they share index values. But I will try your approach, although I dont think it is going to fix the problem. Thank you
Sorry I don't have an immediate answer. I'd love to hear what you find out though as I'm sure I will run into the requirement of multiple params for a geop service at some point.