Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Control slider joint using drive joint in a sub-assembly?

suraj.james6
Explorer

Control slider joint using drive joint in a sub-assembly?

suraj.james6
Explorer
Explorer

I have a slider rail assembly which is assembled in a sub-assembly, which is assembled in the root component. I need to run a loop to move the slider with increaments of 1 mm and extract the physical properties of the whole body as a CSV file. I have figured out to extract the CSV file using python but unable to drive the joints.

 

Hierarchy

Full assembly-->Main Base-->Slider assembly-->Slider1

in the below format

root.Component-->Component-->Sub-Component-->Joint

 

I found some info on revolute joints, but very little on slider joints.

 

0 Likes
Reply
397 Views
3 Replies
Replies (3)

kandennti
Mentor
Mentor

Hi @suraj.james6 .

 

Using the attached f3d file, I made a sample to get CenterOfMass while changing SlideValue.

The result will be displayed in the TextCommands palette.

# Fusion360API Python script
import adsk.core, adsk.fusion, traceback

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

        res = getCenterOfMass_SlideMotion(
            root,
            root.joints[0],
            -10,
            10,
            1)
        
        dumpMsg('\n'.join(res))

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


def getCenterOfMass_SlideMotion(
    targetComp :adsk.fusion.Component,
    targetJoint :adsk.fusion.Joint,
    minValue :float,
    maxValue :float,
    stepValue :float) -> list:

    ui = None
    try:
        app = adsk.core.Application.get()
        des = app.activeProduct
        ui = app.userInterface

        jm :adsk.fusion.JointMotion = targetJoint.jointMotion
        originalValue = jm.slideValue

        unitsMgr = des.unitsManager
        defLenUnit = unitsMgr.defaultLengthUnits
        covUnit = unitsMgr.convert(1, unitsMgr.internalUnits, defLenUnit)

        com = targetComp.physicalProperties.centerOfMass
        info = ['SlideValue,X{0},Y{0},Z{0}'.format(defLenUnit)]
        value = minValue
        while True:
            jm.slideValue = value
            info.append(f'{value}, {com.x * covUnit}, {com.y * covUnit}, {com.z * covUnit}')

            value += stepValue
            if value > maxValue:
                break

        jm.slideValue = originalValue

        return info

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

def dumpMsg(msg :str):
    adsk.core.Application.get().userInterface.palettes.itemById('TextCommands').writeText(str(msg))

1.png

 

0 Likes

kandennti
Mentor
Mentor
0 Likes

suraj.james6
Explorer
Explorer

Hi @kandennti ,

 

Thanks for sharing the code. But I'm having issues finding my joint. The joint is in a sub assembly of a sub assembly (See image). How do I fing the joint using the API and then extract the properties exactly like your code.

surajjames6_0-1630729697817.png

 

0 Likes