2

For example, when I have a geometry change on a point, I would like to update the X and Y fields to the new current location, I understand how to make the code, but not where do I set or put it to be triggered/called

3
  • are you asking how to set a field to update automatically when the point is moved without having to run a stand alone script to update it or use a field calculator?
    – crld
    Commented Jun 21, 2016 at 21:11
  • looks like you can at least label the feature with dynamic text (support.esri.com/technical-article/000011568), and apparently arc 9.3 had this functionality (webhelp.esri.com/arcgisdesktop/9.3/…)
    – crld
    Commented Jun 21, 2016 at 21:19
  • 2
    We schedule our updates, rather than having them trigger on edit. Have scheduled tasks run once a day (usually at night) to perform automatic updates.
    – Midavalo
    Commented Jun 21, 2016 at 21:46

1 Answer 1

2

Use label expression:

def FindLabel ( [OID]  ):
  mxd = arcpy.mapping.MapDocument("CURRENT")
  lr=arcpy.mapping.ListLayers(mxd)[0]
  with arcpy.da.UpdateCursor(lr, ('Shape@','POINT_X','POINT_Y'),r'"OID"='+str( [OID] )) as cursor:
      for row in cursor:
         row[1]=row[0].firstPoint.X
         row[2]=row[0].firstPoint.Y
         cursor.updateRow(row)
  return '%i\n%i' %(int(row[1]),int(row[2]))
2
  • Nice! Using an existing event saves wiring a new one. Trust me FeatureModified triggers are a pain to work with - updating the feature with the new X and Y triggers the event then you go cyclic from there, after you've solved that the update of the X and Y becomes the last action so the Undo buffer is increased by one and the user can Undo the update (BAD). The more I think about it the more I like this solution. Commented Jun 21, 2016 at 22:01
  • @MichaelMiles-Stimson this is just a slight modification to this answer to your Q gis.stackexchange.com/questions/124398/…
    – FelixIP
    Commented Jun 21, 2016 at 22:03

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.