import org.opensim.modeling.*;
import java.io.IOException;
import static java.nio.file.StandardOpenOption.*;
import java.nio.file.*;

class TestEditMarkers {
  public static void main(String[] args) {
    try {
        Model model = new Model("gait10dof18musc_subject01.osim");
        OpenSimContext context=null;
        long t1  = System.currentTimeMillis();
        context = new OpenSimContext(model.initSystem(), model);
        MarkerSet markerset = model.getMarkerSet();
        // The following code exercises the Marker->Add New  functionality
        Vec3 offset = new Vec3(0.11, 0.22, 0.33);
        Body body = model.getBodySet().get(0);
        String newMarkerName = "newMarker";
        // This exercises Marker -> Add New
        Marker newMarker = new Marker();
        newMarker.setName(newMarkerName);
        newMarker.set_location(offset);
        newMarker.setParentFrame(body);
        context.cacheModelAndState();
        markerset.adoptAndAppend(newMarker);
        try {
            context.restoreStateFromCachedModel();
        } catch (IOException ex) {
            System.exit(1);
        }
        // This exercises Marker -> delete
        context.cacheModelAndState();
        Marker findMarker = Marker.safeDownCast(model.getComponent("newMarker"));
        assert (findMarker != null);
        markerset.remove(findMarker);
        try {
            context.restoreStateFromCachedModel();
        } catch (IOException ex) {
            System.exit(1);
        }
        markerset.print("savedMarkers.xml");
        // Now create a new MarkerSet from the file
        MarkerSet newMarkerSet = new MarkerSet(model, "savedMarkers.xml");
        Marker newMarkerRenamed = newMarkerSet.get(0);
        String addedMarkerName = newMarkerRenamed.getName()+"_renamed";
        newMarkerRenamed.setName(addedMarkerName);
        context.cacheModelAndState();
        markerset.adoptAndAppend(newMarkerRenamed);
        try {
            context.restoreStateFromCachedModel();
        } catch (IOException ex) {
            System.exit(1);
        }
        Marker findMarkerAdded = Marker.safeDownCast(model.getComponent(addedMarkerName));
        assert(findMarkerAdded != null);
        System.exit(0);
    }
    catch(IOException ex){
        System.out.println("Failed to load model or in initSystem");
        System.exit(-1);
    }
    // TODO to cause test to fail: System.exit(-1);
  }

}

@@ -196,32 +196,61 @@
 gs) %7B%0A    try %7B%0A
+        // GUI model loading%0A
         Model mo
@@ -341,55 +341,8 @@
 ll;%0A
-        long t1  = System.currentTimeMillis();%0A
     
@@ -674,52 +674,8 @@
 r%22;%0A
-        // This exercises Marker -%3E Add New%0A
     
@@ -1127,32 +1127,118 @@
 odelAndState();%0A
+        // we use getComponent to make sure Marker is accessible thru model traversal%0A
         Marker f
@@ -1508,32 +1508,57 @@
 t(1);%0A        %7D%0A
+%09%09// Exercise saveToFile%0A
         markerse

Address feedback on PR