Odd one this, not sure if I'm missing something obvious. I'm trying to take a user selected isopoint on a curve, figure out it's percentage position on the curve and feed this into a path constraint to add a null at that point along the curve. Script below does exactly that, except the nulls it generates are accurately placed when the curve is linear and has 2 control points. Once the curve becomes more complicated then it appears the reported percentage from the isopoint selection gets wildly inaccurate.
Any ideas welcome!
Code: Select all
//FIRST DRAW A CURVE!!!
var crv = dictionary.getobject("crvlist");
SelectObj(crv);
SetSelFilter("Isopoint");
//pick a point on the curve
var rtn = PickElement("isopoint");
var button = rtn.Value("ButtonPressed");
var iso = rtn.Value("PickedElement");
//get the percentage of the isopoint on the curve (0-1)
if (button!=0)
{
var e = iso.SubElements2.toArray();
var p = e[1];
}
//display percentage
LogMessage("ISOPOINT: "+iso);
LogMessage("PERCENTAGE: "+p*100);
//put null on curve using percentage got from isopoint selection
var nul = Application.ActiveProject.ActiveScene.Root.addnull();
ApplyCns("Path", nul, crv, null);
SetValue(nul+".kine.pathcns.perc", p*100, null);