POST
|
Staring at your code for some time I found that the encapsulating method is the key. I was overwriting onCreateFeature of the IEditEventsAdapter, where it needs to be in in onStopOperation of the IEditEvents2Adapter. Here is the piece of code that works for me: 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();
}
}
}
); Thanks.
... View more
05-09-2012
04:07 AM
|
0
|
0
|
857
|
POST
|
That would delete the feature. But I need to undo polygon cut. Perhaps I could merge the polygons back if the size is small, but that would create undesirable additional vertexes. Instead of: cut polygons > if size is small > merge the polygons back I would need something like: cut polygons > if size is small > revert to original state I am really puzzled why undo does not undo things. thanks anyway.
... View more
05-03-2012
10:59 PM
|
0
|
0
|
857
|
POST
|
Thanks. I modified the code according to your example. So I included both "undo" and then "remove" operation, but still no success. When I step through it, I can see the operations to be removed from the operation stack, but nothing is actually undone. In addition I tried to remove all operations step by step and I got the "Undo failed" message from ArcMap UI. 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());
}
}
} This is the System.out messages when I do simple polygon cut: no of operations in stack before: 3 Operation to undo: Add Vertex Can be undone: true Operation to undo: Add Vertex Can be undone: true Operation to undo: Cut Can be undone: true no of operations in stack after: 0 Perhaps it has to do something with wrong editor assignment. I got reference to editor this way: IUID uid = new UID();
uid.setValue("{F8842F20-BB23-11D0-802B-0000F8037368}");
editor = (Editor) app.findExtensionByCLSID(uid);
... View more
05-02-2012
11:30 PM
|
0
|
0
|
857
|
POST
|
I am trying to programatically undo cutting of polygons if the area of newly created polygon is too small. However, the operation does no undo edits. It shows the dialog, but it does not roll back the edits. No errors are thrown in this example. 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(); } } } Is there any example of how to solve undos withing ArcMap Add-in?
... View more
05-02-2012
03:45 AM
|
0
|
6
|
4755
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|