Get the value of a joint selected

Get the value of a joint selected

JHRendon
Advocate Advocate
701 Views
2 Replies
Message 1 of 3

Get the value of a joint selected

JHRendon
Advocate
Advocate

Hi! How can i get the value of a joint that i selected? 

 

I want to select a revolute joint and then appear a message box with the value of that revolute joint.

 

 

0 Likes
Accepted solutions (1)
702 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor
Accepted solution

Hi JHRendon.

 

try it.
#Fusion360API Python script
#Author-kantoku
#Description-RevoluteJointType GetAngleValue test

import adsk.core, adsk.fusion, traceback

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

        msg :str = 'Select a Revolute Joint'
        selFiltter :str = 'Joints'
        sel :adsk.core.Selection = SelectEnt(ui, msg ,selFiltter)
        if sel is None:
            return

        jnt :adsk.fusion.Joint = sel.entity
        ang :adsk.fusion.ModelParameter = jnt.angle
        msg = 'jointName : {}\nexpression : {}\nvalue : {} rad'.format(
            jnt.name, ang.expression, ang.value)
            
        ui.messageBox(msg)

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

def SelectEnt(
        ui :adsk.core.UserInterface,
        msg :str, 
        filtter_str :str) -> adsk.core.Selection :
    while True:
        try:
            selection = ui.selectEntity(msg, filtter_str)
            jointType = selection.entity.jointMotion.jointType
            if jointType is adsk.fusion.JointTypes.RevoluteJointType:
                return selection
            ui.messageBox('Please select a Revolute Joint Type')
        except:
            return None
About units
 'expression' property → degree(string)
 'value' property → radian(float)
Message 3 of 3

JHRendon
Advocate
Advocate

You're great! 😄 

0 Likes