NACA Airfoil script

 From:  Hamish Mead (HAIRYKIWI)
7265.17 In reply to 7265.15 
Hi Michael,

Thanks for your suggestions and further explanations.

In a hurry, I was using <code><\code> - i.e. wrong slash direction. :/

I found the .update() .getCreatedObjects() approach you suggested 'sort of works', but leaves 'orphaned display objects'; see my note at the end of the first code block below.

Here's are three 'Join Two Line Segment' examples (can be copy pasted into the script console that ttype mentioned earlier):
Partially working code:
var line_a = moi.command.createFactory( 'line' );
line_a.setInput( 0, moi.vectorMath.createPoint( 0, 0, 0 ));
line_a.setInput( 1, moi.vectorMath.createPoint( 1, 1, 0 ));
line_a.update();
var objectlist_a = line_a.getCreatedObjects();

var line_b = moi.command.createFactory( 'line' );
line_b.setInput( 0, moi.vectorMath.createPoint( 0, 0, 0 ));
line_b.setInput( 1, moi.vectorMath.createPoint( 1, -1, 0));
line_b.update();
var objectlist_b = line_a.getCreatedObjects();

var objectstojoin = moi.geometryDatabase.createObjectList();
for ( var i = 0; i < objectlist_a.length; i++ ) objectstojoin.addObject( objectlist_a.item(i));
for ( var i = 0; i < objectlist_b.length; i++ ) objectstojoin.addObject( objectlist_b.item(i));

moi.geometryDatabase.addobjects(objectstojoin);

var factoryjoin_ab = moi.command.createFactory( 'join' );
factoryjoin_ab.setInput( 0, objectstojoin );
factoryjoin_ab.commit();


//  line_a.update() and line_b.update() displays those objects, but of course doesn't commit them,
//  leaving 'orphaned display objects' visible: i.e. objects that are displayed, but never selectable after the script completes.


In the end I discovered that using the factory.calculate().item() approach - without using .getCreatedObjects() - does actually work as required.
Here are two examples:

Working code:
var line_a = moi.command.createFactory( 'line' );
line_a.setInput( 0, moi.vectorMath.createPoint( 0, 0, 0 ));
line_a.setInput( 1, moi.vectorMath.createPoint( 1, 1, 0 ));
var line_a_objectlist = line_a.calculate();

var line_b = moi.command.createFactory( 'line' );
line_b.setInput( 0, moi.vectorMath.createPoint( 0, 0, 0 ));
line_b.setInput( 1, moi.vectorMath.createPoint( 1, -1, 0 ));
var line_b_objectlist = line_b.calculate();

var objectstojoin = moi.geometryDatabase.createObjectList();
for ( var i = 0; i < line_b_objectlist.length; i++ ) objectstojoin.addObject(line_a_objectlist.item(i));
for ( var i = 0; i < line_b_objectlist.length; i++ ) objectstojoin.addObject(line_b_objectlist.item(i));

moi.geometryDatabase.addobjects(objectstojoin);

var factoryjoin_ab = moi.command.createFactory( 'join' );
factoryjoin_ab.setInput( 0, objectstojoin );
factoryjoin_ab.commit();

// Notes:
// .item(i) returns the i'th GeomObject object
// .calculate() returns an ObjectList of objects
// .addobject ONLY takes a GeomObject object
// .addobjects ONLY takes an objectlist



Working code:
var line_a = moi.command.createFactory( 'line' );
line_a.setInput( 0, moi.vectorMath.createPoint( 0, 0, 0 ));
line_a.setInput( 1, moi.vectorMath.createPoint( 1, 1, 0 ));

var line_b = moi.command.createFactory( 'line' );
line_b.setInput( 0, moi.vectorMath.createPoint( 0, 0, 0 ));
line_b.setInput( 1, moi.vectorMath.createPoint( 1, -1, 0 ));

var objectstojoin = moi.geometryDatabase.createObjectList();

objectstojoin.addObject(line_a.calculate().item(0));
objectstojoin.addObject(line_b.calculate().item(0));

moi.geometryDatabase.addobjects(objectstojoin);

var factoryjoin_ab = moi.command.createFactory( 'join' );
factoryjoin_ab.setInput( 0, objectstojoin );
factoryjoin_ab.commit();

// Notes:
// .item(i) returns the i'th GeomObject object
// .calculate() returns an ObjectList of objects
// .addobject ONLY takes a GeomObject object
// .addobjects ONLY takes an objectlist


I'll update the NACA Airfoil script when I get a spare moment.

Good night, and thank you all your help :)

- Hamish