Hi all,
I have a requirement to develop a python tool to import streetlights (Electric Junction) using a CSV/Excel file. UNM editor runs this tool from ArcGIS pro map by providing CSV file, StructureJunction layer and ElectricJunction layer. CSV file provides details about the streetlights including unique pole ID (Structure Junction) it resides on and also if any existing streetlight on the pole to be removed. Unique pole id is used for the XYZ location of the streetlight. Processing needs to happen in a non-default branch version that current ArcGIS Pro map is connecting to. Here is my workflow
- Ensure current active map has UN topology layer and other required layers such as StructureJunction (for poles) and ElectricJunction (for streetlights) and is connecting to a non-default version.
- For each line in CSV file
- Read streetlight details including pole id.
- Find pole by the id and get its geometry to add a streetlight using.
- If there is existing streetlight on the pole, disassociate this streetlight from the pole and change its state to "Removed".
- Add a new streetlight.
- Create structural association between the streetlight and pole.
- Validate the location for topology.
- Go to next line
I can create a new streetlight using arcpy.da.InsertCursor on the streetlights layer. But I cannot see a python tool for creating association. Only tool available is import associations https://pro.arcgis.com/en/pro-app/latest/tool-reference/utility-networks/import-associations.htm It feels this is a overkill.
Even if I create a CSV file for the association to be created and import it, I cannot see a way to remove association for existing streetlight that needs to be disassociated from the pole for the new streetlight to be added. Is there a better way to create and remove associations using arcpy?
I tried to go down the URL way by finding the REST URL for the Streetlight layer and add a record using "addFeatures". And then I tried to add / remove association record using association layer's (layer id 500001) addFeatures and deleteFeatures. But calling REST API from a python toolbox gives me
Error: Cannot acquire a lock error.
Failed to add Streetlight ID #xxxxxx: {'error': {'code': 500, 'extendedCode': -2147220947, 'message': 'Unable to complete operation.', 'details': ['Error: Cannot acquire a lock. [StreetlightsProcessing].']}}
StreetlightsProcessing is the branch version name.
The add features and other REST operations called from python tool are using same version the current map in Pro is connecting to so that user can ensure everything is correct and then reconcile and post. It seems that having Pro map open connecting to a branch version puts a lock on the version and stops any other thread being able to perform any edits. Is this by design? Should version readers block version writer?
Any idea on how I can achieve my workflow?
Thanks in advance