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: 

Reading / Recording Component Data

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Anonymous
389 Views, 7 Replies

Reading / Recording Component Data

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.

7 REPLIES 7
Message 2 of 8
JeromeBriot
in reply to: Anonymous

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.

 

Message 3 of 8
Anonymous
in reply to: JeromeBriot

This was exactly what I needed! Thank you!

Message 4 of 8
3dprintwiz
in reply to: JeromeBriot

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.

Message 5 of 8
3dprintwiz
in reply to: Anonymous

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.

Message 6 of 8
JeromeBriot
in reply to: 3dprintwiz

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.

 

Message 7 of 8
3dprintwiz
in reply to: JeromeBriot

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

 

Message 8 of 8
3dprintwiz
in reply to: JeromeBriot

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.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report