Simple Drive Joint Example

Simple Drive Joint Example

cadop5R9X9
Enthusiast Enthusiast
3,166 Views
6 Replies
Message 1 of 7

Simple Drive Joint Example

cadop5R9X9
Enthusiast
Enthusiast

I am trying to do something similar to the drive joint example here: https://forums.autodesk.com/t5/fusion-360-api-and-scripts/inverse-kinematics-robot/m-p/5901869#M944

 

However, my layout is different than the example.  The Joints are on the main level, not under a particular geometry.  I was wondering how to directly get the joint angle in its own context, without first getting the 'piston' component. 

 

Basically I just want to write something similar to:

 

Rev1.setAngle(x)

 

 

Thanks

0 Likes
Accepted solutions (1)
3,167 Views
6 Replies
Replies (6)
Message 2 of 7

ekinsb
Alumni
Alumni

The code below gets a joint using the name of the joint and changes it's value.

 

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

    joint = root.joints.itemByName('Rev1')
    rev = adsk.fusion.RevoluteJointMotion.cast(joint.jointMotion)
    for i in range(720):
        rev.rotationValue = i * (math.pi/180)
        adsk.doEvents()
  except:
    if ui:
      ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 7

cadop5R9X9
Enthusiast
Enthusiast

Hi Brian,

 

Thanks for the fast response.  


When running that I get a traceback:

 

rev = adsk.fusion.RevoluteJointMotion.cast(joint.jointMotion)

AttributeError: 'NoneType' object has no attribute 'jointMotion'

 

my imports are below, maybe that is an issue?

 

import adsk.core, traceback
import time
import math

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        des = adsk.fusion.Design.cast(app.activeProduct)
        root = des.rootComponent
    
        joint = root.joints.itemByName('Rev1')
        rev = adsk.fusion.RevoluteJointMotion.cast(joint.jointMotion)
        for i in range(720):
            rev.rotationValue = i * (math.pi/180)
            adsk.doEvents()
            time.sleep(0.1)
        
    except:
        if ui:
          ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

0 Likes
Message 4 of 7

ekinsb
Alumni
Alumni

Do you have a joint named "Rev1" in the root component of your design?  I believe the itemByName is failing and returning None and so the next call on that variable is failing.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 5 of 7

cadop5R9X9
Enthusiast
Enthusiast

Hi,


Yes I am trying this on the file that I gave the screenshot.  I also tried renaming the joint and using that new name, but same error.  Are there issues with it not being assigned a geometry as it was in the post I had first found?

0 Likes
Message 6 of 7

ekinsb
Alumni
Alumni
Accepted solution

I think I know what it is. The UI makes this a bit confusing.  I suspect you create an as-built joint and not a regular joint.  They're two different animals.  Just change this line:

    joint = root.joints.itemByName('Rev1')

to:

    joint = root.asBuiltJoints.itemByName('Rev1')

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 7 of 7

cadop5R9X9
Enthusiast
Enthusiast

Excellent thank you! It works great. 

0 Likes