import arcpy, os #Set the workspace workspace = r"D:/Work" #create list of files from directories and subdirectories for root, dirs, files in arcpy.da.Walk(workspace, datatype="FeatureClass", type="Polygon"): for name in files: if name.startswith("APE") or name.startswith("SAB"): path = os.path.abspath(os.path.join(root, name)) for x in path: outFC = x + "_pt" # convert to points arcpy.FeatureToPoint_management(path, outFC, "INSIDE")
Solved! Go to Solution.
appendFC = r"C:\TEMP\PDX_SAB\PDX_SAB.gdb\PDX_SAB_Centerpoint" outFC = "in_memory\\centerPoints" tmpFC= "in_memory\\tmpFC" fieldList = ["ProjectNum", "OriginalPath", "ServiceArea"] ##Merge tool will honor the coordinate system of the first FC in the list to be merged, so I'd make my list something like: fcList = ["baseFC"] # where BaseFC is a FC in your workspace that is in the correct coordinate system, this will set the output to the SR you want layerList = [] then, after you do your walk, for all file in filenames: fcList.append("file") for all fcs in fcList: ## these two look like duplication, but this is how I add to a list with a value already. For file in filenames is a list I can't control this way layername = str(fcs) + "feature_layer" layerList.append(layername) # append the new in memory layer names to a list so we can utilize it after iteration. arcpy.MakeFeatureLayer_management(fcs,layername) # this will put them as in memory layers and are fast arcpy.AddField_management(layername, "ProjectNum", "TEXT", "", "", 20, "", "NULLABLE", "REQUIRED") arcpy.AddField_management(layername, "OriginalPath", "TEXT", "", "", 255, "", "NULLABLE", "REQUIRED") arcpy.AddField_management(layername, "ServiceArea", "TEXT", "", "", 75, "", "NULLABLE", "REQUIRED") arcpy.CalculateField_management(layername, "ProjectNum", "exp", "PYTHON_9.3") arcpy.CalculateField_management(layername, "OriginalPath", "exp2", "PYTHON_9.3") arcpy.CalculateField_management(layername, "ServiceArea", "exp3", "PYTHON_9.3") Now, after iterating through all FC, and making the list of feature layers, combine them all so we can do the rest in one swoop. arcpy.Merge_management(layerList, tmpFC) ### merges all the polygon in memory fc's with new calculated fields into an in memory fc fields = arcpy.ListFields(tmpFC) for field in fields: if field not in fieldList: arcpy.DeleteField_management (tmpFC, field) ## will drop all the "extra" fields if not in the fieldsList. arcpy.FeatureToPoint_management(tmpFC, appendFC, "INSIDE") ## this will make point FC in same SR as first input with your three fields appended.
exp2 = str(os.path.join(dirpath, fcs))
baseFC = r"c:\pathto\dataset ## set to FC that has the desired output SR ## then, after you do your da.walk, filenames.insert(0,baseFC) ## this would ensure the baseFC is the first in the list when passing it to the merge function