Select to view content in your preferred language

Passing an Array from Flex to a Python Script

2204
1
02-23-2011 08:56 AM
PlanningLDS
Emerging Contributor
Hello all,
I am having difficulty passing multiple values from flex to a Python script using gp.submitJob().  I've tried several things including passing them in an array and as a custom object class.  I feel like my problem might be on the python side.  The script is supposed to read extents and scale from the flex app and print a PDF.

In Python I have:
import arcgisscripting
import os

# Import arcpy module
import arcpy
from arcpy import env

# Set active MXD, Data Frame, and Layer
mxd = arcpy.mapping.MapDocument(r"D:\AGIS_MXDs\PermitPrintToScale.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]

# Script arguments
fromFlex = arcpy.Array()
fromFlex = arcpy.GetParameter(0)

minX = fromFlex.getObject(0)
if minX == '#' or not minX:
    minX = 727834

minY = fromFlex.getObject(1)
if minY == '#' or not minY:
    minY = 649034

maxX = fromFlex.getObject(2)
if maxX == '#' or not maxX:
    maxX = 938634

maxY = fromFlex.getObject(3)
if maxY == '#' or not maxY:
    maxY = 754900

mapScale = fromFlex.getObject(4)
if mapScale == '#' or not mapScale:
    mapScale = 100
  
# Set Data Frame to the extents passed from Flex
newExtent = df.extent
newExtent.XMin, newExtent.YMin = float(minX), float(minY)
newExtent.XMax, newExtent.YMax = float(maxX), float(maxY)
df.extent = newExtent

# Set scale of the Data Frame to the value passed from flex
# Multiply by 12 to adjust to geographic scale
df.scale = float(mapScale) * 12

# Print to PDF
arcpy.mapping.ExportToPDF(mxd, r"C:\Inetpub\wwwroot\PrintToScalePDF\Print_Output.pdf")

Any help would be greatly appreciated.  If there is an easier way to pass the extents into python I am all ears, but I am still interested in knowing how to pass an array regardless.  Many thanks forum users!

Greg
Allegany County, MD GIS
Tags (2)
0 Kudos
1 Reply
PlanningLDS
Emerging Contributor
I'm replying to my own question.  Instead of passing an array I have switched to passing all the strings individually instead.  The widget is working better now but the output PDF extent is about a mile or two south of what I am viewing in flex.  Any insight would be appreciated.

In flex:
<esri:Geoprocessor
id="gp"
jobComplete="openPDF(event)"
url="http://arcgis.allconet.org/ArcGIS/rest/services/PermitDashboard/GPServer/PrintToScale"
showBusyCursor="true"/>

public var urlPDF:String = "http://arcgis.allconet.org/PrintToScalePDF/Print_Output.pdf";

private function submit():void
   { 
    var params:Object = {inMinX:map.extent.xmin.toString(), inMinY:map.extent.ymin.toString(), inMaxX:map.extent.xmax.toString(), inMaxY:map.extent.ymax.toString(), inScale:txtScale.text};     
    gp.submitJob(params);         
   }
   
   private function openPDF(event:GeoprocessorEvent):void
   {
    var urlRequest:URLRequest = new URLRequest(urlPDF);
                navigateToURL(urlRequest);


And in Python:
import arcgisscripting
import os

# Import arcpy module
import arcpy
from arcpy import env

# Set active MXD, Data Frame, and Layer
mxd = arcpy.mapping.MapDocument(r"D:\AGIS_MXDs\PermitPrintToScale.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]

# Script arguments
minX = arcpy.GetParameterAsText(0)
if minX == '#' or not minX:
    minX = 727834

minY = arcpy.GetParameterAsText(1)
if minY == '#' or not minY:
    minY = 649034

maxX = arcpy.GetParameterAsText(2)
if maxX == '#' or not maxX:
    maxX = 938634

maxY = arcpy.GetParameterAsText(3)
if maxY == '#' or not maxY:
    maxY = 754900

mapScale = arcpy.GetParameterAsText(4)
if mapScale == '#' or not mapScale:
    mapScale = 100
   
# Set Data Frame to the extents passed from Flex
newExtent = df.extent
newExtent.XMin, newExtent.YMin = float(minX), float(minY)
newExtent.XMax, newExtent.YMax = float(maxX), float(maxY)
df.extent = newExtent

# Set scale of the Data Frame to the value passed from flex
# Multiply by 12 to adjust to geographic scale
df.scale = float(mapScale) * 12

# Print to PDF
arcpy.mapping.ExportToPDF(mxd, r"C:\Inetpub\wwwroot\PrintToScalePDF\Print_Output.pdf")


I'm still interested in being able to pass an array to python if possible.  Also, the performance of the above code leaves something to be desired.  It takes about five minutes to get the PDF.

Greg
Allegany County, MD GIS
0 Kudos