Error when reading rotationValue

Error when reading rotationValue

Anonymous
Not applicable
656 Views
3 Replies
Message 1 of 4

Error when reading rotationValue

Anonymous
Not applicable

I am trying to change the angel of a simple revolution as BuiltIn joint like this:

 

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

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

        occ = root.occurrences.itemByName("MyComponent:1")     
        ui.messageBox(occ.name)
        driveJoint = occ.component.asBuiltJoints.itemByName("Rev7")

        revMotion = adsk.fusion.RevoluteJointMotion.cast(driveJoint.jointMotion)
        somevar = revMotion.rotationValue
        revMotion.rotationValue = somevar
        ui.messageBox(revMotion.rotationValue)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

The problem is that I always get an error when trying to read the value of `rotationValue` like in this line:

 

    revMotion.rotationValue

 

 

---------------------------
Fusion 360
---------------------------
Failed:
Traceback (most recent call last):
  File "C:/Users/XXX/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/Simulator/Simulator.py", line 22, in run
    somevar = revMotion.rotationValue
  File "C:/Users/XXX/AppData/Local/Autodesk/webdeploy/production/e93c21ea16478b49c4dee1f65accf1a11ae6ef96/Api/Python/packages\adsk\fusion.py", line 50025, in _get_rotationValue
    return _fusion.RevoluteJointMotion__get_rotationValue(self)
RuntimeError: 2 : InternalValidationError : axis

---------------------------
OK   
---------------------------

 

 

Could anyone help me to get rid of this error? I cannot understand totally why this is happening..

 

What I am trying to achieve is getting a relative motion, so just to increase the current angel like this:

 

    revMotion.rotationValue = revMotion.rotationValue + 1

 

0 Likes
657 Views
3 Replies
Replies (3)
Message 2 of 4

kandennti
Mentor
Mentor

Hi @Anonymous .

 

Isn't driveJoint set to None?

 

driveJoint = occ.joints.itemByName ("Rev7")


How about changing to?

0 Likes
Message 3 of 4

Anonymous
Not applicable

Hello, actually noy because I am able to move the joint when I write an explicit value to the rotationValue, but reading it causes the error.

0 Likes
Message 4 of 4

kandennti
Mentor
Mentor

I ran the following code with the model data in the attachment.
I couldn't reproduce the situation.

 

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

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

        occ = root.occurrences.itemByName("MyComponent:1")     
        ui.messageBox(occ.name)
        driveJoint = occ.joints.itemByName("Rev7")

        revMotion = adsk.fusion.RevoluteJointMotion.cast(driveJoint.jointMotion)
        somevar = revMotion.rotationValue
        revMotion.rotationValue = somevar
        ui.messageBox(str(revMotion.rotationValue))
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

0 Likes