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: 

How to select a rigid group?

2 REPLIES 2
Reply
Message 1 of 3
ricardoxcm
402 Views, 2 Replies

How to select a rigid group?

Hello!

 

I've been working on a short script to select a rigid group and print its name. However, I've only been able to select a component and print its name so far. Is it possible to determine to which rigid group a component belongs to and print the rigid group's name? Or is there a more direct way to do it?

Thanks a lot for the help,

 

Ricardo

import adsk.core, adsk.fusion, traceback
app = adsk.core.Application.cast(None)
ui = adsk.core.UserInterface.cast(None)
def run(context):
    try:
        global app, ui
        app = adsk.core.Application.get()
        ui = app.userInterface
    
    
# Select a Body.
        ui.messageBox("Please select the root link.")
        rootSel = ui.selectEntity('Select root', 'Bodies')
        if rootSel:
            root = adsk.fusion.BRepBody.cast(rootSel.entity)
            toprint = root.parentComponent.name
            print('Selected body :', toprint)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
2 REPLIES 2
Message 2 of 3
ekinsb
in reply to: ricardoxcm

Rigid groups are only selectable in the user-interface from within the browser.  However, you can select other types of entities, like you were trying to do, and then get any associated rigid groups from them.  Rigid groups are applied to occurrences to it's easiest to get them from them and they are selectable in the graphics window.  I modified your code to do this.

 

import adsk.core, adsk.fusion, traceback

app = adsk.core.Application.cast(None)
ui = adsk.core.UserInterface.cast(None)

def run(context):
    try:
        global app, ui
        app = adsk.core.Application.get()
        ui = app.userInterface
           
           # Select an occurrence.
        occSel = ui.selectEntity('Select occurrence', 'Occurrences')
        if occSel:
            occ = adsk.fusion.Occurrence.cast(occSel.entity)
            
            result = ''
            for rigidGroup in occ.rigidGroups:
                result += '\n    ' + rigidGroup.name
                    
            if result == '':
                ui.messageBox('No rigid groups for the selected occurrence.')
            else:
                ui.messageBox('The rigid groups below are on the selected occurrence:' + result)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 3
ricardoxcm
in reply to: ekinsb

Thanks a lot for the quick reply! It worked perfectly.

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