cjustinmayers

Finding script location... dynamically

Discussion created by cjustinmayers on Feb 6, 2012
Latest reply on Feb 6, 2012 by Dan_Patterson
Should be a simple question... but those can be the hardest. I have created a script that uses ESRI's arcpy site package and it functions properly in a stand-alone environment. I am now trying to integrate this script into a toolbox to be run within an open ArcMap session and I am having trouble. In integrating this script I am using the tool structure that ESRI suggests... http://goo.gl/eesrV . The script I have created has information in the 'ToolData' folder that I need to access to run the script.

So the question is how do I locate the script's directory dynamically when running it in an open ArcMap session?  In my stand-alone script I use 'os.getcwd()'; this works because it returns the proper location of the script and I then know the structure around it. Whereas when incorporated as a script in a tool box and run within an ArcMap session 'os.getcwd()' returns the directory of the map document while the toolbox, script, and tool data are located where ever the user installed them and my script can't find this structure. Thanks for your help.

Outcomes