How to use the mesh repair comand in the API

How to use the mesh repair comand in the API

joao.araujoDNTFK
Participant Participant
666 Views
1 Reply
Message 1 of 2

How to use the mesh repair comand in the API

joao.araujoDNTFK
Participant
Participant

I need to use the mesh repair feature in the API and change the repair type (Wrap, Stich and remove, rebuild); is there anyway to do it? 

0 Likes
667 Views
1 Reply
Reply (1)
Message 2 of 2

kandennti
Mentor
Mentor

Hi @joao.araujoDNTFK .

 

I don't think the mesh repair command is provided in the API, but I made a sample using a text command.

# Fusion360API Python script

import traceback
import adsk.core as core

def run(context):
    ui = core.UserInterface.cast(None)
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface

        msg: str = 'Select MeshBody'
        selFilter: str = 'MeshBodies'
        sel: core.Selection = selectEnt(msg, selFilter)
        if not sel:
            return

        exec_mesh_repair('Wrap')

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


def exec_mesh_repair(
    repairType: str):

    repairTypeDict = {
        'Close Holes': 'infoTypeSimple',
        'Stitch and Remove': 'infoTypeDefault',
        'Wrap': 'infoTypeExtended',
        'Rebuild': 'infoTypeMakeSolid',
    }

    if not repairType in repairTypeDict.keys():
        return

    app: core.Application = core.Application.get()

    app.executeTextCommand(u'Commands.Start ParaMeshRepairCommand')
    app.executeTextCommand(u'Commands.SetString infoRepairType {}'.format(repairTypeDict[repairType]))
    app.executeTextCommand(u'NuCommands.CommitCmd')


def selectEnt(
        msg: str,
        filterStr: str) -> core.Selection:

    try:
        app: core.Application = core.Application.get()
        ui: core.UserInterface = app.userInterface
        sel = ui.selectEntity(msg, filterStr)
        return sel
    except:
        return None

 

For more information about text commands, please read here.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/use-textcommands/m-p/9645688 

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/use-textcommands2/m-p/9937161 

 

0 Likes