4

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.

  • Can you edit to clarify where you are in the process, and what's working/not working? Also, do you want a toolbar add-in or a separate script: the two approaches are pretty different (although the geoprocessing steps are the same). – Erica Oct 28 '14 at 15:02
  • I am asking if there is a way using add-in tool that i can copy the attributes of feature to another- first to click on feature that i want to copy his attributes and secound to click on the feature that i want to update his attributes. – mahmoud hageer Oct 29 '14 at 6:35
  • I have updated the question – mahmoud hageer Oct 30 '14 at 7:17
  • 1
    It seems that the functionality for this tool already exists in the Attribute Transfer Tool which comes with ArcGIS Desktop. – Fezter Mar 7 '18 at 3:55
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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