Does CurveEvaluator3D.getPointAtParameter work in Javascript?

Does CurveEvaluator3D.getPointAtParameter work in Javascript?

carloquinonez
Advocate Advocate
572 Views
2 Replies
Message 1 of 3

Does CurveEvaluator3D.getPointAtParameter work in Javascript?

carloquinonez
Advocate
Advocate

Hi - I can't figure out how to use CurveEvaluator3D.getPointAtParameter in javascript.

 

First, I've figured out the documentation is wrong (i think). The docs say to pass in the parameter in as an object { value: parameter} but that throws an error (Parameter must be a number). This error disappears when I just pass in the parameter (not inside an object). Unfortunately, the returnObject is is completely empty - no properties as far as I can detect even though returnValue is true. 

 

var selection = selections.item(0);
var entity = selection.entity; // sketchLine
var geometry = entity.geometry; // line3D
var evaluator = geometry.evaluator; // curve3devaluator
var returnObject = {};
var returnValue = evaluator.getPointAtParameter(0.5, returnObject); // the extent is 0-1 in my case.

 

Has anyone else used this successfully in javascript? I would really appreciate some working sample code...

 

And, seriously, debugging Fusion scripts is just miserable without a working debugger and no console.


-CQ
0 Likes
573 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Hi, 

 

I can't help you with the javascript version of the getPointAtParameter method, but below, you find a working version using this method written in Python. I also tried to reproduce the code in javascript, but I also failed (I have literally no experience in javascript).

The point to notice is that each point on a face is parametrized by two values - the u and the v parameter of the surface point. I hope this might help.

 

 

 

surfEval = face.evaluator
paramRange = surfEval.parametricRange()
parameter=paramRange.minPoint 
(retVal, boundariesMinAs3DPoint)=surfEval.getPointAtParameter(parameter)
# or, more explicitly
parameter=adsk.core.Point2D.create(boundariesMin.x,boundariesMin.y)
(retVal, boundariesMinAs3DPoint)=surfEval.getPointAtParameter(parameter)

 

0 Likes
Message 3 of 3

ekinsb
Alumni
Alumni

You're right that the syntax example in the help is quite right.  It's created automatically using the API definition so I'll have to investigate if it's the definition or the help compilation that has the problem.

 

Here's a JS sample that works.  To visualize the result it creates a construction point at the mid-point of the parametric range of the selected face.  The document you run this in needs to be a direct modeling document or the work point creation will fail.  You can change it by clicking the gear in the lower-right corner and choosing "Do not capture design history".

 

function run(context) {

    "use strict";
    if (adsk.debug === true) {
        /*jslint debug: true*/
        debugger;
        /*jslint debug: false*/
    }
 
    var ui;
    try {
        var app = adsk.core.Application.get();
        ui = app.userInterface;
     
        var face = adsk.fusion.BRepFace.cast(ui.selectEntity('Select a face', 'Faces').entity);
        var faceEval = face.evaluator;
        
        var paramRange = faceEval.parametricRange();
        var midU = (paramRange.maxPoint.x + paramRange.minPoint.x) / 2;
        var midV = (paramRange.maxPoint.y + paramRange.minPoint.y) / 2;
        
        var modelPointObj = {};
        var ret = faceEval.getPointAtParameter(adsk.core.Point2D.create(midU, midV), modelPointObj);
        var modelPoint = modelPointObj.value;
        
        var des = adsk.fusion.Design(app.activeProduct);
        var root = des.rootComponent;
        var pointInput = root.constructionPoints.createInput();
        pointInput.setByPoint(modelPoint);
        root.constructionPoints.add(pointInput);
    } 
    catch (e) {
        if (ui) {
            ui.messageBox('Failed : ' + (e.description ? e.description : e));
        }
    }

    adsk.terminate(); 
}

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes