def onClick(self): object = pythonaddins.GPToolDialog("C:\Users\University\Dropbox\University\Advanced_programming\practicals\prac1_modelBuilder\models.tbx", "explosionscript2") Input_Features = arcpy.GetParameterAsText(0) Distance__value_or_field_ = arcpy.GetParameterAsText(1) Layer = arcpy.GetParameterAsText(2) Intersect__3_ = arcpy.GetParameterAsText(3) if Intersect__3_ == '#' or not Intersect__3_: Intersect__3_ = "C:\\Users\\University\\Dropbox\\University\\Advanced_programming\\practicals\\advPrg.gdb\\Intersect" # provide a default value if unspecified Output_Feature_Class = arcpy.GetParameterAsText(4) try: try: arcpy.ImportToolbox("C:/Users/University/Dropbox/University/Advanced_programming/practicals/prac1_modelBuilder/models.tbx", "models") except arcpy.ExecuteError as e: print("Import toolbox error", e) try: arcpy.Explosion_models(Input_Features, Distance__value_or_field_, Layer, Intersect__3_, Output_Feature_Class) # don't forget to remove the " " when changing to parameter based inputs except arcpy.ExecuteError as e: print("Model run error", e) except Exception as e: print(e)
try: arcpy.ImportToolbox("m:/Documents/Programming2/Prac1/Models.tbx", "models") except arcpy.ExecuteError as e: print("Import toolbox error", e) tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] print(tbinfo) # or arcpy.AddError(tbinfo) if arcpy.Exists("TEST.shp"): arcpy.Delete_management("TEST.shp") if arcpy.Exists("buffer.shp"): arcpy.Delete_management("buffer.shp") try: arcpy.Explosion_models(Explosive, Area, Blast_Zone_Name, Blast_Range, "buffer.shp") except arcpy.ExecuteError as e: print("Model run error", e) tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] print(tbinfo) # or arcpy.AddError(tbinfo) except Exception as e: print(e) tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] print(tbinfo) # or arcpy.AddError(tbinfo)
#Catch errors that exist without crashing the program. try: try: #Import the arc toolbox that the script is located in. arcpy.ImportToolbox("C:/Users/kate/Documents/python_uni/Python_Advanced/albertsurface/Models.tbx","models") #Let the user know the progress of the script. arcpy.AddMessage("Toolbox is importing") #Inform user of any errors that occur. except arcpy.ExecuteError as e: print(arcpy.GetMessages()) print("Import toolbox error", e) tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] arcpy.AddError(tbinfo) try: #Run the model with the parameters specified above. arcpy.Explosion_models(explosion,distance,name1,buildings,name2) #Inform the user of the model progress. arcpy.AddMessage("Model is running") #Catch and print any error messages but continue running. except arcpy.ExecuteError as e: tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] arcpy.AddError(tbinfo) print("Model run error", e) #Catch and print any other errors that occur but continue running. except Exception as e: print(e)
if arcpy.Exists(name1): arcpy.Delete_management(name1) ##If the name of the intersection polygon already exists, write over it. if arcpy.Exists(name2): arcpy.Delete_management(name2) #Open the toolbox used to run this function in such a manner that it does not fail if ther is an error. try: try: #Import the toolbox which contains the required model. arcpy.ImportToolbox("M:/Python_Advanced/albertsurface/Models.tbx", "models") #If there is an error, catch it instead of failing to run. except arcpy.ExecuteError as e: #Print the error message. print("Import toolbox error", e) try: #Open up the model that we would like to run. #Include the parameters and file names that are to be used/created. arcpy.Explosion_models("explosion0/point", "20 Meters", name1, "build0/polygon", name2) #Catch errors except arcpy.ExecuteError as e: #Print error message. print("Model run error", e) #Catch all other errors. except Exception as e: #Print the error message. print(e)
Python Version: 3.6 Course: GEOG5790M Programming-for-Spatial-Analysts-Advanced-Skills Author: Annabel Whipp File name: explosionscript.py ''' # imports import arcpy p0 = arcpy.GetParameterAsText(0) p1 = arcpy.GetParameterAsText(1) p2 = arcpy.GetParameterAsText(2) p3 = arcpy.GetParameterAsText(3) try: try: arcpy.ImportToolbox("m:/advancedprogramming/models.tbx", "models") except arcpy.ExecuteError as e: print("Import toolbox error", e) try: arcpy.Explosion_models(p0, p1, p2, p3) # arcpy.Explosion_models("M:/advancedprogramming/data/input/explosion.shp", # "100 Meters", # "M:/advancedprogramming/data/input/buildings.shp", # "M:/advancedprogramming/data/generated/int4.shp") # Your parameters, here. except arcpy.ExecuteError as e: print("Model run error", e) except Exception as e: print(e)
import arcpy #Set the workspace environment. arcpy.env.workspace = "M:/Python_Advanced/albertsurface" #Import the model toolbox. arcpy.ImportToolbox("M:/Python_Advanced/albertsurface/Models.tbx", "models") #Run the explosion model. arcpy.Explosion_models("explosion0/point", "20 Meters", "mickey.shp", "build0/polygon", "mouse.shp")
import arcpy arcpy.env.workspace = "C:/Users/University/Dropbox/University/Advanced_programming/practicals/prac1_modelBuilder/data" try: try: arcpy.ImportToolbox( "C:/Users/University/Dropbox/University/Advanced_programming/practicals/prac1_modelBuilder/models.tbx", "models") except arcpy.ExecuteError as e: print("Import toolbox error", e) try: arcpy.Explosion_models("explosion0/point", "25 Meters", "build0/polygon", "intersect.shp", "buffer.shp") # Your parameters, here. except arcpy.ExecuteError as e: print("Model run error", e) except Exception as e: print(e) #syntax: Explosion_models (Input_Features, Distance__value_or_field_, Layer, Intersect__3_, Output_Feature_Class)
import arcpy arcpy.env.workspace = "m:/Documents/Programming2/Prac1" try: try: arcpy.ImportToolbox("m:/Documents/Programming2/Prac1/Models.tbx", "models") except arcpy.ExecuteError as e: print("Import toolbox error", e) if arcpy.Exists("TEST.shp"): arcpy.Delete_management("TEST.shp") if arcpy.Exists("buffer.shp"): arcpy.Delete_management("buffer.shp") try: arcpy.Explosion_models("explosion0/point", "build0/polygon", "TEST.shp", "50 Meters", "buffer.shp") except arcpy.ExecuteError as e: print("Model run error", e) except Exception as e: print(e)