Python arcpy.AddError() Examples

The following are 30 code examples of arcpy.AddError(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module arcpy , or try the search function .
Example #1
Source File: gSSURGO_ValuTable.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def PrintMsg(msg, severity=0):
    # Adds tool message to the geoprocessor
    #
    #Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
            if severity == 0:
                arcpy.AddMessage(string)

            elif severity == 1:
                arcpy.AddWarning(string)

            elif severity == 2:
                arcpy.AddMessage("    ")
                arcpy.AddError(string)

    except:
        pass

## =================================================================================== 
Example #2
Source File: mapmatcher.py    From mapmatching with MIT License 6 votes vote down vote up
def exportPath(opt, trackname):
    """
    This exports the list of segments into a shapefile, a subset of the loaded segment file, including all attributes
    """
    start_time = time.time()
    opt=getUniqueList(opt)
    qr =  '"OBJECTID" IN ' +str(tuple(opt))
    outname = (os.path.splitext(os.path.basename(trackname))[0][:9])+'_pth'
    arcpy.SelectLayerByAttribute_management('segments_lyr',"NEW_SELECTION", qr)
    try:
        if arcpy.Exists(outname):
            arcpy.Delete_management(outname)
        arcpy.FeatureClassToFeatureClass_conversion('segments_lyr', arcpy.env.workspace, outname)
        print("--- export: %s seconds ---" % (time.time() - start_time))
    except Exception:
        e = sys.exc_info()[1]
        print(e.args[0])

        # If using this code within a script tool, AddError can be used to return messages
        #   back to a script tool.  If not, AddError will have no effect.
        arcpy.AddError(e.args[0])
        arcpy.AddError(arcpy.env.workspace)
        arcpy.AddError(outname)
        #raise arcpy.ExecuteError
    except arcpy.ExecuteError:
        arcpy.AddError(arcpy.GetMessages(2))

    # Return any other type of error
    except:
        # By default any other errors will be caught here
        #
        e = sys.exc_info()[1]
        print(e.args[0])
        arcpy.AddError(e.args[0])
        arcpy.AddError(arcpy.env.workspace)
        arcpy.AddError(outname) 
Example #3
Source File: compareNASIStables_pedonGDBTable.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def AddMsgAndPrint(msg, severity=0):
    # prints message to screen if run as a python script
    # Adds tool message to the geoprocessor
    #
    #Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        print msg

        #for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
        if severity == 0:
            arcpy.AddMessage(msg)

        elif severity == 1:
            arcpy.AddWarning(msg)

        elif severity == 2:
            arcpy.AddError(msg)

    except:
        pass

## =================================================================================== 
Example #4
Source File: Tabulate_Components_By_Mukey.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def AddMsgAndPrint(msg, severity=0):
    # prints message to screen if run as a python script
    # Adds tool message to the geoprocessor
    #
    #Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        print msg

        #for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
        if severity == 0:
            arcpy.AddMessage(msg)

        elif severity == 1:
            arcpy.AddWarning(msg)

        elif severity == 2:
            arcpy.AddError("\n" + msg)

    except:
        pass

## =================================================================================== 
Example #5
Source File: Convert_NCSSPedonDatabase_to_FGDB.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def AddMsgAndPrint(msg, severity=0):
    # prints message to screen if run as a python script
    # Adds tool message to the geoprocessor
    #
    #Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        print msg

        #for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
        if severity == 0:
            arcpy.AddMessage(msg)

        elif severity == 1:
            arcpy.AddWarning(msg)

        elif severity == 2:
            arcpy.AddError("\n" + msg)

    except:
        pass

## =================================================================================== 
Example #6
Source File: BBB_SharedFunctions.py    From public-transit-tools with Apache License 2.0 6 votes vote down vote up
def import_AGOLservice(service_name, username="", password="", ags_connection_file="", token="", referer=""):
    '''Imports the AGOL service toolbox based on the specified credentials and returns the toolbox object'''

    #Construct the connection string to import the service toolbox
    if username and password:
        tbx = "http://logistics.arcgis.com/arcgis/services;{0};{1};{2}".format(service_name, username, password)
    elif ags_connection_file:
        tbx = "{0};{1}".format(ags_connection_file, service_name)
    elif token and referer:
        tbx = "http://logistics.arcgis.com/arcgis/services;{0};token={1};{2}".format(service_name, token, referer)
    else:
        arcpy.AddError("No valid option specified to connect to the {0} service".format(service_name))
        raise CustomError

    #Import the service toolbox
    tbx_alias = "agol"
    arcpy.ImportToolbox(tbx, tbx_alias)

    return getattr(arcpy, tbx_alias) 
Example #7
Source File: BBB_SharedFunctions.py    From public-transit-tools with Apache License 2.0 6 votes vote down vote up
def CheckArcVersion(min_version_pro=None, min_version_10x=None):
    DetermineArcVersion()
    # Lists must stay in product release order
    # They do not need to have new product numbers added unless a tool requires a higher version
    versions_pro = ["1.0", "1.1", "1.1.1", "1.2"]
    versions_10x = ["10.1", "10.2", "10.2.1", "10.2.2", "10.3", "10.3.1", "10.4"]

    def check_version(min_version, all_versions):
        if min_version not in all_versions:
            arcpy.AddError("Invalid minimum software version number: %s" % str(min_version))
            raise CustomError
        version_idx = all_versions.index(min_version)
        if ArcVersion in all_versions[:version_idx]:
            # Fail out if the current software version is in the list somewhere earlier than the minimum version
            arcpy.AddError("The BetterBusBuffers toolbox does not work in versions of %s prior to %s.  \
You have version %s.  Please check the user's guide for more information on software version compatibility." % (ProductName, min_version, ArcVersion))
            raise CustomError

    if ProductName == "ArcGISPro" and min_version_pro:
        check_version(min_version_pro, versions_pro)
    else:
        if min_version_10x:
            check_version(min_version_10x, versions_10x) 
Example #8
Source File: SDA_JSON_Testing.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def AddMsgAndPrint(msg, severity=0):
    # prints message to screen if run as a python script
    # Adds tool message to the geoprocessor
    #
    #Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:

        #print(msg)
        #for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
        if severity == 0:
            arcpy.AddMessage(msg)

        elif severity == 1:
            arcpy.AddWarning(msg)

        elif severity == 2:
            arcpy.AddError("\n" + msg)

    except:
        pass

## =================================================================================== 
Example #9
Source File: AddNatMusym.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def AddMsgAndPrint(msg, severity=0):
    """prints messages to screen if the script is executed as
       a standalone script.  Otherwise, Adds tool message to the
       window geoprocessor.  Messages are color coded by severity."""

    #Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        print msg

        #for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
        if severity == 0:
            arcpy.AddMessage(msg)

        elif severity == 1:
            arcpy.AddWarning(msg)

        elif severity == 2:
            arcpy.AddError("\n" + msg)

    except:
        pass

## ================================================================================================================ 
Example #10
Source File: BBB_SharedFunctions.py    From public-transit-tools with Apache License 2.0 6 votes vote down vote up
def CountTripsOnLines(day, start_sec, end_sec, DepOrArr, Specific=False):
    '''Given a time window, return a dictionary of {line_key: [[trip_id, start_time, end_time]]}'''

    triplist, triplist_yest, triplist_tom = GetTripLists(day, start_sec, end_sec, DepOrArr, Specific)

    try:
        frequencies_dict = MakeFrequenciesDict()

        # Get the stop_times that occur during this time window
        linetimedict = GetLineTimesInTimeWindow(start_sec, end_sec, DepOrArr, triplist, "today", frequencies_dict)
        linetimedict_yest = GetLineTimesInTimeWindow(start_sec, end_sec, DepOrArr, triplist_yest, "yesterday", frequencies_dict)
        linetimedict_tom = GetLineTimesInTimeWindow(start_sec, end_sec, DepOrArr, triplist_tom, "tomorrow", frequencies_dict)

        # Combine the three dictionaries into one master
        for line in linetimedict_yest:
            linetimedict[line] = linetimedict.setdefault(line, []) + linetimedict_yest[line]
        for line in linetimedict_tom:
            linetimedict[line] = linetimedict.setdefault(line, []) + linetimedict_tom[line]

    except:
        arcpy.AddError("Error creating dictionary of lines and trips in time window.")
        raise CustomError

    return linetimedict 
Example #11
Source File: SSURGO_MergeDatabasesByMap.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def PrintMsg(msg, severity=0):
    # Adds tool message to the geoprocessor
    #
    #Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
            if severity == 0:
                arcpy.AddMessage(string)

            elif severity == 1:
                arcpy.AddWarning(string)

            elif severity == 2:
                arcpy.AddError(" \n" + string)

    except:
        pass

## =================================================================================== 
Example #12
Source File: SSURGO_ExportMuRaster.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def PrintMsg(msg, severity=0):
    # prints message to screen if run as a python script
    # Adds tool message to the geoprocessor
    #
    #Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
            if severity == 0:
                arcpy.AddMessage(string)

            elif severity == 1:
                arcpy.AddWarning(string)

            elif severity == 2:
                arcpy.AddMessage("    ")
                arcpy.AddError(string)

    except:
        pass

## =================================================================================== 
Example #13
Source File: SSURGO_CountRecords.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def PrintMsg(msg, severity=0):
    # Adds tool message to the geoprocessor
    #
    #Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
            if severity == 0:
                arcpy.AddMessage(string)

            elif severity == 1:
                arcpy.AddWarning(string)

            elif severity == 2:
                arcpy.AddMessage("    ")
                arcpy.AddError(string)

    except:
        pass

## =================================================================================== 
Example #14
Source File: gSSURGO_CheckValuTables.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def PrintMsg(msg, severity=0):
    # Adds tool message to the geoprocessor
    #
    #Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
            if severity == 0:
                arcpy.AddMessage(string)

            elif severity == 1:
                arcpy.AddWarning(string)

            elif severity == 2:
                arcpy.AddMessage("    ")
                arcpy.AddError(string)

    except:
        pass

## =================================================================================== 
Example #15
Source File: SSURGO_GetSizes.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def PrintMsg(msg, severity=0):
    # Adds tool message to the geoprocessor
    #
    #Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
            if severity == 0:
                arcpy.AddMessage(string)

            elif severity == 1:
                arcpy.AddWarning(string)

            elif severity == 2:
                arcpy.AddMessage("    ")
                arcpy.AddError(string)

    except:
        pass

## =================================================================================== 
Example #16
Source File: SSURGO_BatchImport.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def PrintMsg(msg, severity=0):
    # Adds tool message to the geoprocessor
    #
    #Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
            if severity == 0:
                arcpy.AddMessage(string)

            elif severity == 1:
                arcpy.AddWarning(string)

            elif severity == 2:
                arcpy.AddError(" \n" + string)

    except:
        pass

## =================================================================================== 
Example #17
Source File: gSSURGO_DistributeValuTable.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def PrintMsg(msg, severity=0):
    # Adds tool message to the geoprocessor
    #
    #Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
            if severity == 0:
                arcpy.AddMessage(string)

            elif severity == 1:
                arcpy.AddWarning(string)

            elif severity == 2:
                arcpy.AddMessage("    ")
                arcpy.AddError(string)

    except:
        pass

## =================================================================================== 
Example #18
Source File: SSURGO_gSSURGO_byState.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def PrintMsg(msg, severity=0):
    # prints message to screen if run as a python script
    # Adds tool message to the geoprocessor
    #
    # Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
            if severity == 0:
                arcpy.AddMessage(string)

            elif severity == 1:
                arcpy.AddWarning(string)

            elif severity == 2:
                arcpy.AddMessage("    ")
                arcpy.AddError(string)

    except:
        pass

## =================================================================================== 
Example #19
Source File: SSURGO_ProjectSoilShapefilesbyAreasymbol.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def PrintMsg(msg, severity=0):
    # Adds tool message to the geoprocessor
    #
    #Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
            if severity == 0:
                arcpy.AddMessage(string)

            elif severity == 1:
                arcpy.AddWarning(string)

            elif severity == 2:
                arcpy.AddError(" \n" + string)

    except:
        pass

## =================================================================================== 
Example #20
Source File: FeaturesToGPX.py    From sample-gp-tools with Apache License 2.0 6 votes vote down vote up
def featuresToGPX(inputFC, outGPX, zerodate, pretty):
    ''' This is called by the __main__ if run from a tool or at the command line
    '''

    descInput = arcpy.Describe(inputFC)
    if descInput.spatialReference.factoryCode != 4326:
        arcpy.AddWarning("Input data is not projected in WGS84,"
                         " features were reprojected on the fly to create the GPX.")

    generatePointsFromFeatures(inputFC , descInput, zerodate)

    # Write the output GPX file
    try:
        if pretty:
            gpxFile = open(outGPX, "w")
            gpxFile.write(prettify(gpx))
        else:
            gpxFile = open(outGPX, "wb")
            ET.ElementTree(gpx).write(gpxFile, encoding="UTF-8", xml_declaration=True)
    except TypeError as e:
        arcpy.AddError("Error serializing GPX into the file.")
    finally:
        gpxFile.close() 
Example #21
Source File: gSSURGO_ValidateData.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def PrintMsg(msg, severity=0):
    # Adds tool message to the geoprocessor
    #
    #Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
            if severity == 0:
                arcpy.AddMessage(string)

            elif severity == 1:
                arcpy.AddWarning(string)

            elif severity == 2:
                arcpy.AddMessage("    ")
                arcpy.AddError(string)

    except:
        pass

## =================================================================================== 
Example #22
Source File: SSURGO_CountRecords2.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def PrintMsg(msg, severity=0):
    # Adds tool message to the geoprocessor
    #
    #Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
            if severity == 0:
                arcpy.AddMessage(string)

            elif severity == 1:
                arcpy.AddWarning(string)

            elif severity == 2:
                arcpy.AddMessage("    ")
                arcpy.AddError(string)

    except:
        pass

## =================================================================================== 
Example #23
Source File: SSURGO_BatchDownload.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def PrintMsg(msg, severity=0):
    # Adds tool message to the geoprocessor
    #
    #Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
            if severity == 0:
                arcpy.AddMessage(string)

            elif severity == 1:
                arcpy.AddWarning(string)

            elif severity == 2:
                arcpy.AddError(" \n" + string)

    except:
        pass

## =================================================================================== 
Example #24
Source File: SSURGO_CheckgSSURGO.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def PrintMsg(msg, severity=0):
    # Adds tool message to the geoprocessor
    #
    #Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
            if severity == 0:
                arcpy.AddMessage(string)

            elif severity == 1:
                arcpy.AddWarning(string)

            elif severity == 2:
                arcpy.AddMessage("    ")
                arcpy.AddError(string)

    except:
        pass

## =================================================================================== 
Example #25
Source File: DataServicePillager.py    From DataPillager with MIT License 6 votes vote down vote up
def output_msg(msg, severity=0):
    """ Adds a Message (in case this is run as a tool)
        and also prints the message to the screen (standard output)
        :param msg: text to output
        :param severity: 0 = none, 1 = warning, 2 = error
    """
    print msg
    # Split the message on \n first, so that if it's multiple lines,
    #  a GPMessage will be added for each line
    try:
        for string in msg.split('\n'):
            # Add appropriate geoprocessing message
            if severity == 0:
                arcpy.AddMessage(string)
            elif severity == 1:
                arcpy.AddWarning(string)
            elif severity == 2:
                arcpy.AddError(string)
    except:
        pass 
Example #26
Source File: SSURGO_gSSURGO_byTile.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def PrintMsg(msg, severity=0):
    # prints message to screen if run as a python script
    # Adds tool message to the geoprocessor
    #
    # Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
            if severity == 0:
                arcpy.AddMessage(string)

            elif severity == 1:
                arcpy.AddWarning(string)

            elif severity == 2:
                arcpy.AddMessage("    ")
                arcpy.AddError(string)

    except:
        pass

## =================================================================================== 
Example #27
Source File: github_release.py    From r-bridge-install with Apache License 2.0 6 votes vote down vote up
def release_info():
    """Get latest release version and download URL from
       the GitHub API.

    Returns:
        (download_url, tag_name) tuple.
    """
    download_url = None
    tag = None
    json_r = parse_json_url(latest_url)
    if json_r is not None and 'assets' in json_r:
        assets = json_r['assets'][0]
        if 'browser_download_url' in assets and \
                'tag_name' in json_r:
            download_url = assets['browser_download_url']
            tag = json_r['tag_name']
        if not download_url or not tag:
            arcpy.AddError("Invalid GitHub API response for URL '{}'".format(
                latest_url))

    return (download_url, tag) 
Example #28
Source File: GetDominantComponent.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def PrintMsg(msg, severity=0):
    # prints message to screen if run as a python script
    # Adds tool message to the geoprocessor
    #
    #Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
            if severity == 0:
                arcpy.AddMessage(string)

            elif severity == 1:
                arcpy.AddWarning(string)

            elif severity == 2:
                arcpy.AddMessage("    ")
                arcpy.AddError(string)
                #arcpy.AddMessage("    ")

    except:
        pass

## =================================================================================== 
Example #29
Source File: SSURGO_CheckgSSURGO2.py    From geo-pit with GNU General Public License v2.0 6 votes vote down vote up
def PrintMsg(msg, severity=0):
    # Adds tool message to the geoprocessor
    #
    #Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
    try:
        for string in msg.split('\n'):
            #Add a geoprocessing message (in case this is run as a tool)
            if severity == 0:
                arcpy.AddMessage(string)

            elif severity == 1:
                arcpy.AddWarning(string)

            elif severity == 2:
                arcpy.AddMessage("    ")
                arcpy.AddError(string)

    except:
        pass

## =================================================================================== 
Example #30
Source File: reset_required_fields_python_api.py    From collector-tools with Apache License 2.0 6 votes vote down vote up
def update_service_definition(args_parser):
    try:
        gis = GIS(args_parser.url,args_parser.username, args_parser.password)
        featureLayerItem = gis.content.get(args_parser.itemId)

        featureLayerCollection = FeatureLayerCollection.fromitem(featureLayerItem)
        layers = featureLayerCollection.manager.layers
        tables = featureLayerCollection.manager.tables

        arcpy.AddMessage("Updating Service Definition..")        

        for layer in layers:
            layer_index = layers.index(layer)
            update_template(featureLayerCollection,layer,layer_index,False)

        for table in tables:
            table_index = tables.index(table)
            update_template(featureLayerCollection,table,table_index,True)

                
        arcpy.AddMessage("Updated Service Definition..")

    except Exception as e:
        arcpy.AddError(e)