RuntimeError: 2 : InternalValidationError : results

RuntimeError: 2 : InternalValidationError : results

NuofanQiu
Enthusiast Enthusiast
1,231 Views
5 Replies
Message 1 of 6

RuntimeError: 2 : InternalValidationError : results

NuofanQiu
Enthusiast
Enthusiast

I currently write an add-in to import models into design but I can only import one model at a time.

NuofanQiu_0-1684250458125.pngNuofanQiu_1-1684250471934.png

Import only one manipulator or one gripper works. But import manipulator and gripper at the same time, something went wrong:

Traceback (most recent call last):
  File "C:\Users/Aspartame/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/ImportRobot\lib\fusion360utils\event_utils.py", line 84, in notify
    callback(args)
  File "C:\Users/Aspartame/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/ImportRobot\commands\importRobot\entry.py", line 138, in command_execute
    import_robot.importManipulator(gripper.name)
  File "C:\Users/Aspartame/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/ImportRobot\commands\importRobot\import_robot.py", line 40, in importManipulator
    importManager.importToTarget(f3dOptions, rootComp)
  File "C:\Users/Aspartame/AppData/Local/Autodesk/webdeploy/production/b4885f4229f39fee5ad2bce82f309e671e5c9ccd/Api/Python/packages\adsk\core.py", line 10892, in importToTarget
    return _core.ImportManager_importToTarget(self, importOptions, target)
RuntimeError: 2 : InternalValidationError : results

 But I test it using a script works well, here is the `test.py`:

import adsk, adsk.core, adsk.fusion
import os, sys
import pathlib
import time

def importManipulator(name: str):
    """
    name: name of manipulator
    """
    app = adsk.core.Application.get()
    ui = app.userInterface
    product = app.activeProduct
    design = adsk.fusion.Design.cast(product)
    rootComp = design.rootComponent
    importManager = app.importManager
    viewPort = app.activeViewport
    currentCamera = viewPort.camera

    # change the view to make z-axis with a up direction
    camera_up_vector = adsk.core.Vector3D.create(0.0, 0.0, 1.0)
    currentCamera.upVector = camera_up_vector
    viewPort.camera = currentCamera
    _ = viewPort.refresh()

    current_dir = os.path.dirname(os.path.abspath(__file__))
    if name == "None":
        return # do nothing
    if name == "UR5e":
        model_file = current_dir + "/robot_models/UR5e.f3d"
        f3dOptions = importManager.createFusionArchiveImportOptions(model_file)
        f3dOptions.isViewFit = True
        importManager.importToTarget(f3dOptions, rootComp)
    if name == "Robotiq85 Gripper":
        model_file = current_dir + "/robot_models/Robotiq_2F85_Gripper.f3d"
        f3dOptions = importManager.createFusionArchiveImportOptions(model_file)
        f3dOptions.isViewFit = True
        importManager.importToTarget(f3dOptions, rootComp)

importManipulator("UR5e")
importManipulator("Robotiq85 Gripper")

But I don't know what is wrong with the add-in code. I iput it at GoogleDrive hoping you can help with me. By now, I only have two `f3d` file so you can just pick `UR5e` model and `Robotiq85 Gripper` as the selection.

 

My add-in file at GoogleDrive:

Add-in at GoogleDrive 

 

Thanks a lot!

0 Likes
Accepted solutions (1)
1,232 Views
5 Replies
Replies (5)
Message 2 of 6

kandennti
Mentor
Mentor
Accepted solution

Hi @NuofanQiu .

 

I made a script and tried it. The f3d files used are the same.
This one simply imports two f3d files.

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion

import pathlib
THIS_DIR = pathlib.Path(__file__).resolve().parent

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

        paths = [
            str(THIS_DIR / 'robot_models' / 'Robotiq_2F85_Gripper.f3d'),
            str(THIS_DIR / 'robot_models' / 'UR5e.f3d'),
        ]

        import_f3ds(paths)

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


def import_f3ds(paths: list[str]) -> None:
    app: core.Application = core.Application.get()
    try:
        des: fusion.Design = app.activeProduct
        root: fusion.Component = des.rootComponent

        importMgr: core.ImportManager = app.importManager

        for path in paths:
            importOpt: core.FusionArchiveImportOptions = importMgr.createFusionArchiveImportOptions(
                path,
            )
            importMgr.importToTarget(importOpt , root)
    except:
        app.log('Failed:\n{}'.format(traceback.format_exc()))

This one was handled correctly.

 

The next script uses a dialog.
It is longer, but the import process itself is the same.

# Fusion360API Python script

import traceback
import adsk
import adsk.core as core
import adsk.fusion as fusion

import pathlib
THIS_DIR = pathlib.Path(__file__).resolve().parent

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

CMD_INFO = {
    'id': 'kantoku_test',
    'name': 'test',
    'tooltip': 'test'
}

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

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

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

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

            txtIpt: core.TextBoxCommandInput = inputs.addTextBoxCommandInput(
                'txtIpt',
                'test',
                'Click OK',
                1,
                True
            )

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


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

    def notify(self, args: core.CommandEventArgs):
        paths = [
            str(THIS_DIR / 'robot_models' / 'Robotiq_2F85_Gripper.f3d'),
            str(THIS_DIR / 'robot_models' / 'UR5e.f3d'),
        ]

        import_f3ds(paths)


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

    def notify(self, args: core.CommandEventArgs):
        adsk.terminate()


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

        cmdDef: core.CommandDefinition = _ui.commandDefinitions.itemById(
            CMD_INFO['id']
        )

        if not cmdDef:
            cmdDef = _ui.commandDefinitions.addButtonDefinition(
                CMD_INFO['id'],
                CMD_INFO['name'],
                CMD_INFO['tooltip']
            )

        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()))


def import_f3ds(paths: list[str]) -> None:
    app: core.Application = core.Application.get()
    try:
        des: fusion.Design = app.activeProduct
        root: fusion.Component = des.rootComponent

        importMgr: core.ImportManager = app.importManager

        for path in paths:
            importOpt: core.FusionArchiveImportOptions = importMgr.createFusionArchiveImportOptions(
                path,
            )
            importMgr.importToTarget(importOpt , root)
    except:
        app.log('Failed:\n{}'.format(traceback.format_exc()))

This one can reproduce the situation because it is not possible to import.

 

The main difference is the use of CommandDefinition.
The first f3d is imported, but the second one fails and the imported one disappears.
Perhaps the transaction is causing the process to revert.

 

There was a crash bug with the importToTarget method in the past.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/addin-cause-the-crash-shutdown-of-fusion-a... 

 

It was fixed in a relatively short time, but I think it is probably incomplete.
Also, using the importToTarget2 method causes the same problem.
I feel it is a bug.

Message 3 of 6

NuofanQiu
Enthusiast
Enthusiast

Yes, I have the same result as you mentioned:"The first f3d is imported, but the second one fails and the imported one disappears.".

 

Thank you for you reply. I will try to avoid it.

Message 4 of 6

espablo
Enthusiast
Enthusiast

I just had the same problem. I see it hasn't been fixed yet because I'm also trying to load the f3d file for the second time and I can't because I get this error: "RuntimeError: 2 : InternalValidationError : pBase"

0 Likes
Message 5 of 6

BrianEkins
Mentor
Mentor

I recently learned about an undocumented limitation when opening and importing files. Internally, the API calls a command to do this, which causes problems when you're running within a command, which you are in this case. That's why it works as a script because you're not in a command. I'm not sure how to work around this limitation. I think it might be possible, but it would take some experimenting to see what will work.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 6 of 6

espablo
Enthusiast
Enthusiast

Have you managed to solve this problem?