How to set collision detection and limit in .Net Plugin

Hi,

I have some problems when I want to set some configurations for simulations

I have these settings first:

avant

I want these for result:

apres

I’m trying to set these configurations using this code:

private void App_LayoutLoaded(object sender, LayoutLoadedEventArgs e)
{
app.IsCollisionDetectionActivated = true; // detectors active
ISimulation sim = app.Simulation;
sim.JointLimitTestSettings |= JointLimitTestSettings.StopAtLimit;
sim.JointLimitTests |= JointLimitTests.Singularity;
sim.TimeMode = SimulationTimeMode.VirtualTime;
sim.Update();

// we active all detectors except Selection vs World (who is the first)
IDetectorManager iDetectorManager = IoC.Get<IDetectorManager>();
iDetectorManager.IsActive = true;
for (int id = 0; id < iDetectorManager.AllDetectors.Count; id++)
{
    ICollisionDetector cd = iDetectorManager.AllDetectors[id];
    if (id == 0)    // this is Selection vs World that we do not want
    {
        cd.IsActive = false;

        //-------------------- TODO: do not seams to work (why is it on the detector as in the UI it is global like)
        cd.StopOnCollision = true;
        cd.DetectFirstCollisionOnly = true;
        cd.Tolerance = 0.01;
        cd.MinimumDistance = false;
        //--------------------
    }
    else
    {
        cd.IsActive = true;

        //-------------------- TODO: do not seams to work (why is it on the detector as in the UI it is global like)
        cd.StopOnCollision = true;
        cd.DetectFirstCollisionOnly = true;
        cd.Tolerance = 0.01;
        cd.MinimumDistance = false;
        //--------------------
    }
}

iDetectorManager.ReConfigureDetectors();
app.Simulation.Update();
app.Simulation.SaveState();

ms.AppendMessage("\nTEST -- INFO --> Layout #" + layoutIndex + " : " + app.LayoutUri + " has been loaded\n", MessageLevel.Warning);

}

it’s not working:

the settings don’t change on the ribbon

I even tried to save a layout using the main application:
I change the settings, save the layout
load another layout, change the settings again
when I reload the previous layout, the settings should be back, but no, they are not.

Can you help me?

Thanks