Edit the value of a joint already created.

Edit the value of a joint already created.

JHRendon
Advocate Advocate
1,492 Views
5 Replies
Message 1 of 6

Edit the value of a joint already created.

JHRendon
Advocate
Advocate

Hi! I'm working with a robotic arm that i designed and I want to control it making "inverse kinematics".

So, the point is that i select the joints of the robotic arm and with all the calculations joints move to the position that i want. 

 

The problem is how can I edit this joints. 

 

I know that first i need to select the joints:

 

        ui.messageBox('Select a Joint, please')
        selectedItem1 = ui.selectEntity("Select a Joint""Joints")
        selectedItem1Value = selectedItem1.entity
 
I do not know if this would be the right way to select the joint to modify it, but if it is, how can i modify its value? 
 
 
        angle = adsk.core.ValueInput.createByString('190 deg')
        selectedItem1Value.angle = angle
 
this way it is not working. 😞
 
if someone knows how can i take a joint already created and modify it when i run an add-ins, please tell me 🙂
 
0 Likes
Accepted solutions (2)
1,493 Views
5 Replies
Replies (5)
Message 2 of 6

MichaelT_123
Advisor
Advisor

Hi Mr JHRendon,

 

Perhaps as a starter reading/immersing into respective sample codes available in F360 docs (search <JointMotion Sample>) would be of benefit. The subject could be tricky from time to time so, to avoid drowning I would suggest to have  two hands handy 😉.

 

Regards

MichaelT

 

MichaelT
Message 3 of 6

kandennti
Mentor
Mentor
Accepted solution

Hi JHRendon.

 

[BasicTraining]-[Assemblice]-[GenevaDrive] data was used.
Execute the following script and select [Joints]-[Rev1] to start rotation.

#Fusion360API Python script
#Author-kantoku
#Description-joint angle 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 Joint'
        selFiltter :str = 'Joints'
        sel :adsk.core.Selection = SelectEnt(ui, msg ,selFiltter )
        if sel is None:
            return

        jnt :adsk.fusion.Joint = sel.entity

        for v in range(0,360,10):
            jnt.angle.expression = str(v)
            app.activeViewport.refresh()

        ui.messageBox('Done')

    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 :

    try:
        selection = ui.selectEntity(msg, filtter_str)
        return selection
    except:
        return None

1.png

Message 4 of 6

JHRendon
Advocate
Advocate

Thanks a lot!!! 😄 

0 Likes
Message 5 of 6

kandennti
Mentor
Mentor
Accepted solution

I created a sample but it seems to have been deleted.
It is very disappointing.

#Fusion360API Python script
#Author-kantoku
#Description-joint angle test2

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
        des = adsk.fusion.Design.cast(app.activeProduct)
        root = des.rootComponent

        jnt :adsk.fusion.Joint = root.joints.itemByName('Rev1')
        if not jnt:
            ui.messageBox('Joint not found')
            return
        
        msg = 'Please enter an angle(unit-degree)\n(Cancel-ESC)'
        (iptAngStr, cancelled) = ui.inputBox(msg)
        if cancelled or not isfloat(iptAngStr):
            return

        ang :adsk.fusion.ModelParameter = jnt.angle
        beforeAng = ang.value

        import math
        afterAng = math.radians(float(iptAngStr))

        diff = afterAng - beforeAng

        if abs(diff) < 0.01:
            return
        
        if diff > 0:
            step = 0.1
        else:
            step = -0.1

        for v in floatRange(beforeAng, afterAng, step):
            ang.value = v
            app.activeViewport.refresh()
        ang.value = afterAng
        app.activeViewport.refresh()

        ui.messageBox('Done ( {} )'.format(ang.expression))

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

def floatRange(begin, end, step):
    n = begin
    if step > 0:
        while n + step < end:
            yield n
            n += step
    else:
        while n + step > end:
            yield n
            n += step

def isfloat(string):
    try:
        float(string)
        return True

    except ValueError:
        return False
0 Likes
Message 6 of 6

JHRendon
Advocate
Advocate

THANKS A LOT!! You're amazing! 😄 

0 Likes