Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

3 REPLIES 3
Reply
Message 1 of 4
suraj.james6
227 Views, 3 Replies

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

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.

 

Labels (3)
3 REPLIES 3
Message 2 of 4
kandennti
in reply to: suraj.james6

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

 

Message 3 of 4
kandennti
in reply to: kandennti

Message 4 of 4
suraj.james6
in reply to: suraj.james6

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

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums