Find out which app you're in: ArcCatalog/ArcMap

763
4
03-22-2012 12:17 PM
BruceKessler
New Contributor
This has got to be easy, but I'm missing it. How, in Python, can I check to see which application I'm in: ArcCatalog or ArcMap?

Thanks.
Tags (2)
0 Kudos
4 Replies
MathewCoyle
Frequent Contributor
Rather inelegant, but should accomplish what you want.
try:
    mxd = arcpy.mapping.MapDocument("current")
except:
    print "in arccatalog!"
0 Kudos
BruceKessler
New Contributor
Rather inelegant, but should accomplish what you want.
try:
    mxd = arcpy.mapping.MapDocument("current")
except:
    print "in arccatalog!"


Well, you're right, it's not the most elegant. Gets the job done -- thanks. Seems clunky to create an error to find out if you're in ArcCatalog, tho. Anybody know of something that's a test that is more like this?

if <in ArcMap>:
  <do some ArcMap thing>
elif <in ArcCatalog>:
  <do some ArcCatalog thing>
else:
  <your lost>

I'm wondering if there is some sort of sys function for this? I've googled this and found a number of solutions in python, but gads! And the modules that were listed are not installed on my machine. So I may be stuck with the solution mzcoyle sent
0 Kudos
RDHarles
Occasional Contributor
You can do it like this:

# Prints "where" script is running from.  (e.g. ArcMap, ArcCatalog, python, PythonWin, etc.)

import os, sys, arcpy

RunFrom = os.path.splitext(os.path.basename(sys.executable))[0]
print RunFrom
print arcpy.AddMessage(RunFrom)
0 Kudos
BruceKessler
New Contributor
You can do it like this:

# Prints "where" script is running from.  (e.g. ArcMap, ArcCatalog, python, PythonWin, etc.)

import os, sys, arcpy

RunFrom = os.path.splitext(os.path.basename(sys.executable))[0]
print RunFrom
print arcpy.AddMessage(RunFrom)


Outstanding! Thank you.
0 Kudos