1

I have this python script that I execute inside the ArcMap Python Window and it does an array of spatial analysis processes to get me to my desired final mxd content. I then have another script that overrides my existing feature classes on my AGOL account with the current layers in the open mxd. : Click Here (it is necessary that this script is ran outside of ArcMap via the Python shell. )

The only issue is that after I run my first script in ArcMap I then have to open my python shell outside of ArcMap in order to run the second script. I am trying to find a way to execute the 2nd script from the first script without manually leaving arcmap to open my python shell and load the script. But keep in mind my first script is being run from the ArcMap Python Window. SO I cannot figure out a way to escape that... hope this question makes sense and is this even possible. I am basically trying to eliminate all user-interaction to completely automate this task once I load the first script into ArcMap.

Please feel free to ask if this does not make sense.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
NULL.Dude
  • 2,131
  • 2
  • 14
  • 32
  • In the first script, add code to import and execute the second script. – Tom Jan 04 '17 at 16:33
  • I tried import OS and then tried to execute the 2nd script but it doesn't work. It needs to be ran via shell (from what the ESRI guy told me) so I need to activate python shell from arcmap if that makes sense. – NULL.Dude Jan 04 '17 at 16:34
  • What is the difference between the two scripts? Why can you run one but not the other? – Tom Jan 04 '17 at 16:35
  • 1
    first script is just spatial.analysis processes such as clips, selects, geocoding, etc. the 2nd script connects to my AGOL account and overwrites an existing service with the new output from my first script. The 2nd script is linked in OP. but ESRI support says it must be ran from python shell and not ArcMap Python Window.. which is where I am stuck trying to execute. – NULL.Dude Jan 04 '17 at 16:41
  • Have you tried anything like execfile or subprocess? – Tom Jan 04 '17 at 16:42
  • When importing the script did you also import sys module and point to the script location using sys.path.append? – geoJshaun Jan 04 '17 at 16:50
  • No I did not import sys module... never worked with that before let me see if I can figure that out. I should alsomention that the 2nc script also reads a settings.ini file which is located in the same directory as the 2nd script. – NULL.Dude Jan 04 '17 at 16:53
  • So when I try to execfile (path to file) it returns cannot find settings.ini file, be sure its in the same directory. WHich it is in the same directory and when i run the script via shell it finds it fine. – NULL.Dude Jan 04 '17 at 16:56
  • 2
    Your .ini is probably referenced by a relative path in your script. Use absolute paths or Try changing your working directory in ArcMap before executing the gp script http://stackoverflow.com/questions/1810743/how-to-set-the-current-working-directory-in-python – Ben S Nadler Jan 04 '17 at 17:16

0 Answers0