Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Python add in- update two fields in one feature based on same fields of another

$
0
0
I'm totally new to making add ins and quite novice at python itself but I have a script that executes perfectly as a script tool or simply in the python window of ArcMap. I want to make this a quick button click so I looked into making an add-in toolbar with a button.

Just to get the hang of making the addin i made a print "Hello World!" that works as expected.

However, it seems something is going wrong with my code when put into the add-in. I can only assume I'm missing some syntax due to my inexperience with python.

The situation here is I have a percels layer and an address points layer, which both contain a PIN and TMS number. I simply want to have the function select the address points within the parcel geometry, find the value of PIN and TMS from the parcel layer's attribute table, and update the same fields in the address points' attribute table. Again, the script I've written executes perfectly inside the python console in ArcMap but not as an add-in. Thanks for any hints you all might have!

So here's what I've got:

Code:

import arcpy
import pythonaddins

class BlueBird(object):
    """Implementation for BlueBird.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
arcpy.SelectLayerByLocation_management("Address Points","COMPLETELY_WITHIN","Parcels")

#insert if statement checking that only one parcel is selected to prevent selecting all address points

with arcpy.da.SearchCursor("Parcels",'PIN') as cursor:
        for row in cursor:
                storedPIN = row[0]
with arcpy.da.UpdateCursor("Address Points",'PIN') as cursor:
        for row in cursor:
                row[0] = storedPIN
                cursor.updateRow(row)

del cursor

with arcpy.da.SearchCursor("Parcels",'TMS') as cursor:
        for row in cursor:
                storedTMS = row[0]
with arcpy.da.UpdateCursor("Address Points",'TMS') as cursor:
        for row in cursor:
                row[0] = storedTMS
                cursor.updateRow(row)

del cursor, storedPIN, storedTMS


Viewing all articles
Browse latest Browse all 2485

Trending Articles