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

Script for movement plot or table (Motion Study Results)

rui_pessoa
Observer

Script for movement plot or table (Motion Study Results)

rui_pessoa
Observer
Observer

Does anybody have solution to get the movement plot.

I want a plot or a excel table  of the position of joint  "slider12" in relation of "revolution2"

The drawing it's just a example.

 

Thanks in advance

0 Likes
Reply
Accepted solutions (1)
416 Views
3 Replies
Replies (3)

BrianEkins
Mentor
Mentor

I think writing a program to do this should be possible, but I'm unaware of any that already exist. I think you would want a UI allowing you to pick the joint to drive, the joint(s) to get the results from, and then where to write the results. It shouldn't be that difficult to write, and I would give it a shot, but I'm busy with some other projects I need to get finished first. 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes

kandennti
Mentor
Mentor
Accepted solution

Hi @rui_pessoa .

 

I have created a sample that changes 'Revolute 2' every once in a while and exports the value of 'Slider 12' in a csv file.
More work needs to be done to make it usable beyond the attached data.

# Fusion360API Python script

import traceback
import adsk
import adsk.core as core
import adsk.fusion as fusion
import math
import csv

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

        # get joints
        rev2: fusion.Joint = root.joints.itemByName('Revolute 2')
        sdr12: fusion.Joint = root.joints.itemByName('Slider 12')

        # get joint values
        dataLst = get_joint_values(
            rev2,
            sdr12,
            0,
            360,
            1
        )

        # export csv
        path = r'C:\temp\test.csv'
        export_csv(path, dataLst)

        ui.messageBox('Done')

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


def get_joint_values(
    ref_joint: fusion.Joint,
    target_joint: fusion.Joint,
    minValue: float,
    maxValue: float,
    step: float,
) -> list:

    app: core.Application = core.Application.get()
    des: fusion.Design = app.activeProduct
    unitsMgr: core.UnitsManager = des.unitsManager
    ratio = unitsMgr.convert(
        1,
        unitsMgr.internalUnits,
        unitsMgr.defaultLengthUnits
    )
    units = unitsMgr.defaultLengthUnits

    vp: core.Viewport = app.activeViewport
    dataLst = []

    app.executeTextCommand(u'Transaction.Start get_joint_values')

    for deg in frange(minValue, maxValue, step):
        rad = math.radians(deg)
        ref_joint.jointMotion.rotationValue = rad

        dataLst.append(
            [
                deg,
                'deg',
                target_joint.jointMotion.slideValue * ratio,
                f'{units}',
            ]
        )
        vp.refresh()
        adsk.doEvents()

    app.executeTextCommand(u'Transaction.Abort')

    return dataLst


def frange(start, end, step) -> list:
    list = [start]
    n = start
    while n + step < end:
         n = n + step
         list.append(n)
    return list


def export_csv(
    path: str,
    dataLst: list
) -> None:

    with open(path, 'w', newline='') as f:
        writer = csv.writer(f)
        writer.writerows(dataLst)
1 Like

rui_pessoa
Observer
Observer
Thanks... fully working 🙂
0 Likes