import arcpy mxd = arcpy.mapping.MapDocument ("CURRENT") df = arcpy.mapping.ListDataFrames (mxd)[0] lyr = arcpy.mapping.ListLayers(mxd, "Lot_Lines", df)[0] for lyr in arcpy.mapping.ListLayers(mxd): tlyr = lyr dsc = arcpy.Describe(tlyr) sel_set = dsc.FIDSet if dsc.shapeType == "Line": if len(sel_set) > 0: #If ARCLENGTH value > 0 arcpy.AddMessage(str(ARCLENGTH)) #Return ARCLENGTH value else: arcpy.AddMessage(str(Shape_Length)) #Return Shape_Length value
Solved! Go to Solution.
James:
Can you create a feature class with a small subset of features (say 10) and then print out the fidset?
It appears from Richard's last post that the semi-colon delimited string will need to be converted to a comma separated list. You shouldbe able to find python methods to easily perform that process.
James:
Can you create a feature class with a small subset of features (say 10) and then print out the fidset?
It appears from Richard's last post that the semi-colon delimited string will need to be converted to a comma separated list. You shouldbe able to find python methods to easily perform that process.
Python is case sensitive. Try dsc.fidSet
mxd = arcpy.mapping.MapDocument("CURRENT") for lyr in arcpy.mapping.ListLayers(mxd): dsc = arcpy.Describe(lyr) sel_set = dsc.fidSet if dsc.shapeType == "Polyline": rows = arcpy.SearchCursor(lyr, "OBJECTID = " + sel_set) for row in rows: arcLength = row.ARCLENGTH shapeLength = row.shape.length if arcLength > 0: print arcLength else: print shapeLength del row, rows
The result is the same whether I use dsc.fidSet, dsc.FidSet, or dsc.FIDSet.
Attached is some data you can test with. Add the feature class to ArcMap, select a single line, then execute the following:mxd = arcpy.mapping.MapDocument("CURRENT") for lyr in arcpy.mapping.ListLayers(mxd): dsc = arcpy.Describe(lyr) sel_set = dsc.fidSet if dsc.shapeType == "Polyline": rows = arcpy.SearchCursor(lyr, "OBJECTID = " + sel_set) for row in rows: arcLength = row.ARCLENGTH shapeLength = row.shape.length if arcLength > 0: print arcLength else: print shapeLength del row, rows
Are you positive your layer has a feature selection already applied? If nothing is selected, no FID values should be returned.
Jake, the script works with the feature class you provided, using the Python window within ArcMap.