Arcpy scripting works in Python window but not in Script

7281
12
08-04-2011 12:00 PM
LorindaGilbert
Occasional Contributor II
Okay, I am really at my wits end now.  The three previous posts were with the script - all written after testing in the python window.  Now I see that I am not having difficulties with the language even if I am just learning it, for these simple tasks, I have gotten the process.

Can SOMEONE please explain why the individual lines of script work in the python window from within an ArcMap session, but DO NOT work when saved as a script to be used as a tool?

The entire script is really quite simple:
After the mxd is opened in ArcMap,
Geocode some data (already know that a composite locator won't work on a Win7 x64 in script)
Update the symbology
Save the geocoded results as a fc in fgd with name_userid_date
Append the geocoded results to an existing fc in fgd with name_year_userid
Then the user prints maps as required

I mean really, this SHOULD NOT be this difficult.  When I tried the geocode portion, discovered that the composite wouldn't run in the script.  Then the update symbology works in window, not in script.  Save the geocoded results to either the current geocoded with date or append to the yearly file, get either an error 582 or the warning 117 of empty set created.

I have tried this on a Win7 x64 Arc10 SP1 machine and on an XP x32 SP3 Arc10 SP2 machine - scripting doesn't work on either one.

Guess the good thing is that we can always teach the new folks how to do the process the old fashioned way and then when we can figure out WHY the script isn't working and get it working then we can give them the tool.
0 Kudos
12 Replies
JasonPardy
New Contributor
Rather than letting the parameter for symbology_only default to True, try setting it to False:

arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, False)
0 Kudos
LorindaGilbert
Occasional Contributor II
Have one part of the script working, had to separate into two pieces though.  As simple of a process that I am attempting write, it is a shame that it has to be separated.

Anyway, over on the Python forum, they gave me help with getting a row count for the ungeocoded features, again it worked fine in the python window, but add it to a script and it fails!  This is getting old!  I have tried to run the script that was created using the wizard from Catalog opened thru ArcMap and as a tool in a toolbar in ArcMap - same errors both ways.

These are the error messages:

<class 'arcgisscripting.ExecuteError'>: ERROR 000622: Failed to execute (Make Feature Layer). Parameters are not valid.
ERROR 000628: Cannot set input into parameter in_features.

Failed to execute (ProcessCAUFile)

Yet when I copy and paste each line from the script into the python window - NO errors.  I've attached a copy of the script.
0 Kudos
ZacharyStauber
New Contributor
Did you get some resolution on this?  I have the same problem.  Only a very few very short scripts work as .py files, and then others, cutting and pasting is fine, running as a .py crashes, in my case with the generic "ERROR 000582: Error occurred during execution."  All I'm doing is trying to synchronize a replica.

import arcpy
from arcpy import env
env.workspace = "C:/data"
try:
 arcpy.SynchronizeChanges_management("c:/data/sde/envp as sde_admin.sde", "envp2local", "c:/data/sde_copy.gdb", "FROM_GEODATABASE1_TO_2", "", "", "")
except Exception as e:
 print e


I have checked all my sys.environ.items() and they're all the same running both ways, env.workspace is the same, PYTHONPATH is blank in both cases, path is the same, and I have no other versions of Python on this machine.
0 Kudos