How to run python script without opening the mxd?

594
1
07-21-2011 04:07 PM
BartKowalski
New Contributor
Howdie,
I just wrote my first python script that copies an even layer to a shp (yay!). It works fine when I run it in python window with the mxd already open. However, if I run the code without  opening the mxd, I get the dataset "does not exist" error message, and if I run it outside of ArcMap entirely, I get a bunch of error messages.
Ultimately, I want to schedule a task that runs the python script like an executable. I understand that the first case is probably due to the fact that I don't have a full path, but it is an event layer, so I am not sure what to put in the path.
Any help would be greatly appreciated.

Thanks,

import arcpy
#set the overwrite option
arcpy.env.overwriteOutput = 'true'
#define the mxd
mxd = arcpy.mapping.MapDocument(r"G:\Temp\Bart\mxds\Parcel_map.mxd")
#copy specified layer to a new shapefile
arcpy.CopyFeatures_management("Transfer Status","G:\Temp\Bart\Shapefiles\PyTest6.shp")
Tags (2)
0 Kudos
1 Reply
DuncanHornby
MVP Notable Contributor
Bart,

Sounds like you have found a bug? Alternatively (although not tested by me) is you could create the event layer using the arcpy.MakeXYEventLayer_management tool from the table as you know what the table is called and never have the need to "enter" the MXD?

Just an idea...

Duncan
0 Kudos