AnsweredAssumed Answered

Can I return feature layersfrom a function?

Question asked by recurvata on Feb 28, 2018
Latest reply on Mar 1, 2018 by recurvata

I'm creating 3 feature layers in one function. I'd like to return them from the function in a list, but as I expected, their type in the list is just string. I know I can save them out as a lyr file, but trying to avoid that if possible. Maybe they go out of scope when the function ends? Thanks.

def makeFeatureLayers():
    Make feature layers from Annotation, Polygon and Points features

    print("\nCreating feature layers")
    anno = 'Annotation'
    pt = 'Point'
    poly = 'Polygon'

    anno_path = os.path.join(ds_path, anno)
    pt_path = os.path.join(ds_path, pt)
    poly_path = os.path.join(ds_path, poly)

    fc_dict = {}
    fc_dict[anno] = anno_path
    fc_dict[pt] = pt_path
    fc_dict[poly] = poly_path

    fc_list = []

    for k, v in fc_dict.iteritems():
        lyr_name = k + '_lyr'
            arcpy.MakeFeatureLayer_management(v, lyr_name)
        except Exception as e:
            print("\nError: {}".format(e))

    for fc in fc_list:
        print("\nType of fc: {}".format(type(fc)))