Enable Rotation and Translation in Model Space when Dialog Box active

Enable Rotation and Translation in Model Space when Dialog Box active

peter.pant
Participant Participant
306 Views
1 Reply
Message 1 of 2

Enable Rotation and Translation in Model Space when Dialog Box active

peter.pant
Participant
Participant

Hello everyone,

 

I am currently writing a skript in Fusion 360 API. When I execute a command and the command dialog appears, I would like to enable rotation and translation in the model space while the message box is still there waiting for my input. Currently, navigation in the model space freezes once the message box appears. This is in my case an issue since a closer look on the created model is needed in order to decide for the proper message box input. Is there any way to unfreeze navigation?

 

Best Regards,

Peter

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

kandennti
Mentor
Mentor

Hi @peter.pant .

 

Since inputBox and messageBox are modal dialogs, they should not accept other operations.

The only way to make the screen operable while the dialog box is displayed (modal-less dialog) is to create a CommandDefinition and create your own command.

import traceback
import adsk.fusion
import adsk.core

_app: adsk.core.Application = None
_ui: adsk.core.UserInterface = None
_handlers = []

class MyCommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()

    def notify(self, args: adsk.core.CommandCreatedEventArgs):
        adsk.core.Application.get().log(args.firingEvent.name)
        try:
            global _handlers
            cmd: adsk.core.Command = adsk.core.Command.cast(args.command)
            inputs: adsk.core.CommandInputs = cmd.commandInputs

            onDestroy = MyCommandDestroyHandler()
            cmd.destroy.add(onDestroy)
            _handlers.append(onDestroy)

            onExecute = MyExecuteHandler()
            cmd.execute.add(onExecute)
            _handlers.append(onExecute)

            inputs.addTextBoxCommandInput(
                'txtIpt',
                'text',
                '',
                1,
                False
            )

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


class MyExecuteHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()

    def notify(self, args: adsk.core.CommandEventArgs):
        adsk.core.Application.get().log(args.firingEvent.name)


class MyCommandDestroyHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()

    def notify(self, args: adsk.core.CommandEventArgs):
        adsk.core.Application.get().log(args.firingEvent.name)
        adsk.terminate()


def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        cmdDef: adsk.core.CommandDefinition = _ui.commandDefinitions.itemById(
            'test_cmd'
        )

        if not cmdDef:
            cmdDef = _ui.commandDefinitions.addButtonDefinition(
                'test_cmd',
                'Test',
                'Test'
            )

        global _handlers
        onCommandCreated = MyCommandCreatedHandler()
        cmdDef.commandCreated.add(onCommandCreated)
        _handlers.append(onCommandCreated)

        cmdDef.execute()

        adsk.autoTerminate(False)

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