Hi,
Is there a way to terminate a script that's stuck in an infinite loop? If I run something dumb like
code:
while ( true ){}
hitting the Esc key fails to terminate the script. Instead, I have to terminate MoI itself.
What does the Esc key actually do? Say I set a script to repeat by ticking the repeat checkbox in the properties panel, but the script throws an alert. If I hit Esc, that seems to be the same as clicking ok on the alert modal, rather than terminating the script. And so it goes in a loop and I have to terminate MoI. IsoAtPoints on repeat is a good example.
A mirror image of the IsoAtPoints situation happens when setting a CPlane interactively from within a script. If I hit Esc while
code:
moi.View.setCPLaneInteractive();
is running, that seems to be the same as pressing the Cancel button in the Properties Panel. That sort of makes sense, but the problem is that the rest of the script runs. How can I terminate the script rather than just canceling the CPlane tool? Or, is there some way to suppress the Cancel button when calling the CPlane tool from a script?
Is there a standalone interactive Orientation Picker I can call that doesn't have the cancel button and that sets a coordinateFrame, but not a CPlane?
Additional weirdness happens if I wrap the CPlane tool in a loop:
code:
var box;
while ( true ){
// user picks orientation of new CPlane
moi.View.setCPLaneInteractive();
// get bounding box of selected object in frame set by user
box = moi.ui.PropertiesPanel.highAccuracyBoundingBox;
var tol = 0.0001; //numerical tolerance
// check the just-set CPlane to see if it has the correct orientation
// relative to the selected object
if ( compareNumbers( box.zLength, 0, tol ) != 0 ){
// restore original CPlane in case user terminates script when error thrown
moi.view.setCplane(activeCPlane);
moi.ui.alert( "CPlane XY must coincide with face" );
} else {
break;
}
}
My intent here was to re-prompt the user if the orientation of the cplane that they set with the orientation picker isn't right. But, if I hit Esc while the CPlane tool is active the result is an infinite loop of the alert getting thrown. In other words, it looks like the while loop keeps going after hitting Esc, but somehow misses the setCPlane line. What am I doing wrong?