Select to view content in your preferred language

Dumb question - can I write standalone python script to run without arcgis?

8708
31
05-18-2010 11:54 PM
jimparsons
Occasional Contributor
I need to open a raster, thin it, and save it. Can I do that in a script outside of arcgis, or does arcgis need to be running for the script to work? I have it installed on the system, so it would obviously be running on my computer.

Sorry this question is really simple. I don't really understand how to run a script outside of arcgis...or even if it's possible. I'm hoping someone will say yes or no! Thanks
0 Kudos
31 Replies
LoganPugh
Frequent Contributor

You should really look into the python logging, its wonderful: http://docs.python.org/library/logging.html

However you need to create a gp friendly logger... heres an example:


Frank I finally got around to trying this and I had to tweak one line to get it to work:

The line:
if type(sys.stdout)) != "<type 'geoprocessing sys.stdout object'>":


I had to strip whitespace from the type check because on my machine at least it adds whitespace after the type for some reason. So the fixed line is:
if str(type(sys.stdout)).strip() != "<type 'geoprocessing sys.stdout object'>":


Thanks for the nifty example!
0 Kudos
LucianoCampagnolo
Emerging Contributor
Hi...
I've a problem with standalone scripts running as 'standalone' 🙂

Let me clarify:
- The scripts run smoothly within an ArcSomething session, be it from Python window or a Script tool added to some toolbox.
- When fired from console (in fact: another program calls it after another non-gis process) or Eclipse or IDLE or anything non-ArcSomething; the execution fails with a "Parameters are not valid" - "ERROR 000824: The tool is not licensed" error.
- The code has the appropriate import arcinfo and arcpy.CheckOutExtension statements.

Running ArcGIS 'for' Desktop (:P) 10 fully patched.

Any help will be appreciated and will post a sum or solution upon successful outcome...

Cheers!
0 Kudos
DannyLackey
Deactivated User
I wrote a simple script in arcGis and I'm trying to call it without arcgis open.  My plan is to put this in task scheduler to automatically create a PDF.  The script works great within ArcGIS, just not sure how to create an external file to call it (something I can load into windows task scheduler.  My .py file is "PDF_Export_SAPT.py" and the script within it is:
mxd=arcpy.mapping.MapDocument("CURRENT")
arcpy.RefreshActiveView();arcpy.RefreshTOC()
arcpy.mapping.ExportToPDF (mxd,"I:\GIS_Workspace\Ventura_Area\Danny\SAPT_MAP.pdf")

I read in this forum that I can call it from a cmd prompt, which I tried, but got a a syntax error.  I just typed in the name of my .py file and hit enter.  I don't know which (if any) parameters to use.  Here is a screen of error:

[ATTACH=CONFIG]11097[/ATTACH]

Sorry to hijack thread - but I'm so close.  Not sure what type of file I need to create to call this script.  Batch?  thx!
0 Kudos
JasonScheirer
Esri Alum
You can't use CURRENT outside of ArcMap.
0 Kudos
BruceNielsen
Frequent Contributor
Try changing "CURRENT" to the full path name of your .mxd file. CURRENT only works when you are in ArcMap.
0 Kudos
DannyLackey
Deactivated User
Well, that eliminated the error, but now NOTHING happens.  Doesn't produce a .pdf.  Was I calling it from command prompt correctly? 

Current code:

mxd=arcpy.mapping.MapDocument("I:\GIS_Workspace\Ventura_Area\Danny\SAPTList.mxd") arcpy.RefreshActiveView();arcpy.RefreshTOC() arcpy.mapping.ExportToPDF (mxd,"I:\GIS_Workspace\Ventura_Area\Danny\SAPT_MAP.pdf")

I even tried placing the .py file inside the python directory and calling it like "python PDF_Export_SAPT.py" (without quotes), still nothing.
0 Kudos
DannyLackey
Deactivated User
Ok, tried running it in python shell and got this error:

>>> mxd=arcpy.mapping.MapDocument("I:\GIS_Workspace\Ventura_Area\Danny\SAPTList.mxd")
arcpy.RefreshActiveView();arcpy.RefreshTOC()
arcpy.mapping.ExportToPDF (mxd,"I:\GIS_Workspace\Ventura_Area\Danny\SAPT_MAP.pdf")
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
mxd=arcpy.mapping.MapDocument("I:\GIS_Workspace\Ventura_Area\Danny\SAPTList.mxd")
NameError: name 'arcpy' is not defined>>>

Again, this SAME script run beautifully in ArcGIS.
0 Kudos
JasonScheirer
Esri Alum
import arcpy first.
0 Kudos
DannyLackey
Deactivated User
Tried
import arcpy.mapping

Tried in python shell
got this error:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import arcpy.mapping
ImportError: No module named arcpy.mapping
Forgive me... Fairly new to ArcGIS...and python.. What would that line of code look like?
0 Kudos
DannyLackey
Deactivated User
Ok, I got it with import arcpy.  Works great.  However, its panning the map all of the way out so the .pdf file is about 24mb.  Now I need to research the code to change scale/focus area.  thank you!!!
0 Kudos