Python arcpy.GetParameterAsText() Examples

The following are 6 code examples of arcpy.GetParameterAsText(). 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: add_update_gnss_fields_python_api.py    From collector-tools with Apache License 2.0 6 votes vote down vote up
def parseArguments():
    parser = argparse.ArgumentParser(
        usage='Add/Update GNSS metadate fields')

    arcpy.AddMessage("Parsing Arguments..")

    parser.add_argument('url', help='Organization url')
    parser.add_argument('username', help='Organization username')
    parser.add_argument('password', help='Organization password')
    parser.add_argument('itemId', type=str, help='Feature service Item Id')
    parser.add_argument('layerIndex', type=int, help='Feature Layer index. If not specified use 0 as index')
    parser.add_argument('-r', dest='remove', default=False, type=bool,
                        help='Set True if GNSS metadata fields need to be removed')

    args_parser = parser.parse_args()
    if '*' in args_parser.password:
        args_parser.password = password = arcpy.GetParameterAsText(2)
    arcpy.AddMessage("Done parsing arguments..")
    return args_parser


# Search for a item id and add GNSS Metadata fields 
Example #2
Source File: configure_gnss_popup_python_api.py    From collector-tools with Apache License 2.0 6 votes vote down vote up
def parseArguments():
    parser = argparse.ArgumentParser(
        usage='Configure GNSS metadate fields visibility and popup')

    arcpy.AddMessage("Parsing Arguments..")

    parser.add_argument('url', help='Organization url')
    parser.add_argument('username', help='Organization username')
    parser.add_argument('password', help='Organization password')
    parser.add_argument('webmap_Name', type=str, help='Webmap Name')
    parser.add_argument('layerIndex', type=int, help='Feature Layer index. If not specified use 0 as index')

    args_parser = parser.parse_args()
    if '*' in args_parser.password:
        args_parser.password = password = arcpy.GetParameterAsText(2)
    arcpy.AddMessage("Done parsing arguments..")
    return args_parser


# Search for a Webmap and update GNSS Metadata fields popup info 
Example #3
Source File: reset_required_fields_python_api.py    From collector-tools with Apache License 2.0 6 votes vote down vote up
def parseArguments():
    parser = argparse.ArgumentParser(
        usage='Reset required fields to None in the feature templates')

    arcpy.AddMessage("Parsing Arguments..")

    parser.add_argument('url', help='Organization url')
    parser.add_argument('username', help='Organization username')
    parser.add_argument('password', help='Organization password')
    
    parser.add_argument('itemId', type=str, help='Feature service Item Id')

    args_parser = parser.parse_args()
    if '*' in args_parser.password:
        args_parser.password = password = arcpy.GetParameterAsText(2)
    
    arcpy.AddMessage("Done parsing arguments..")
    return args_parser 
Example #4
Source File: GetLayoutTemplatesInfo.py    From sample-gp-tools with Apache License 2.0 5 votes vote down vote up
def main():
    # Get the value of the input parameter
    #
    tmpltFolder = arcpy.GetParameterAsText(0)

    # When empty, it falls back to the default template location like ExportWebMap tool does
    #
    if (len(tmpltFolder) == 0):
        tmpltFolder = _defTmpltFolder

    # Getting a list of all file paths with .mxd extensions
    #    createing MapDocument objects and putting them in an array
    #
    mxds    = []
    for f in glob.glob(os.path.join(tmpltFolder, "*.mxd")):
        try:    #throw exception when MapDocument is corrupted
            mxds.append(arcpy.mapping.MapDocument(f))
        except:
            arcpy.AddWarning("Unable to open map document named {0}".format(os.path.basename(f)))
            

    # Encoding the array of MapDocument to JSON using a custom JSONEncoder class
    #
    outJSON = json.dumps(mxds, cls=MxdEncoder, indent=2)
    
    # Set output parameter
    #
    arcpy.SetParameterAsText(1, outJSON)
    
    # Clean up
    #
    del mxds 
Example #5
Source File: arcapi.py    From arcapi with GNU Lesser General Public License v3.0 4 votes vote down vote up
def fixArgs(arg, arg_type=list):
    """Fixe arguments from a script tool.

    For example, when using a script tool with a multivalue parameter,
    it comes in as "val_a;val_b;val_c".  This function can automatically
    fix arguments based on the arg_type.
    Another example is the boolean type returned from a script tool -
    instead of True and False, it is returned as "true" and "false".

    Required:
    arg --  argument from script tool (arcpy.GetParameterAsText() or sys.argv[1]) (str)
    arg_type -- type to convert argument from script tool parameter. Default is list.

    Example:
    >>> # example of list returned from script tool multiparameter argument
    >>> arg = "val_a;val_b;val_c"
    >>> fixArgs(arg, list)
    ['val_a', 'val_b', 'val_c']
    """
    if arg_type == list:
        if isinstance(arg, str):
            # need to replace extra quotes for paths with spaces
            # or anything else that has a space in it
            return map(lambda a: a.replace("';'",";"), arg.split(';'))
        else:
            return list(arg)
    if arg_type == float:
        if arg != '#':
            return float(arg)
        else:
            return ''
    if arg_type == int:
        return int(arg)
    if arg_type == bool:
        if str(arg).lower() == 'true' or arg == 1:
            return True
        else:
            return False
    if arg_type == str:
        if arg in [None, '', '#']:
            return ''
    return arg 
Example #6
Source File: parseVST.py    From CTM with Apache License 2.0 4 votes vote down vote up
def main():
    xml_file = arcpy.GetParameterAsText(1)
    input_workspace = arcpy.GetParameterAsText(0)
    field =  arcpy.GetParameterAsText(2)
    checked = []

    fcs = get_fcs(input_workspace)

    xmldoc = minidom.parse(xml_file)
    value_list = xmldoc.getElementsByTagName('Expression')
    fc_list = xmldoc.getElementsByTagName('FeatureClass')
    where_list = xmldoc.getElementsByTagName('WhereClause')

##    print(len(value_list))
##    print(len(fc_list))
##    print(len(where_list))

    for index, fc_item in enumerate(fc_list):
        fc = fc_item.firstChild.data
        where_item = where_list[index]
        where = where_item.firstChild.data
        value_item = value_list[index]
        value_str = value_item.firstChild.data
        string_list = str(value_str).split("Generate = ")
        value = string_list[1][:1]
        value = int(value)

        if fc in fcs:
            update_fc = fcs[str(fc)]
            print update_fc
            if update_fc not in checked:
                check_field(update_fc, field)
                checked.append(update_fc)
            print("updating " + str(fc) + " where " + str(where) )
            up_cnt = 0
            with arcpy.da.UpdateCursor(update_fc, '*', where) as cursor:
                cfields = cursor.fields
                field_ind = 0
                for index, item in enumerate(cfields):
                    if item == field:
                        field_ind = index
                if field_ind >= 0:
                    for row in cursor:
                        row[field_ind] = value
                        cursor.updateRow(row)
                        up_cnt += 1

            arcpy.AddMessage(str(up_cnt) + " features updated in " + str(fc) + " where " + str(where))


    pass