Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am building a script to automate a water outage map(I'm new to Python). In the ArcGIS Desktop 10.1 window the script runs fine. However in Pythonwin and IDLE I get syntax errors(In Pythonwin reads: Failed to run script-syntax error-Invalid syntax). The goal is to use task scheduler to run the script outside of ArcGIS.

enter image description here

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_ = "X:\\Mikes_Workspaces\\Outage\\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, "")
mxd.save()
arcpy.RefreshActiveView()
share|improve this question
    
I think there must be something else in your script that we are not seeing. Did you post your code by using a ctrl-A/ctrl-C in your script, ctr-V into the edit window here and then apply {} with no other steps? –  PolyGeo Apr 9 at 22:13
1  
The path in ApplySymbologyFromLayer is not escaped as the others. Can you try that? Also, just curious what you plan is for GetParameterAsText, run from Task Scheduler. edit: it doesn't look like either \M or \O is an escape sequence, so that may not be the issue. –  phloem Apr 9 at 22:21
    
Did you run the script as a saved file and then via the toolbox, or in the Python window? –  Erica Apr 10 at 0:13
    
I would suggest to execute each statement one by one in IDLE to identify where the hang up is. –  artwork21 Apr 10 at 1:36
    
RemoveJoin should have the name of the join and not "", try adding the join and removing it in model builder then export that to python to understand the syntax a bit better. Joining with Excel spreadsheets can be a bit flaky and can insert random errors, could you convert it to a file/personal geodatabase table? –  Michael Miles-Stimson Apr 10 at 3:53

2 Answers 2

arcpy.GetParameterAsText is for accessing parameters in Script Tools.

If you're going to run this outside of ArcGIS, you'll need another way to pass parameters in a command line, such as sys.argv.

Have a look at this page for some examples uses: http://www.tutorialspoint.com/python/python_command_line_arguments.htm

Here's more information on the sys module: https://docs.python.org/2/library/sys.html

share|improve this answer
1  
Using arcpy.GetParameterAsText(i) outside of script tools works just fine. –  Luke Apr 10 at 0:42
    
I stand corrected. Good to know. –  Fezter Apr 10 at 0:43
    
Either works, sys.argv[] is less typing and is all lower case, it's GetParameter that's funny as it expects an object which doesn't convey well on the command line. –  Michael Miles-Stimson Apr 10 at 3:56

check your indentation, your OutCurrent = "X... line looks like it is indented 5 spaces compared to the others. An error should have thrown more information as well

share|improve this answer
    
Looks like 4 spaces to me. –  Fezter Apr 10 at 4:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.