Hi,
I want to create a Pythonaddin button which automates some tasks like counts the selected features from different feature classes and list them accordingly after that it disconnects those features from geometric network and do some other stuff on those layers.
I am facing problem in disconnecting selected features on ArcMap10.6.1. As I arcpy module doesn't provide any way to disconnect so I chose ArcObjects. After some google, I got help using comtypes.
from snippets import NewObj, CType, CLSID
import comtypes.gen.esriArcMapUI as esriArcMapUI
import comtypes.gen.esriEditor as esriEditor
import comtypes.gen.esriFramework as esriFramework
import comtypes.gen.esriGeoDatabase as esriGeoDatabase
import comtypes.gen.esriSystem as esriSystemclass ButtonClass(object):
"""Implementation for My_addin.button (Button)"""
def __init__(self):
self.enabled = False
self.checked = Falsedef onClick(self):
# Do some task in python
# ...........python code............
# ...........python code............
# ...........python code............
# ArcObjects to desconnect feature from geometric network
pApp = NewObj(esriFramework.AppRef, esriFramework.IApplication)
pFeatSel = CType(pApp.Document, esriArcMapUI.IMxDocument).FocusMap.FeatureSelectionpID = NewObj(esriSystem.UID, esriSystem.IUID)
pID.Value = CLSID(esriEditor.Editor)
pExt = pApp.FindExtensionByCLSID(pID)
pEditor = CType(pExt, esriEditor.IEditor)
pEnumFeat = CType(pFeatSel, esriGeoDatabase.IEnumFeature)
pEnumFeat.Reset()net = CType(pEnumFeat.Next(), esriGeoDatabase.INetworkFeature)
net.Disconnect()
# Do something else.... lengthy task
# ...........python code............
# ...........python code............
# ...........python code............
class ExtensionClass(object):
"""Implementation for Temp_addin.extension2 (Extension)"""
def __init__(self):
# For performance considerations, please remove all unused methods in this class.
self.enabled = Truedef onStartEditing(self):
button.enabled = Truedef onStopEditing(self, save_changes):
button.enabled = False
But after the arcobjects code executes. My Python addin does not get disabled on editor stop event. Written inside onStopEditing method of ExtensionClass. I have added a pythonaddins.MessageBox("message", 'Msg', 0) in these methods but it never gets executed on editor start/stop.
def onStopEditing(self, save_changes):
button.enabled = False
If I comment the ArcObjects part then code works fine. What should I do to pass the control to python addin framework after I disconnect the features from network using ArcObjects?