Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Set the "Physical Material" using a Python script

isocam
Collaborator

Set the "Physical Material" using a Python script

isocam
Collaborator
Collaborator

Can anybody help?

 

Is it possible to set the "Physical Material", of a part, using a Python script?

 

For example,

 

Say I have a simple part already open, can I set the "Physical Material" to Aluminium 7075 or any other material?

 

Many thanks in advance

 

Darren

0 Likes
Reply
230 Views
1 Reply
Reply (1)

BrianEkins
Mentor
Mentor

Here's a small example.

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        design: adsk.fusion.Design = app.activeProduct

        # Get the material.
        lib = app.materialLibraries.itemByName('Fusion 360 Material Library')
        aluminum = lib.materials.itemByName('Aluminum 7075')

        # Get a component. In this case, using the name.
        comp = design.allComponents.itemByName('Component1')

        # Check if the component is local or linked. Only local components can be edited.
        if comp.parentDesign == design:
            # Set the material.
            comp.material = aluminum
        else:
            ui.messageBox('Cannot set material on linked component.')
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
1 Like