AnsweredAssumed Answered

How can I test to determine if script is being run in ArcMap vs ArcCatalog?

Question asked by rastrauch Champion on Nov 30, 2015
Latest reply on Mar 31, 2016 by rharmon_OWRD_1

I have a script that can currently run in ArcMap or ArcCatalog, by design.


However, if it is run in in ArcMap, I would like the two final output FC to be added to the map (Saving is optional at this point, so haven't added )


I was able to get this to work in ArcMap with the following addition code..

# my variables finalOutdd and finalOutProj are set to full paths of the output
mxd = arcpy.mapping.MapDocument("CURRENT")
df  = arcpy.mapping.ListDataFrames(mxd)[0]
ddLayer = arcpy.mapping.Layer(finalOutdd)
projLayer = arcpy.mapping.Layer(finalOutProj)
arcpy.mapping.AddLayer(df, ddLayer, "TOP")
arcpy.mapping.AddLayer(df, projLayer, "TOP")



My question is, how can I do a test to see if I'm running this in ArcMap?    ArcCatalog and an external python window will basically work the same, i.e. not add the layers to anything.  But if the code above is used, it will error out that there is no MapDocument


I've looked at the options for arcpy.GetInstallInfo()[""]  and arcpy.ProductInfo() but so far, it sees both as "Desktop" (ProduceName from GetInstallInfo)  and "ArcInfo" (from ProductInfo).


Anyone know a simple way to test for this?



(btw - Desktop 10.3.1)