General technical questions about v3 Moi's API

 From:  mkdm
8010.7 In reply to 8010.6 
Hi Michael,

First of all i wish to thank you for your support.

After following your suggestions i produced a first working version of my javascript code.

Here's are the core javascript line codes :

code:
var input = this.getInputData(0, moi.geometryDatabase.createObjectList()); // take the input from NodeEditor
var output = moi.geometryDatabase.createObjectList();

var curves = input.getCurves();

for (var i = 0;  i < curves.length; i++) {

	var subObjs = curves.item(i).getSubObjects();

	if (subObjs.length > 1) {
		var objListTmp = moi.geometryDatabase.createObjectList();
		objListTmp.addObject(curves.item(i));

		// separate the multisegmented curve, using the NodeEditor's wrapper factory() method
		// Just for info, it simply calls the Moi's createFactory() method as shown below :
		// function factory( factoryname ) { var f = moi.command.createFactory( factoryname ); for ( var i = 1; i < arguments.length; i++ ) if (arguments[i] !==null) f.setInput( i - 1, arguments[i] ); var obj = f.calculate(); f.cancel(); return obj; }		
		
		var segCurves = factory('separate', objListTmp);

		for ( var i2 = 0; i2 < segCurves.length; i2++ ) {
			var addSegCurve = false;
			
			// INIT OF MY FILTERING CRITERIA BASED ON LENGTH
			if (this.properties.maxL != this.properties.minL) {
				if (this.properties.minL == 0) {
					addSegCurve = (segCurves.item(i2).getLength() > this.properties.minL);
				} else {
					addSegCurve = (segCurves.item(i2).getLength() >= this.properties.minL);
				}
				if (this.properties.maxL > 0) {
					addSegCurve = addSegCurve && (segCurves.item(i2).getLength() <= this.properties.maxL);
				}
			} else {
				if (this.properties.minL == 0) {
					addSegCurve = true;
				} else {
					addSegCurve = (segCurves.item(i2).getLength() == this.properties.minL);
				}
			}
			// END OF MY FILTERING CRITERIA BASED ON LENGTH
			
			if (addSegCurve) {
				output.addObject(segCurves.item(i2));
			}						
		}
	}
}


But it seems that this is the only working code...

> I forget what happens if you run separate on a single segment curve, if it skips those then you would need to use crv.clone() on single segment curves instead.

I tried both methods :

1) Trying to directly clone the curve's sub segment : var x = subObjs.item(y).clone();
It generates an error : Moi's message is "Exception occurred"

2) Trying to run the "separate" factory command on a single curve segment but it generates an empty ObjectList and i get the same "Exception occurred" :
code:
for ( var i2 = 0; i2 < subObjs.length; i2++ ) {
	var objListTmp = moi.geometryDatabase.createObjectList();
	objListTmp.addObject(subObjs.item(i2));

	var segCurves = factory('separate', objListTmp);

	moi.UI.alert(segCurves.length);

	output.addObject(segCurves.item(0)); // generate exception 'cause the ObjectList is empty
}



So, only the first block of code seems to work.

Am i doing something wrong with the other approaches ?

Thank you very much for you patience and have a nice day!

Marco (mkdm).