How to get current workspace from tool Environment?

6801
2
Jump to solution
08-05-2016 11:07 AM
AndreaBrugger
New Contributor

I believe this is a super basic question but I'm not having any luck so far and I am just learning all of this. When I am running a custom tool scripted in python using the ArcCatalog, how do I read in the current workspace environment so I can use it in my script?  This assumes before I run the script, I've clicked on the "Environments..." button and entered in the appropriate values for the current workspace and scratch workspace, etc.  For parameters, I use something like arcpy.GetParameterAsText(0), but how do I get the environment values that were provided in the script launch window?  Every example I find expects me to use something like arcpy.env.workspace = "c:/data/data.mdb", using a hard-coded path. I could create a parameter for the workspace too but it seems like I should be pulling the workspace from the configured environment.  Am I going about this wrong? 

Thanks

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

sorry, did you miss this in the arcpy tree ListEnvironments—Help | ArcGIS for Desktop there are several there such as GetSystemEnvironment—Help | ArcGIS for Desktop

You should always be setting your environments to begin with even if you think you know where they are set, this is a common area where script, models and builtin tools fail... the environments aren't known, they are in inappropriate folders or geodatabases and the lists go on.  If you need a scratch workspace... make one, use it, then delete it when a script process is done and you don't need the contents.  Temp is anything but...

View solution in original post

2 Replies
DanPatterson_Retired
MVP Emeritus

sorry, did you miss this in the arcpy tree ListEnvironments—Help | ArcGIS for Desktop there are several there such as GetSystemEnvironment—Help | ArcGIS for Desktop

You should always be setting your environments to begin with even if you think you know where they are set, this is a common area where script, models and builtin tools fail... the environments aren't known, they are in inappropriate folders or geodatabases and the lists go on.  If you need a scratch workspace... make one, use it, then delete it when a script process is done and you don't need the contents.  Temp is anything but...

AndreaBrugger
New Contributor

Thank you! Yes, I missed it and thank you for the help.

0 Kudos