General technical questions about v3 Moi's API

 From:  mkdm
8010.17 In reply to 8010.14 
Hi Michael,

Regarding the possibility to easily access curves' control points, i've found a solution that has always been in front of me!

I've written a modified version of Max's DelCorners script, that simply given a bunch of selected curves as input,
creates a bunch of new point objects, automatically selected, representing the selected curves' control points.

I'm aware that this is a simple solution that doesn't allow me to access to the control points' data,
as said by you in your post (http://moi3d.com/forum/index.php?webtag=MOI&msg=6890.5)

> Hi Andrei, Max's script works by doing a "select all" and then a copy to the clipboard of the points and then a paste back in of those points.
> That is indeed a way for a script to access the points without there being a proper script interface, but it's limited in what it can recover,
> it only gets a big bunch of points and isn't able to access additional information like being able to determine
> which particular points are actually corner points or not.

> Just in general it's difficult to make scripts that do control point manipulation since things
> are not currently set up to make all the information about the points accessible to a script.

Here's my code :

code:
// ExtractCurvesControlPoints.js v.0.1 - Marco Di Mario (mkdm), 2016
// based on :
// 		Max Smirnov's DelCorners, v.1.0.2015.09.09

// Given a bunch of selected curves as input, creates a bunch of new point objects, automatically selected,
// representing the selected curves' control points.


function extractCurvesControlPoints() {
	var gd = moi.geometryDatabase;	

	var obj = gd.getObjects(); // get all the objs
	
	var selCurves = gd.getSelectedObjects().getCurves(); // get all the selected curves
	
	if (selCurves.length == 0) {
		moi.UI.alert("At least one curve must be selected!");
		return;
	}
	
	// 1 - deselect everything and turn off all control points
	obj.setProperty('selected', 0);
	obj.setProperty('showPoints', 0);
	
	// 2 - turn on control points on selected curves
	selCurves.setProperty('showPoints', 1);
	
	// 3 - select all the objs
	gd.selectAll();
	
	// 4 - doing so, only all control points remains selected.
	// In this case, the control points of the selected curves
	obj.setProperty('selected', 0);
	
	// 5 - doing so only the control points will be copied and then pasted.
	// Pasted objects are automatically selected
	gd.copyToClipboardCommand( selCurves );	
	gd.pasteFromClipboard();
	
	// 6 - turn off control points on selected curves
	selCurves.setProperty('showPoints', 0);
	
	// As final result, we have now a bunch of new point objects, automatically selected,
	// representing the selected curves' control points!

}

extractCurvesControlPoints();



The ExtractCurvesControlPoints.zip file contains a 3dm example file that can be useful to test the script.

The ExtractCurvesControlPoints.js file can be equally copied to "commands" or "scripts" folder.

I've written this script also for using it together with some NodeEditor's nodes that i'm writing
and that i hope to post as soon as possible.

For example one of these, called "ArrayRemDupl", can be used to remove duplicated points.
That is, given a PointArray and a distance, this node returns a new PointArray, containing only
all the original points, far from each other at least the given distance.

Anyway....thank you for all and have a nice day!

Ciao.

Marco (mdkm).