Skip to main content
edited tags
Source Link
PolyGeo
  • 65.5k
  • 29
  • 115
  • 352

Finding script location... dynamically when using ArcPy?

Should be a simple question... but those can be the hardest. I have created a script that uses ESRI'sEsri'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... https://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html . The script I have created has information in the 'ToolData' folder that I need to access to run the script.

So the question is howHow do I locate the script's directory dynamically when running it in an open ArcMap session? In

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 on 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.

Finding script location... dynamically

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... https://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html . 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 on 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.

Finding script location dynamically when using ArcPy?

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... https://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html . The script I have created has information in the 'ToolData' folder that I need to access to run the script.

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 on 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.

Tweeted twitter.com/#!/StackGIS/status/166619439163379714
Source Link

Finding script location... dynamically

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... https://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html . 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 on 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.