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();
        try {
            context = new OpenSimContext(model.initSystem(), model);
            context.cacheModelAndState();
            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 marker = markerset.addMarker(newMarkerName, offset, body);
            // This exercises Marker -> delete
            //markerset.remove(marker);
            context.restoreStateFromCachedModel();
        } catch (IOException ex) {
            ex.printStackTrace();
            System.out.println("Failed to initialize Context");
            System.exit(-1);
        }
        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);
  }

}

@@ -359,26 +359,8 @@
 ();%0A
-        try %7B%0A    
     
@@ -424,54 +424,8 @@
 l);%0A
-            context.cacheModelAndState();%0A    
     
@@ -468,28 +468,24 @@
 arkerSet();%0A
-    
         // T
@@ -555,20 +555,16 @@
         
- 
-   
 Vec3 off
@@ -605,20 +605,16 @@
         
-    
 Body bod
@@ -652,20 +652,16 @@
         
-  
-  
 String n
@@ -688,20 +688,16 @@
 arker%22;%0A
-    
         
@@ -744,82 +744,384 @@
     
-    Marker marker = m
+Marker newMarker = new Marker();%0A        newMarker.setName(newMarkerName);%0A        newM
 arker
+.
 set
-.addMarker(newMarkerName, offset, body
+_location(offset);%0A        newMarker.setParentFrame(body);%0A        context.cacheModelAndState();%0A        markerset.adoptAndAppend(newMarker);%0A        try %7B%0A            context.restoreStateFromCachedModel();%0A        %7D catch (IOException ex) %7B%0A            System.exit(1
 );%0A    
+    %7D%0A
     
@@ -1167,22 +1167,173 @@
         
+context.cacheModelAndState();%0A        Marker findMarker = Marker.safeDownCast(model.getComponent(%22newMarker%22));%0A        assert (findMarker != null);%0A    
     
-//
 markerse
@@ -1345,17 +1345,21 @@
 ove(
-m
+findM
 arker);%0A
     
@@ -1346,32 +1346,46 @@
 ve(findMarker);%0A
+        try %7B%0A
             cont
@@ -1470,93 +1470,573 @@
     
-ex.printStackTrace();%0A            System.out.println(%22Failed to initialize Context%22);
+System.exit(1);%0A        %7D%0A        markerset.print(%22savedMarkers.xml%22);%0A        // Now create a new MarkerSet from the file%0A        MarkerSet newMarkerSet = new MarkerSet(model, %22savedMarkers.xml%22);%0A        Marker newMarkerRenamed = newMarkerSet.get(0);%0A        String addedMarkerName = newMarkerRenamed.getName()+%22_renamed%22;%0A        newMarkerRenamed.setName(addedMarkerName);%0A        context.cacheModelAndState();%0A        markerset.adoptAndAppend(newMarkerRenamed);%0A        try %7B%0A            context.restoreStateFromCachedModel();%0A        %7D catch (IOException ex) %7B
 %0A   
@@ -2048,33 +2048,32 @@
     System.exit(
--
 1);%0A        %7D%0A  
@@ -2062,32 +2062,164 @@
 t(1);%0A        %7D%0A
+        Marker findMarkerAdded = Marker.safeDownCast(model.getComponent(addedMarkerName));%0A        assert(findMarkerAdded != null);%0A
         System.e

Test includes add New, delete, save to file and load from file