AnsweredAssumed Answered

Stopping Python addin script

Question asked by BrokenLegMike on May 6, 2016
Latest reply on May 8, 2016 by MidnightYell2003

I am trying to find a way to trap an error in a python addin and stop the script. For example, I want to test if the dataframes spatial reference is a particular coordinate system. If it is not that specific CS, then I want to have a popup messagebox explaing that the user needs to change the CS and then re-run the tool and then have the addin stop running. I've attempted a try/except statement with sys.exit(), however sys.exit() seems to kill ArcMap all together, instead of just stopping the script itself. Is there a better way to accomplish what I want?

 

try:
    if df.spatialReference.name in ("NAD_1983_BC_Environment_Albers", "NAD 1983 BC Environment Albers"):
           print "No problem with the CS"
    else:
        raise Exception
except Exception:
    pythonaddins.MessageBox("Change dataframe spatial reference to NAD_1983_BC_Environment_Albers and re-run tool", "Report Generator")
    raise sys.exit()

Outcomes