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")
# mxd.save()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 <SPAN class="n">arcpy</SPAN><SPAN class="o">.</SPAN><SPAN class="n">ProductInfo</SPAN><SPAN class="p">() but so far, it sees both as "Desktop" (ProduceName from GetInstallInfo) and "ArcInfo" (from ProductInfo). </SPAN>
Anyone know a simple way to test for this?
Thanks.
(btw - Desktop 10.3.1)