6

I'm trying to add a tool to an add-in toolbar to select features from an existing feature class and copy attributes to another feature class, from point to point.

TopoHeight_Field_Name='Comment'
def testing(mxd,Transfare_Anno_row):
    for lyr in arcpy.mapping.ListLayers(mxd):
        if lyr.name=="sManhole":
           msg= "Your Layer is " + str(lyr)
           with arcpy.da.UpdateCursor(lyr,TopoHeight_Field_Name) as cursor:
              pythonaddins.MessageBox(msg, "My Layer")
              for row in cursor:
                   pythonaddins.MessageBox(msg, "My Layer")
                   row[0]=Transfare_Anno_row
                   cursor.updateRow(cursor)

class SelectByLine(object):
"""Implementation for SelectByLine_addin.tool (Tool)"""
def __init__(self):
    self.enabled = True
    self.shape = 3 
def onMouseDownMap(self, x, y, button, shift):
    mxd = arcpy.mapping.MapDocument("CURRENT")
    pointGeom = arcpy.PointGeometry(arcpy.Point(x, y), mxd.activeDataFrame.spatialReference)
    searchdistance = getSearchDistanceInches(mxd.activeDataFrame.scale)
    lyr = arcpy.mapping.ListLayers(mxd)[0] # assumes you want to select features from 1st layer in TOC
    arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", pointGeom, "%d INCHES" % searchdistance)
    with arcpy.da.SearchCursor(lyr,TextString_Field_Name) as cursor:
        for Anoorow in cursor:
            Anno_row=Anoorow[0]
            SourceFlag=1
    message = "Your mouse clicked:" + str(x) + ", " + str(y)+"Your Layer is" + str(lyr)+"Your Anno Filed is" + str(Anno_row)
    pythonaddins.MessageBox(message, "My Coordinates")
    if SourceFlag:
        testing(mxd,Anno_row)

When I Call the testing function it will send the first message box but can not send the second message box and is not updating the row.

0

1 Answer 1

0

I think your question distils to whether it is possible using a single click on a Python AddIn tool to have the user interactively specify in order more than one geometry (in this case two points) to use in its processing, and to that I think the answer is "No".

To achieve your goal here, using just a Python AddIn, I originally thought that you may need to use two tools.

  • The first to point at the feature whose attributes you want to copy into global variable values.
  • The second to point at the feature that you want to update the attributes of using the global variable values.

However, an alternative may be to use a single click to draw a two point line from the feature whose attributes you want to copy into global variable values, to the feature that you want to update the attributes of using the global variable values. You could then use the coordinates of those two ends to select and use those features.

Other alternatives to consider, which do not involve ArcPy, are:

Finds where the source line features spatially match the target line features and transfers specified attributes from source features to matched target features.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.