Is there a way with Python to do Select by Location with the Use selected feature option?
I'm trying to automate a process and am running into barriers.
I need to be able to select the 2 lines within the same feature class that intersect a point, but I need to do this 1 at a time so I can capture the field attributes for each line. The 2 lines will then be dissolved and eventually appended back into the original line feature. Basically, I'm trying to merge the lines and keep the attributes. The exact tool I need is the Merge tool in the Editor drop down, but apparently that isn't accessible with Python for some dumb reason.
There's also an Unsplit tool but of course it's only for Advanced, which I don't have.
What I'm trying to do:
From the Points feature class, get a list of the OBJECTID values and then use Select by attributes to select each point one at a time. But then I need to be able to do Select by Location on the Line using only the Selected point feature.
Then once the 2 lines are selected, I'll copy their field attributes and dissolve them and then append them back into the original line and add the values back.
I think I got it to work finally. The only thing I haven't figured out yet is how to delete the original lines that are being replaced when I append the newly dissolved lines. Because I think the only way I can use the Select by Location is when a layer file and not a feature class, so I'm not sure how to go about it yet.
Well, I finally figured it out. As far as I can tell it works just the way I want it to.
Thanks for the help Paul.
Here's the code:
import arcpy arcpy.env.overwriteOutput = True arcpy.env.workspace = "Path to geodatabase" Consumer = "Path to point feature class" Conductor = "Path to line feature class" ConsumerOID =  cursor = arcpy.SearchCursor(Consumer) for row in cursor: ConsumerOID.append(row.getValue("OBJECTID")) del cursor, row arcpy.MakeFeatureLayer_management(Consumer, "tConsumers") arcpy.MakeFeatureLayer_management(Conductor, "tConductor") for OID in ConsumerOID: arcpy.SelectLayerByAttribute_management("tConsumers", "NEW_SELECTION", "[OBJECTID] = " + str(OID)) arcpy.MakeFeatureLayer_management("tConsumers", "ttConsumers") arcpy.SelectLayerByLocation_management("tConductor", "INTERSECT", "ttConsumers") arcpy.MakeFeatureLayer_management("tConductor", "ttConductor") ConductorOID =  cursor = arcpy.SearchCursor("ttConductor") for row in cursor: ConductorOID.append(row.getValue("OBJECTID")) del cursor, row fields = arcpy.ListFields("ttConductor") cursor = arcpy.SearchCursor("ttConductor") FieldsAdd =  FieldValues =  ExcludeList = ["OBJECTID", "SHAPE", "SHAPE_Length", "SHAPE_Area"] for row in cursor: for field in fields: if not field.name in ExcludeList: FieldsAdd.append(field.name) FieldValues.append(row.getValue(field.name)) del cursor, row arcpy.Dissolve_management("ttConductor", "in_memory\\dissolve", "", "", "MULTI_PART", "") arcpy.MakeFeatureLayer_management("in_memory\\dissolve", "newConductor") for field in FieldsAdd: arcpy.AddField_management("newConductor", str(field), "TEXT") count = 0 cursor = arcpy.UpdateCursor("newConductor") for row in cursor: for field in FieldsAdd: row.setValue(field, FieldValues[count]) cursor.updateRow(row) count += 1 del cursor, row for OID in ConductorOID: cursor = arcpy.UpdateCursor(Conductor, "[OBJECTID] = " + str(OID)) for row in cursor: cursor.deleteRow(row) del cursor, row arcpy.Append_management("newConductor", Conductor, "TEST", "", "") arcpy.GetMessages() print ("Finished")