From: Joe (CTKJOSE)
Im on MacOS with MoI V4, just got MoI for Xmas and wanted to play a little with scripting.
I want to select a point in a curve and be able to move it precisely by an offset (x, y, z) provided by the user.
I'm a bit stock, I have searched and looked at most of the scripts in "commands" folder in the app bundle, multiple samples in the forums, among others like
http://kyticka.webzdarma.cz/3d/moi,
http://moi3d.com/forum/lmessages.php?webtag=MOI&msg=7238.5,
http://moi3d.com/wiki/MaxScriptArchive
So far I can select objects using the point picker, then get the associated objects (forcing selection to be on curves and snapping on end points). From there I get all the points of the curve then find the point that was selected with the pointpicker.
To move the point I tried `point.set(x,y,z)` but that doesn't work. I have grep the app files and the scripts I have collected from the forum and the internet for all sort of related things, looked at scripts and the only related thing is is "move"/"offset" but none that actually edits a point.
Any pointers and help will be greatly appreciated...
PS I also wonder what js engine is used in MoI, is it V8, duktape, mugs, etc?
var targets = [];
//var objects = sketch.objects;
for( i in points ){
var pt = points[i];
var o = sketch.pointPickedObject(pt);
if(!o) continue;
if(o.type !== 2 && o.type !== 1) continue; //is curve or segment?
//plugin.showAlert("OBJ.TYPE=" + o.type);
var opoints = sketch.getCurvePoints(o);
for(var k in opoints){
var pt1 = opoints[k];
//plugin.showAlert("OBJPOINT[" + k + "]=" + pt1.toString(3));
if(pt1.x == pt.x && pt1.y == pt.y && pt1.z == pt.z){
targets.push({obj: o, pt: pt1});
continue;
}
}
}
for(i in targets){
var e = targets[i];
var pt = e.pt;
var x = pt.x, y = pt.y, z = pt.z;
if( dx != 0.0 ) x += dx;
if( dy != 0.0 ) y += dy;
if( dz != 0.0 ) z += dz;
pt.set(x, y, z);
}
From: Michael Gibson
Hi Joe,
re:
> PS I also wonder what js engine is used in MoI, is it V8, duktape, mugs, etc?
It's JavaScriptCore that's part of WebKit.
re: Scripting points - MoI v4 does not have an interface for scripts to access object points but there has been some stuff added in for the current v5 beta for that.
You can get the v5 beta at
https://moi3d.com/beta.htm , and the info is in the V5 beta release notes:
https://moi3d.com/wiki/V5Beta , it's this part:
quote:
Edit points scripting - Add scripting interface on objects for:
obj.hasEditPoints - read-only property true if object has edit points, false if not.
obj.hasSelectedEditPoints - read-only property true if object has any selected edit points.
obj.numEditPoints - read-only property for number of edit points.
obj.getEditPoint( index ) - method that returns an x,y,z point for the given edit point index.
obj.getEditPointSelected( index ) - method that returns true if the given edit point is selected.
There may not be enough stuff in there yet for editing the points though, you would need to select it and then use the Move factory to create a new object with a moved point. Although you can read selection currently there isn't a set selection yet.
- Michael
From: Larry Fahnoe (FAHNOE)
Hi Joe,
Welcome to MoI!
In case you've not seen it, do see the thread on some API documentation that the community has contributed to:
https://moi3d.com/forum/index.php?webtag=MOI&msg=10857.36
The release notes also contain references to scripting changes:
https://moi3d.com/wiki/V3Beta
https://moi3d.com/wiki/V4Beta
https://moi3d.com/wiki/V5Beta
When posting code snippets on the forum, adding code tags makes it much more readable by preserving your formatting.
code:
<code> ... </code>
--Larry
From: Joe (CTKJOSE)
@FAHNOE
Thank you for sharing this info. I have in fact been digging deep on the forums and digesting all the great scripts I find from the community.
Matter of fact I started a GitHub repo to document and gather everything I find. It's WIP but I try to work on it every time I can.
https://github.com/ctkjose/moi3d