ArcPy: Issue with MXD="CURRENT" and DataFrame for Tool

1922
3
09-24-2010 08:45 AM
RyanKelley
New Contributor II
I have written a script that calculates acres or miles for layers in my MXD.  When I copy and paste the code from my Python textfile into the arcpy window, it runs great and executes (I have static arguments) when testing.

However, when I turn this script into a tool, I get an error (000714)... which basically tells you there is an error with your script. I have tried both system arguments and static arguments. I do have bacground processing turned off.

After trying to troubleshoot the issue, it does not like:

MXD = arcpy.mapping.MapDocument("CURRENT")
&
DF = arcpy.mapping.ListDataFrames(MXD)[0]

If I point my MXD to an existing MXD on disk, it gets through that line of code, but still stops at the DF part.

I guess I am not toally sure how the tool talks top the MXD.  It would only make sense to me that having a "CURRENT" mxd would allow for buttons, tools, etc. to execute in any ArcMap session.

Any help would be greatly appreciated!!

Ryan Kelley
OR/WA BLM
Portland, OR
0 Kudos
3 Replies
RyanKelley
New Contributor II
I seemed to have fixed the problem by checking the boxes "Always run in foreground" and "Run Python script in process" under the tool properties.
0 Kudos
JeffBarrette
Esri Regular Contributor
Hello Ryan,

I was hoping you had background processing enabled.  But you don't.  That must be turned off for CURRENT to work within a script tool. 

Everything you say should be working the way you expect it to. Could you please send me your script/ script tool to jbarrette@esri.com.  I'd like to look at it a bit more. 

Jeff
0 Kudos
JeffBarrette
Esri Regular Contributor
Oops - I see you found the solution.  Great job!

The "always run in foreground" option was specifically added due to CURRENT.  Current uses the application in memory and if you run in background, the current application can't be referenced.

Jeff
0 Kudos