@isocam I assume you want to apply color to all the bodies. If yes, you need to loop using bRepBodies. Refer to the below code. The code will apply color to all the bodies under the root component only. You need to do a similar loop if the bodies are under the component.
If want to apply to the specific body under the root component then uncomment line 27 and replace the number with the correct body number, and comment the for loop.
import adsk.core, adsk.fusion, adsk.cam, traceback
def run(context):
ui = None
try:
PartColour = "Bright Reduuu"
Red = 255
Green = 0
Blue = 0
SetPartColour(PartColour, Red, Green, Blue)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def SetPartColour(PartColour, Red, Green, Blue):
app = adsk.core.Application.get()
ui = app.userInterface
design = adsk.fusion.Design.cast(app.activeProduct)
# if you want to select specific body replace the number.
# design.rootComponent.bRepBodies.item(0)
# using for loop to apply color to all body present under root component.
for body in design.rootComponent.bRepBodies:
favoriteAppearances = design.appearances
try:
myColor = favoriteAppearances.itemByName(PartColour)
except:
myColor = None
if myColor:
body.appearance = myColor
else:
fusionMaterials = app.materialLibraries.itemByName('Fusion 360 Appearance Library')
yellowColor = fusionMaterials.appearances.itemByName('Paint - Enamel Glossy (Yellow)')
newColor = design.appearances.addByCopy(yellowColor, PartColour)
colorProp = adsk.core.ColorProperty.cast(newColor.appearanceProperties.itemByName('Color'))
colorProp.value = adsk.core.Color.create(Red, Green, Blue, 0)
body.appearance = newColor
------------------------------------------------------------------------------------------------------------------------------
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.