Unable to move or rotate mesh body

Unable to move or rotate mesh body

Anonymous
Not applicable
1,236 Views
2 Replies
Message 1 of 3

Unable to move or rotate mesh body

Anonymous
Not applicable

I am trying to work with mesh bodies using the fusion 360 api. I cannot seem to get the basic functionality down. All I am trying to do right now is move or rotate a mesh body.

 

Here is my code so far (I start by manually inserting the .obj file into a new document) that I've mostly gotten too from the MoveFeatures sample:

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

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        rootComp = design.rootComponent
        features = rootComp.features
        meshBodies = rootComp.meshBodies
        footMesh = meshBodies.item(0)     

        bodies = adsk.core.ObjectCollection.create()
        bodies.add(footMesh)
        
        # Create a transform to do move
        vector = adsk.core.Vector3D.create(0.0, 10.0, 0.0)
        transform = adsk.core.Matrix3D.create()
        transform.translation = vector

        # Create a move feature
        moveFeats = features.moveFeatures
        moveFeatureInput = moveFeats.createInput(bodies, transform)
        moveFeats.add(moveFeatureInput)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

When I run this, I get the following "invalid inputEntity" error:

 

Image 3.png

 

When I look at the debugger, my datatypes seem to be what I am looking for:

 

bodies is a core.Object Collection

transform is a core.Matrix3D

moveFeatureInput is a fusion.MoveFeatureInput.

 

Image 4.png

Where am I going wrong?

1,237 Views
2 Replies
Replies (2)
Message 2 of 3

marshaltu
Autodesk
Autodesk

Hello,

 

According to the description about "inputEntities", Move Feature can only work for mesh body when design is direct modeling type. 

 

http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-977a2ff7-69ab-4683-b4f1-6f847be6074d

 

The following codes would be able to work for you.

 

Thanks,

Marshal

 

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()   
        ui = app.userInterface
        
        design = adsk.fusion.Design.cast(app.activeProduct)
        design.designType = adsk.fusion.DesignTypes.DirectDesignType
        root = design.rootComponent
        
        inputentities = adsk.core.ObjectCollection.create()
        inputentities.add(root.meshBodies.item(0))
        transform = adsk.core.Matrix3D.create()
        transform.translation = adsk.core.Vector3D.create(10, 0, 0)
        
        movefeatures = root.features.moveFeatures
        movefeatureinput = movefeatures.createInput(inputentities, transform)
        movefeatures.add(movefeatureinput)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


Marshal Tu
Fusion Developer
>
0 Likes
Message 3 of 3

Anonymous
Not applicable

is it still the case that mesh object can be moved via api only if design direct type? at a cost of loss of timeline?

How come you can do move body in UI?

0 Likes