Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

Reading / Recording Component Data

Anonymous

Reading / Recording Component Data

Anonymous
Not applicable

Hey,

I'm just starting out to use the scripting/add-ins functionality of Fusion360 and I've gotten some basic understanding of the API, but my specialty does not lie in coding.  


I'm looking at a quick way to simply read/store the current angle of a revolution joint and the value of a slider joint from the RootComponent that were previously input by the user from the Interface. 

 

From there we will be inputting them into .json files, however we already have the means for that - first we need the values.

0 Likes
Reply
Accepted solutions (1)
696 Views
7 Replies
Replies (7)

JeromeBriot
Mentor
Mentor
Accepted solution

Hello,

 

Here is an example written in Python:

import adsk.core, adsk.fusion, traceback
import math

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()

        product = app.activeProduct

        design = adsk.fusion.Design.cast(product)

        for j in design.rootComponent.joints:

            if j.jointMotion.jointType == adsk.fusion.JointTypes.RevoluteJointType:

                print('Revolution: {:.3f}rad {:.3f}°'.format(j.jointMotion.rotationValue, math.degrees(j.jointMotion.rotationValue)))

            elif  j.jointMotion.jointType == adsk.fusion.JointTypes.SliderJointType:

                print('Slide: {:.3f}cm'.format(j.jointMotion.slideValue))

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

Hope this helps.

 

1 Like

Anonymous
Not applicable

This was exactly what I needed! Thank you!

0 Likes

Anonymous
Not applicable

I copied the script and pasted it in the Fusion 360 spyder2. I then cliked run, and nothing seems to happen. Where do I get the component angles. Is there a file or variable that I need to look at to check the component angles. I modeled  a six axis robotic arm and I assembled all components. My IK is working perfectly, all I need now is to get all joint angles in order to send it through serial to control my actual robot arm. Please help and thank you.

0 Likes

Anonymous
Not applicable

I just wanted to ask, if you run the script, where do the component angles go. Does it go to a file or a variable. I am also trying to control a robot arm, and when I copied and pasted the script, nothing happens when I run it. All I need are the angles on my assembled component in order to control my robot arm. I hope you can help me, thank you.

0 Likes

JeromeBriot
Mentor
Mentor

Hello,

 

The angles are written in the Python console of Spyder.

 

You can replace the print statement with a call to ui.messageBox() like this:

 

import adsk.core, adsk.fusion, traceback
import math

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface

        product = app.activeProduct

        design = adsk.fusion.Design.cast(product)

        for j in design.rootComponent.joints:

            if j.jointMotion.jointType == adsk.fusion.JointTypes.RevoluteJointType:

                ui.messageBox('Revolution: {:.3f}rad {:.3f}°'.format(j.jointMotion.rotationValue, math.degrees(j.jointMotion.rotationValue)))

            elif  j.jointMotion.jointType == adsk.fusion.JointTypes.SliderJointType:

                ui.messageBox('Slide: {:.3f}cm'.format(j.jointMotion.slideValue))

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

You must write the code that commands the robot with these values.

 

0 Likes

Anonymous
Not applicable

Hi,

Thank you so much for the reply. Unfortunately, still does not work. It seems to do with the "for statement" since if I put print('hello') inside of the block, it does not print anything in console, outside of the block everything seems to be ok. Is there a change in syntax maybe a new version of python? Do I need to do something to my model maybe for this to work? BY the way is J just an arbitrary variable, or should it be the same index name as my joints?

 

By the way all I want to get are the rotational values shown on the joint rotation when I rotate or move the component.

 

Attached is the image of spyder python. Just in case I am doing something really wrong.python editing.jpg

 

0 Likes

Anonymous
Not applicable

Hi,

I finally figured it out, still using the code you posted, but with a little change.

 

Instead of using .joints use .asBuiltJoints instead, since that is how i jointed my model.

 

Thank you so much for sharing. This is another step to pushing Fusion 360 to the limits of human imagination.

 

Now, to figure out how to send the angles to serial port and control my bot. 

 

Once again thank you so much.

0 Likes