In case drive joint will do what you need, here's some example code that demonstrates driving a joint. I'm driving the joints through a series of changes to create an animation. I wanted to attach the assembly I used but unfortunately, I built in the upcoming release so the f3d can't be used in the current release. It's simple though. I have an assembly that contains two instances of the same component (which is a subassembly made up of several parts). That component is named "PistonAssembly". Inside that component I have several joints that control the behavior of the parts within it. One of those joints is a revolution joint named "Motor". This program will find the two instances of the joint and drive them indepenedently of each other.
def driveJoint():
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
des = adsk.fusion.Design.cast(app.activeProduct)
root = des.rootComponent
# Get the two occurrences in the root. These are two
# instances of the same component.
piston1 = root.occurrences.itemByName('PistonAssembly:1')
piston2 = root.occurrences.itemByName('PistonAssembly:2')
# Get the component referenced by the occurrences.
pistonComp = piston1.component
# Get the joint in the piston component. It will be in
# the context of the piston component.
motorJoint = pistonComp.joints.itemByName('Motor')
# Create proxies of the joint for each occurrence.
motor1 = motorJoint.createForAssemblyContext(piston1)
motor2 = motorJoint.createForAssemblyContext(piston2)
# Get the RevoluteJointMotion object from each joint.
revJointMotion1 = motor1.jointMotion
revJointMotion2 = motor2.jointMotion
# Drive the joints.
for i in range(0, 720, 3):
revJointMotion1.rotationValue = i * (math.pi/180.0)
revJointMotion2.rotationValue = (i+180) * (math.pi/180.0)
adsk.doEvents()
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Here's a picture of the assembly and you can see the structure in the browser.
