Bug: Move Feature is Broken

Bug: Move Feature is Broken

Anonymous
Not applicable
1,249 Views
7 Replies
Message 1 of 8

Bug: Move Feature is Broken

Anonymous
Not applicable

Rotating MeshBodies using a move feature results in unpredictable behavior, when they have previously been rotated. Further rotations do not occur around the desired axis. And the actual axis of rotation seems to change in unpredictable ways.

This makes it impossible to move MeshBodies using the API.

Attached is a script to reproduce this issue and an example mesh with labeled faces.

 

 

Desired behavior:

The script should rotate the selected MeshBody by 4 rotations around the Z-axis. This is done by 320 small, identical moves to visualize the problem.

 

Actual behavior:

The MeshBody seems to rotate about an unknown, ever-changing axis that is neither the global or local Z axis. This makes any useful rotation impossible.

 

Steps to replicate:

Insert example mesh

Rotate by 90 degrees (or other angles) around X or Y-axis.

Select MeshBody

Run Script

Hold Undo to animate

 

#Author-Author
#Description-Description

import adsk.core, adsk.fusion, adsk.cam, traceback


def run(context):
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        des = app.activeProduct
        root = des.rootComponent

        # Creates colection from selection
        bodies = adsk.core.ObjectCollection.create()
        for selection in ui.activeSelections:
            bodies.add(selection.entity)

        # Goes to direct modeling mode since its required for some reason
        des.designType = 0

        # Creates a transformation matrix that rotates around the Z axis, centered at (0,0,0) by about 4.5 degree
        transform = adsk.core.Matrix3D.create()
        transform.setToRotation(3.141/40, adsk.core.Vector3D.create(0,0,1), adsk.core.Point3D.create(0,0,0))

        moveFeats = root.features.moveFeatures


        # Does lots of moves so you can step through by CMD-Z like an animation,
        # should do 4 Rotations and end up exactily like it started
        for i in range(320):
            moveFeatureInput = moveFeats.createInput(bodies, transform)
            moveFeats.add(moveFeatureInput)

        
        
    except:
        print(traceback.format_exc())

I would love to hear If I am doing anything wrong or there is a workaround., as my Add-In is based around working with and moving Meshes.

0 Likes
1,250 Views
7 Replies
Replies (7)
Message 2 of 8

kandennti
Mentor
Mentor

Hi edidos.

 

I tried, but it rotated on the Z axis.
However, I am Win10.

Message 3 of 8

Anonymous
Not applicable

Very Interesting.

Are you sure you rotated it by 90 degrees on x or y first?

 

I can’t imagine why a rotation function would be OS dependent.

 

Thank you.

0 Likes
Message 4 of 8

kandennti
Mentor
Mentor

I added just one line, but basically ran the code above.

 

Message 5 of 8

Anonymous
Not applicable

I am sorry I may have been unclear about this. I manually rotated the cube by 90° along X or Y before running the script. I see you missed that step as your Z face is still pointing up. I probably should have included that part in the script as well.

It workes for me as long as the cube coordinate system is aligned to the global axis. In practice that would mean I could only rotate a mesh once.

0 Likes
Message 6 of 8

kandennti
Mentor
Mentor

The phenomenon could be reproduced.
I understand the cause, but I don't know the solution.

 

MeshBody has two mesh properties (mesh, displayMesh).
https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-96f7fbb8-1faf-4f6a-8079-1129ef336033 
Only when the two match, it seems to rotate correctly.
I guess moveFeature is probably handled by the mesh property.

 

I tried with such code.

import adsk.core, adsk.fusion,  traceback

def run(context):
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        des = app.activeProduct
        root = des.rootComponent

        # Creates colection from selection
        bodies = adsk.core.ObjectCollection.create()
        # for selection in ui.activeSelections:
        #     bodies.add(selection.entity)
        mb = root.meshBodies.item(0)
        bodies.add(mb)
        msg = 'Do Mesh and DisplayMesh match? :{}'.format(isMeshMatches(mb))
        ui.messageBox(msg)

        # Goes to direct modeling mode since its required for some reason
        des.designType = 0

        # Creates a transformation matrix that rotates around the Z axis, centered at (0,0,0) by about 4.5 degree
        transform = adsk.core.Matrix3D.create()
        transform.setToRotation(3.141/40, adsk.core.Vector3D.create(0,0,1), adsk.core.Point3D.create(0,0,0))

        moveFeats = root.features.moveFeatures

        # Does lots of moves so you can step through by CMD-Z like an animation,
        # should do 4 Rotations and end up exactily like it started
        for i in range(320):
            moveFeatureInput = moveFeats.createInput(bodies, transform)
            moveFeats.add(moveFeatureInput)
            app.activeViewport.refresh()

    except:
        print(traceback.format_exc())

def isMeshMatches(
    meshBody :adsk.fusion.MeshBody):

    meshNodes = meshBody.mesh.nodeCoordinates
    dispNodes = meshBody.displayMesh.nodeCoordinates

    for m,d in zip(meshNodes, dispNodes):
        if m.distanceTo(d) > 0.001:
            return False

    return True

Only works when True.
However, I do not know how to deal with it.


This is a related article about mesh and displayMesh.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/get-world-position-of-meshbody-s-meshnode-... 

 

Message 7 of 8

Anonymous
Not applicable

So what is the best way to report this bug to Autodesk to get it resolved quickly?

 

0 Likes
Message 8 of 8

kandennti
Mentor
Mentor

Maybe Mr ?

 

The mesh workspace is still a preview features.

You may have many such problems.

0 Likes