editor.addIEditEventsListener(new IEditEventsAdapter(){ public void onCreateFeature(IEditEventsOnCreateFeatureEvent theEvent) throws IOException, AutomationException{ IFeature createdFeature = (IFeature)theEvent.getObj(); Polygon newPolygon = (Polygon)createdFeature.getShape(); double newPolyArea = newPolygon.getArea(); if(newPolyArea < 1000){ MessageDialog md = new MessageDialog(); md.doModal("Error editing", "Polygon too small" , null, null, 0); doc.getOperationStack().undo(); } } }
Solved! Go to Solution.
pInFeature = CType(obj, ESRI.ArcGIS.Geodatabase.IFeature) CanDelete = False pFClass = CType(pDataset, ESRI.ArcGIS.Geodatabase.IFeatureClass) If pFClass.ShapeType = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon Then pArea = pInFeature.Shape If theDict.TryGetValue("HDX.MMU", MMUList) Then If pArea.Area < MMUList(1) Then If Windows.Forms.MessageBox.Show("The area of the polygon (" & Format(pArea.Area, "##,##0.00") & ") is less than the specified Minimum Mapping Unit." & vbNewLine & vbNewLine & "Do you want to add this polygon to your layer?", "Area Smaller than MMU", Windows.Forms.MessageBoxButtons.YesNo, Windows.Forms.MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then pInFeature.Delete() CanDelete = True Exit Sub End If End If End If End If
Private Sub OnStopOperation() Dim LastOp As Integer Dim pOperation As ESRI.ArcGIS.SystemUI.IOperation Try LastOp = My.ArcMap.Document.OperationStack.Count - 1 If CanDelete Then If LastOp > -1 Then pOperation = My.ArcMap.Document.OperationStack.Item(LastOp) If pOperation.CanUndo Then pOperation.Undo() My.ArcMap.Document.OperationStack.Remove(LastOp) Else System.Windows.Forms.MessageBox.Show("Can't undo last operation", "", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Exclamation) End If End If End If Catch ex As Exception System.Windows.Forms.MessageBox.Show(ex.ToString, "EditorExtention: OnStopOperation") End Try End Sub
pInFeature = CType(obj, ESRI.ArcGIS.Geodatabase.IFeature) CanDelete = False pFClass = CType(pDataset, ESRI.ArcGIS.Geodatabase.IFeatureClass) If pFClass.ShapeType = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon Then pArea = pInFeature.Shape If theDict.TryGetValue("HDX.MMU", MMUList) Then If pArea.Area < MMUList(1) Then If Windows.Forms.MessageBox.Show("The area of the polygon (" & Format(pArea.Area, "##,##0.00") & ") is less than the specified Minimum Mapping Unit." & vbNewLine & vbNewLine & "Do you want to add this polygon to your layer?", "Area Smaller than MMU", Windows.Forms.MessageBoxButtons.YesNo, Windows.Forms.MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then pInFeature.Delete() CanDelete = True Exit Sub End If End If End If End If
Private Sub OnStopOperation() Dim LastOp As Integer Dim pOperation As ESRI.ArcGIS.SystemUI.IOperation Try LastOp = My.ArcMap.Document.OperationStack.Count - 1 If CanDelete Then If LastOp > -1 Then pOperation = My.ArcMap.Document.OperationStack.Item(LastOp) If pOperation.CanUndo Then pOperation.Undo() My.ArcMap.Document.OperationStack.Remove(LastOp) Else System.Windows.Forms.MessageBox.Show("Can't undo last operation", "", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Exclamation) End If End If End If Catch ex As Exception System.Windows.Forms.MessageBox.Show(ex.ToString, "EditorExtention: OnStopOperation") End Try End Sub
editor.addIEditEventsListener(new IEditEventsAdapter(){ public void onCreateFeature(IEditEventsOnCreateFeatureEvent theEvent) throws IOException, AutomationException{ IFeature createdFeature = (IFeature)theEvent.getObj(); Polygon newPolygon = (Polygon)createdFeature.getShape(); double newPolyArea = newPolygon.getArea(); if(newPolyArea < 1000){ MessageDialog md = new MessageDialog(); md.doModal("Error editing", "Polygon too small" , null, null, 0); IOperationStack os = doc.getOperationStack(); System.out.println("no of operations in stack before: " + os.getCount()); for(int i = os.getCount(); i > 0; i--){ System.out.println("Operation to undo: " + os.getUndoOperation().getMenuString()); System.out.println("Can be undone: " + os.getUndoOperation().isCanUndo()); os.undo(); os.remove(i - 1); } System.out.println("no of operations in stack after: " + os.getCount()); } } }
IUID uid = new UID(); uid.setValue("{F8842F20-BB23-11D0-802B-0000F8037368}"); editor = (Editor) app.findExtensionByCLSID(uid);
editor.addIEditEvents2Listener(new IEditEvents2Adapter(){ public void onStopOperation(IEditEvents2OnStopOperationEvent theEvent) throws IOException, AutomationException{ Editor sEditor = (Editor) theEvent.getSource(); sEditor.getEditSelection(); IEnumFeature enumFeature = sEditor.getEditSelection(); enumFeature.reset(); IFeature selFeature = enumFeature.next(); for (int fCount = 0; fCount < sEditor.getSelectionCount(); fCount++) { Polygon sPolygon = (Polygon)selFeature.getShape(); double sArea = sPolygon.getArea(); if(sArea < 1000){ MessageDialog md = new MessageDialog(); md.doModal("Error editing", "Polygon too small, stopping operation" , null, null, 0); IOperationStack os = doc.getOperationStack(); os.undo(); } selFeature = enumFeature.next(); } } } );