Hi Martin, you can leave out the .commit() when you're using .calculate() instead, basically calculate() is an alternate mechanism to the update/commit mechanism.
The never ending calculating loop is because of another quirk of async factories, in order for async factories to work correctly right now objects must have unique ID value generated for them and that happens when they are added to the geometry database.
But when you call .calculate(), the objects are handed back to you and they are not automatically added to the geometry database as they are with the update/commit mechanism. So they won't be visible in the display and also won't get unique IDs assigned to them. Also when you do .calculate() there won't be any input objects removed from the geometry database automatically as well so both the adding and the removing will need to be done manually for that case.
Try this (note the additional calls after .calculate() ):
code:
/*make cylinder 1*/
frame = moi.vectorMath.createTopFrame();
frame.origin = moi.vectorMath.createPoint( 0, 0, 0 );
factory = moi.command.createFactory( 'cylinder' );
factory.setInput( 1, frame );
factory.setInput( 3, 30 );
factory.setInput( 4, moi.vectorMath.createPoint( 0, 0, 60 ) );
factory.update();
var cyl1 = factory.getCreatedObjects();
factory.commit();
/*make cylinder 2*/
frame = moi.vectorMath.createTopFrame();
frame.origin = moi.vectorMath.createPoint( 0, 0, 0 );
factory = moi.command.createFactory( 'cylinder' );
factory.setInput( 1, frame );
factory.setInput( 3, 60 );
factory.setInput( 4, moi.vectorMath.createPoint( 0, 0, 30 ) );
factory.update();
var cyl2 = factory.getCreatedObjects();
factory.commit();
/*cyl2 minus cyl1*/
moi.geometryDatabase.deselectAll();
factory = moi.command.createFactory( 'booleandifference' );
factory.setInput( 0, cyl2 );
factory.setInput( 1, cyl1 );
factory.setInput( 2, false );
var result = factory.calculate();
moi.geometryDatabase.addObjects( result );
moi.geometryDatabase.removeObjects( cyl2 );
moi.geometryDatabase.removeObjects( cyl1 );
/*make cylinder 3*/
frame = moi.vectorMath.createTopFrame();
frame.origin = moi.vectorMath.createPoint( 25, 0, 0 );
factory = moi.command.createFactory( 'cylinder' );
factory.setInput( 1, frame );
factory.setInput( 3, 30 );
factory.setInput( 4, moi.vectorMath.createPoint( 25, 0, 30 ) );
factory.update();
var cyl3 = factory.getCreatedObjects();
factory.commit();
moi.geometryDatabase.selectAll();
moi.view.resetAll();
/*result minus cyl3*/
moi.geometryDatabase.deselectAll();
factory = moi.command.createFactory( 'booleandifference' );
factory.setInput( 0, result );
factory.setInput( 1, cyl3 );
factory.setInput( 2, false );
factory.commit();