Friday, 29 April 2016

arcgis desktop - Script runs in ArcMap Python window but not in standalone PythonWin or IDLE?


I am attempting to automate some basic geoprocessing for a web map service. I am using ArcGIS 10.1 for Desktop.


This code was built in ModelBuilder and exported to python.


This runs perfectly in ArcGIS for Desktop.



However it returns error 000732 for both the "Service_Group" dataset and the Excel sheet that are to be joined when ran Outside of Arc.


I have changed the #Local Variables to a UNC path with no luck.


    import arcpy
mxd = arcpy.mapping.MapDocument(r"X:\Mikes_Workspaces\Outage\Outage.mxd")
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
# Script arguments
OutCurrent = arcpy.GetParameterAsText(0)
if OutCurrent == '#' or not OutCurrent:
OutCurrent = "X:\\Geodatabases\\WebData\\Water_Service.gdb\\OutCurrent" # provide a default value if unspecified


# Local variables:
Service_Group = "Service_Group"
Update_ = "S:\\Pump and Canal Patrol\\Water On\\4-7-15\\Outage_Board.xls\\Update$"
Group_Out = "Service_Group"

# Process: Add Join
arcpy.AddJoin_management(Service_Group, "Group_", Update_, "Group_Out", "KEEP_COMMON")

# Process: Copy Features
arcpy.CopyFeatures_management(Group_Out, OutCurrent, "", "0", "0", "0")

# Process: Symbology
arcpy.ApplySymbologyFromLayer_management("OutCurrent", "X:\Mikes_Workspaces\Online Shapefiles\Outage_today.lyr")
# Process: Remove Join
arcpy.RemoveJoin_management(Service_Group, "")

This is the error received:


    Traceback (most recent call last):
File "C:\Python27\ArcGISx6410.1\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
exec codeObject in __main__.__dict__
File "E:\GIS\Mikes_Workspaces\Automation\OutageUpdate.py", line 15, in

arcpy.AddJoin_management(Service_Group, "Group_", Update_, "Group_Out", "KEEP_COMMON")
File "C:\Program Files\ArcGIS\Server\arcpy\arcpy\management.py", line 5325, in AddJoin
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Layer Name or Table View: Dataset Service_Group does not exist or is not supported
ERROR 000732: Join Table: Dataset S:\Pump and Canal Patrol\Water On\4-7-15\Outage_Board.xls\Update$ does not exist or is not supported
Failed to execute (AddJoin).


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...