ok got to run good.
I was trying to revert the process. Instead of selecting the parcel i was trying to select the address point and populate the address point from the taxparcels.
I have it running if only one is selected, if i select more then one point ArcMap freaks out.
Here is the code.
import arcpy
import os
import pythonaddins
# Assign string literal layer names to variables to make them easier to change with just one line of code.
# Good practice for template code that you may not want to do a search and replace to adapt it for new layers.
parcels = "Taxparcels"
addressPoints = "TonyTwoWay.DBO.CCAP_Test"
arcpy.env.overwriteOutput = True
#Get the current map document and the first data frame.
mxd = arcpy.mapping.MapDocument('current')
df = arcpy.mapping.ListDataFrames(mxd)[0]
#Check to make sure user had at least one parcel selected.
pointCount = int(arcpy.GetCount_management(addressPoints).getOutput(0))
if 0 < pointCount < 2:
lyr = arcpy.mapping.ListLayers(mxd, addressPoints, df)[0]
workspace = r"C:\Users\talmeida\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\Connection to dsd15_sqlexpress.sde"
# Start an edit session. Must provide the workspace.
edit = arcpy.da.Editor(workspace)
# Edit session is started without an undo/redo stack for versioned data
# (for second argument, use False for unversioned data)
edit.startEditing(True)
# Start an edit operation
edit.startOperation()
#Select parcel within selected address Points
arcpy.SelectLayerByLocation_management(parcels, "INTERSECT", addressPoints)
with arcpy.da.SearchCursor(parcels, ['ACCOUNT','SiteStreet']) as singleCursor:
for singleRow in singleCursor:
ACCOUNT = singleRow[0]
SiteStreet = singleRow[1]
with arcpy.da.UpdateCursor(addressPoints, ['Account', 'SiteStreet']) as singleCursor:
for singleRow in singleCursor:
singleRow[0] = ACCOUNT
singleRow[1] = SiteStreet
singleCursor.updateRow(singleRow)
# Stop the edit operation.
edit.stopOperation()
edit.stopEditing(True)
print('Parcel address update is complete.')
elif 1 < pointCount < 1000:
#Create in memory parcel layer
selectedPoints = arcpy.MakeFeatureLayer_management(addressPoints, "selectedPoints")
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
if lyr.name == addressPoints:
addressLayer = lyr
if lyr.name == parcels:
parcelsLayer = lyr
workspace = r"C:\Users\talmeida\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\Connection to dsd15_sqlexpress.sde"
# Start an edit session. Must provide the workspace.
edit = arcpy.da.Editor(workspace)
# Edit session is started without an undo/redo stack for versioned data
# (for second argument, use False for unversioned data)
edit.startEditing(True)
# Start an edit operation
edit.startOperation()
with arcpy.da.SearchCursor(parcels, ['ACCOUNT', 'SiteStreet', 'OBJECTID']) as parcelCursor:
for parcelRow in parcelCursor:
ACCOUNT = parcelRow[0]
SiteStreet = parcelRow[1]
OID = parcelRow[2]
OID = str(OID)
arcpy.SelectLayerByAttribute_management("selectedPoints", "NEW_SELECTION", "OBJECTID= "+OID)
#Select parcels by location, within selected Address Points.
arcpy.SelectLayerByLocation_management(parcels,"INTERSECT","selectedPoints")
with arcpy.da.UpdateCursor(addressPoints, ['Account', 'SiteStreet']) as addressCursor:
for addressRow in addressCursor:
addressRow[0] = ACCOUNT
addressRow[1] = SiteStreet
addressCursor.updateRow(addressRow)
# Stop the edit operation.
edit.stopOperation()
edit.stopEditing(True)
arcpy.Delete_management("selectedPoints")
print('Parcel address update is complete.')
else:
print('Please select a valid number of parcels.')