get default environment

1697
4
03-18-2014 12:22 AM
HugoAhlenius
Occasional Contributor
Hi,
I am working on a little script, and I would like to get the default environment (more specifically the default geoprocessing workspace).

How can I get that? I am looking at a way to create a new instance of arcpy module and get it from there, but I am not sure how to do that!

Thanks,
Hugo
Tags (2)
0 Kudos
4 Replies
AhmedEl-Sisi
Occasional Contributor III
You can get/set your default workspace using:
import arcpy

# Get WS
current_Workspace = arcpy.env.workspace

# Set the workspace environment to local file geodatabase
arcpy.env.workspace = "C:/data/base.gdb"

#set to SDE file
arcpy.env.workspace = r"c:\data\base.sde"





you can check ArcGIS Help for more info:
http://resources.arcgis.com/en/help/main/10.2/index.html#/Current_Workspace/001w00000002000000/
0 Kudos
HugoAhlenius
Occasional Contributor
Yes, but that doesn't work for my case... I am playing with a python addin on ArcMap open document, and if env.workspace is set before I won't have the default workspace...
0 Kudos
curtvprice
MVP Esteemed Contributor
Yes, but that doesn't work for my case... I am playing with a python addin on ArcMap open document, and if env.workspace is set before I won't have the default workspace...


Are you talking about ArcMap's default geodatabase? That's a different thing than the geoprocessing workspace, and only comes into play in the ArcMap UI.

The default env.workspace for new map documents is the one active the last time ArcCatalog closed. You could probably read it using Python from the HKCU part of the registry. It can be null, in which case often tools use TEMP, or sometimes Default.gdb in the users's My Documents\ArcGIS folder.

Maybe if you explain your use case we can help -- what do you intend to do with this location?
0 Kudos
HugoAhlenius
Occasional Contributor
Here is what I would like to do: to create a simple python add-in that sets the env.workspace when opening a document. So that operations in the python pane to the same folder that the mxd reside in. But I don't want to set it if the default geodatabase has been set in the ArcMap document properties, then that is preferable.

So I need a way to check if the default geodatabase property is set or not! (i.e. if it is not the default value)
0 Kudos