1

I am creating a Python add-in for ArcMap, which on click, will disconnect the feature from Geometric Network and then delete it from the feature class. But ArcPy doesn't have any method to disconnect the feature. So, I looked in ArcObjects and there they have method disconnect in INetworkFeature. I am a Python developer and don't know ArcObjects ecosystem. How can I do this?

Assumption of this add-in is that Geometric Network is added to ArcMap, the editor is started and you have selected the feature which you want to disconnect and delete from feature class.

1
  • You may want to try: arcpy.RemoveEmptyFeatureClassFromGeometricNetwork_management(in_geometric_network, in_feature_class) - I know you aren't talking about empty features, but this function will only remove it from the network. But you must then delete the feature which is another python function - arcpy.DeleteFeatures_management(in_feature_class) – enolan Dec 31 '19 at 16:31
1

Turns out it is quite an easy task in ArcObject. Type cast the feature to network feature and you are done. Below is the code for reference.

# get current ArcMap application pointer
pApp = NewObj(esriFramework.AppRef, esriFramework.IApplication)

# get selected features from ArcMap
pFeatSel = CType(pApp.Document, esriArcMapUI.IMxDocument).FocusMap.FeatureSelection

# create editor to start operation
pID = NewObj(esriSystem.UID, esriSystem.IUID)
pID.Value = CLSID(esriEditor.Editor)
pExt = pApp.FindExtensionByCLSID(pID)
pEditor = CType(pExt, esriEditor.IEditor)
pEditor.StartOperation()

# get the pointer to first selected feature (in my case only one is selected on map, .Next() will give you next selected feature)
pEnumFeat = CType(pFeatSel, esriGeoDatabase.IEnumFeature)
pEnumFeat.Reset()
pFeat = pEnumFeat.Next()

# cast the feature to network feature as Disconnect is INetworkFeature method
netFeat = CType(pFeat, esriGeoDatabase.INetworkFeature)
netFeat.Disconnect() # call disconnect

# stop edit operation
pEditor.StopOperation('')

I am not an ArcObjects developer so this solution might not be the best suited or bug free.

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.