Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Attempting to round-trip a Point3D via SurfaceEvaluator of face in Occurrence

1 REPLY 1
SOLVED
Reply
Message 1 of 2
CADacombs
105 Views, 1 Reply

Attempting to round-trip a Point3D via SurfaceEvaluator of face in Occurrence

CADacombs_0-1649803372914.png

 

For a rectangular, planar face from corner-to-corner, 0,0,0 to 10,10,0, a point at 5,5,0 can round-trip through the nativeObject face's SurfaceEvaluator like so:

Point3D to project: (5.0, 5.0, 0.0)

getParameterAtPoint: (0.0, 0.0)

isParameterOnFace: True

getPointAtParameter: (5.0, 5.0, 0.0)

 

On the other hand, for an occurrence of the component that contains the face that is translated 10 in +X, a round-trip attempt starting at 15,0,0 fails:

Point3D to project: (15.0, 5.0, 0.0)

getParameterAtPoint: (20.0, 0.0)

isParameterOnFace: False

getPointAtParameter: (35.0, 5.0, 0.0)  (This reflects double the aforementioned transformation.)

 

The 15,0,0 point is returned when the starting point is -5,5,0, even though no negative values were used in the creation of the patch nor the transformation of the component:

Point3D to project: (-5.0, 5.0, 0.0)

getParameterAtPoint: (0.0, 0.0)

isParameterOnFace: True

getPointAtParameter: (15.0, 5.0, 0.0)

 

It is as if getParameterAtPoint is using a proxy of the face that has been transformed from the nativeObject to the inverse of the occurrence's transform.

 

Does anyone know what is going on here?

 

import adsk.core as ac
import adsk.fusion as af
import traceback


app: ac.Application = ac.Application.get()
ui: ac.UserInterface = app.userInterface


def addComponent():
    matrix = ac.Matrix3D.create()
    matrix.translation = ac.Vector3D.create(10,0,0)

    des:af.Design = app.activeProduct

    root = des.rootComponent

    return root.occurrences.addNewComponent(matrix)


def createAndAddPatch(occ: af.Occurrence):
    comp:af.Component = occ.component

    sketch: af.Sketch = comp.sketches.add(comp.xYConstructionPlane)
    sketch.sketchCurves.sketchLines.addTwoPointRectangle(
        ac.Point3D.create(0,0,0), ac.Point3D.create(10,10,0)
    )
    profile = sketch.profiles.item(0)

    patchFeatures = comp.features.patchFeatures
    patchInput = patchFeatures.createInput(
        profile,
        af.FeatureOperations.NewBodyFeatureOperation)
    patchFeatures.add(patchInput)

    return patchFeatures.item(0)


def printPerSrfEval(face: af.BRepFace, pt_ToProj: ac.Point3D):
    app.log('-'*40)
    srfEval = face.evaluator

    app.log(f"Point3D to project: {pt_ToProj.asArray()}")

    bSuccess, uv = srfEval.getParameterAtPoint(pt_ToProj)
    if not bSuccess:
        app.log("getParameterAtPoint failed.")
        return

    app.log(f"getParameterAtPoint: {uv.asArray()}")

    app.log(f"isParameterOnFace: {srfEval.isParameterOnFace(uv)}")
    
    bSuccess, pt_FromParam = srfEval.getPointAtParameter(uv)
    if not bSuccess:
        app.log("getPointAtParameter failed.")
        return

    app.log(f"getPointAtParameter: {pt_FromParam.asArray()}")


def main():

    occ = addComponent()
    
    patch = createAndAddPatch(occ)

    pts = [
        ac.Point3D.create(5,5,0),
        ac.Point3D.create(15,5,0),
        ac.Point3D.create(-5,5,0),
    ]

    app.log('-'*60)
    face = patch.faces.item(0)
    app.log("nativeObject face")

    for pt in pts:
        printPerSrfEval(face, pt)

    app.log('-'*60)
    face = face.createForAssemblyContext(occ)
    app.log("Transformed occurrence face")

    for pt in pts:
        printPerSrfEval(face, pt)


def run(context):
    try:
        app.log('-'*80)
        main()

    except:
        app.log('Failed:\n{}'.format(traceback.format_exc()))

    app.log("\nEnd of script.")

 

1 REPLY 1
Message 2 of 2
kandennti
in reply to: CADacombs

Hi @CADacombs .

 

I don't know what is going on, but I take it that this is a specification of the Fusion360 API.
If this is changed now, it will be a problem as there are several things that will not work correctly.

 

As I mentioned here, the TemporaryBRepManager.copy method will always return the element in the root component, so it is stable.

・・・
def main():

    occ = addComponent()
    
    patch = createAndAddPatch(occ)

    pts = [
        ac.Point3D.create(5,5,0),
        ac.Point3D.create(15,5,0),
        ac.Point3D.create(-5,5,0),
    ]
    # dumpPnt(pts)

    app.log('-'*60)
    tmpMgr: af.TemporaryBRepManager = af.TemporaryBRepManager.get()
    clone = tmpMgr.copy(patch.faces.item(0)).faces[0]
    app.log("TemporaryBRepManager copy face")

    for pt in pts:
        printPerSrfEval(clone, pt)


    app.log('-'*60)
    face = patch.faces.item(0)
    app.log("nativeObject face")

    for pt in pts:
        printPerSrfEval(face, pt)

    app.log('-'*60)
    face = face.createForAssemblyContext(occ)
    occ.activate()
    app.log("Transformed occurrence face")

    for pt in pts:
        printPerSrfEval(face, pt)


    app.log('-'*60)
    clone = tmpMgr.copy(face).faces[0]
    app.log("TemporaryBRepManager copy face")

    for pt in pts:
        printPerSrfEval(clone, pt)
・・・

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report