How to get material of product on Fusion360?

How to get material of product on Fusion360?

ruban2
Participant Participant
347 Views
2 Replies
Message 1 of 3

How to get material of product on Fusion360?

ruban2
Participant
Participant

Hello Everyone.

I am trying to get material of product on Fusion360.

what is api script for it?

0 Likes
348 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor

Hi @ruban2 .

 

"Product" was interpreted to mean occurrence or component.

 

The material name can be obtained in the following way

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion

def run(context):
    ui = core.UserInterface.cast(None)
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface
        des: fusion.Design = app.activeProduct
        root: fusion.Component = des.rootComponent

        for occ in root.allOccurrences:
            app.log(f'{occ.name} --> {occ.component.material.name}')

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

 

However, if there are several bodies with different materials in one component, you will not get the correct result.
If you want to get the correct result, you need to refer to the material property of the body.

Message 3 of 3

ruban2
Participant
Participant

Thank you for your message.

0 Likes