Reduce mesh in API

Reduce mesh in API

barbaracc6
Participant Participant
1,064 Views
5 Replies
Message 1 of 6

Reduce mesh in API

barbaracc6
Participant
Participant

Hello there!
I am new in using API interface to control Fusion 360 and i am having a little bit of trouble finding the correspondence between Mesh > Modify > Reduce mesh command to Fusion 360 API.
I have a STL file mesh with to many facets. I want to convert it to a body, but, because of the size of it I can't do it. So, I need a little help here trying to reduce the number of facets of the mesh preserving the shape of the model (like the Fusion 360 visual interface provides).

0 Likes
1,065 Views
5 Replies
Replies (5)
Message 2 of 6

tykapl.breuil
Advocate
Advocate

I don't think there is any way to do this through the API.

However, you might be able to use textCommands to do this, as they allow you to simulate what can be done through the UI, see this post.

Message 3 of 6

j.han97
Advocate
Advocate

You can execute its command definition (ID: ParaMeshReduceCommand) directly but it is hardly useful unless you manage to figure out how to configure the command inputs with API.

Message 4 of 6

kandennti
Mentor
Mentor

Hi @barbaracc6 .

 

There is no guarantee that it will work in the future, but here is a script that divides the mesh up to the number of faces that can be converted and converts them.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/is-it-possible-to-use-text-command-within-... 

 

Message 5 of 6

kandennti
Mentor
Mentor

@barbaracc6 .

 

I tried.

Process the first MeshBody of the root component.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core

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

        if root.meshBodies.count < 1:
            return

        mesh: adsk.fusion.MeshBody = root.meshBodies[0]
        execMeshReduce(
            mesh,
            1000
        )

        ui.messageBox('Done')

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


def execMeshReduce(
    mesh: adsk.fusion.MeshBody,
    facetsCount: int):

    app: adsk.core.Application = adsk.core.Application.get()
    ui: adsk.core.UserInterface = app.userInterface
    sels: adsk.core.Selections = ui.activeSelections

    sels.clear()
    sels.add(mesh)

    cmds = [
        u'Commands.Start ParaMeshReduceCommand',
        u'Commands.SetDouble infoFacets 1', #dammy
        u'Commands.SetString infoReduceType infoTriCount',
        u'Commands.SetString infoMeshingType infoAdaptiveType',
        u'Commands.SetDouble infoFacets {}'.format(facetsCount),
        u'NuCommands.CommitCmd',
    ]

    [app.executeTextCommand(cmd) for cmd in cmds]
Message 6 of 6

barbaracc6
Participant
Participant
Thank you all for all the help provided. I managed to do what i wanted thanks to you guys!
0 Likes