Show "Properties" Dialog Box For Parts & Assemblies

Show "Properties" Dialog Box For Parts & Assemblies

isocam
Collaborator Collaborator
300 Views
1 Reply
Message 1 of 2

Show "Properties" Dialog Box For Parts & Assemblies

isocam
Collaborator
Collaborator

Can anybody help?

 

I have the following Fusion 360 "Python" script file....


import adsk.core, adsk.fusion, traceback

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

ui = app.userInterface

des = app.activeProduct

root = des.rootComponent

sels = ui.activeSelections

sels.add(root.bRepBodies[0])

app.executeTextCommand(u'Commands.Start FusionPropertiesCommand')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

It works great when I run the script on a "Part" document but not on a "Assembly" document.

 

Can anybody update the script for me so that it works on both "Part" & "Assembly" documents?

 

Many thanks in advance!

 

Darren

0 Likes
301 Views
1 Reply
Reply (1)
Message 2 of 2

Rushikesh.kadam
Autodesk
Autodesk

@isocam you need to use the component instance under which the body is present. Attached is the modified code. I have assumed the body is present under the first instance of the component. One needs to make sure that the component and body exist before accessing them.

 

#Author-
#Description-

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        des = app.activeProduct
        root = des.rootComponent
        sels = ui.activeSelections
        
        # here use the component instance under which the body is present
        #  for which the properties dialog needs to display.
        sels.add(root.allOccurrences[0].bRepBodies[0])

        app.executeTextCommand(u'Commands.Start FusionPropertiesCommand')
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

  

 ---------------------------------------------------------------------------------------------------------------------------

If my reply was helpful, please click the "Accept as Solution" button. It helps others get the answer quickly! A "Like" is always welcomed

 




Rushikesh Kadam
Senior QA Engineer
Quality Assurance
Autodesk, Inc.


0 Likes