Hello,
if you just want to play with appearance of a body for visual purposes you can just use the:
bRepBody_var.appearance = propertyValue
The tricky thing is how to obtain the appearance you want to to assign to the body. For that you need to load it from appropriate library, if it exists. If it doesn't you will have to copy existing appearance and set its properties to your liking.
This is a sample code that first checks if the desired appearance already exists in one of the libraries and if not, creates new one by copying an existing appearance and editing it.
import adsk.core, adsk.fusion, adsk.cam, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = app.activeProduct
if not design:
ui.messageBox('No active Fusion 360 design', 'No Design')
return
# get the body
ui.messageBox("Select a body you want to change", "Body selection")
body = adsk.fusion.BRepBody.cast(ui.selectEntity('Select a body', 'Bodies').entity)
# body appearance
BodyA = body.appearance;
ui.messageBox(BodyA.name, "Body Appearance")
# Check to see if the "MyColor1" exists in the local appearances
try:
myColor = design.appearances.itemByName('MyColor1')
except:
myColor = None
if myColor:
body.appearance = myColor
else:
# Get the existing appearance.
AppearanceLibrary = app.materialLibraries.itemByName('Fusion Appearance Library')
yellowColor = AppearanceLibrary.appearances.itemByName('Paint - Enamel Glossy (Yellow)')
# Copy yellow color to the design, giving it a new name.
newColor = design.appearances.addByCopy(yellowColor, 'MyColor1')
# Change the color property of the appearance to what you want.
colorProperty = adsk.core.ColorProperty.cast(newColor.appearanceProperties.itemByName('Color'))
colorProperty.value = adsk.core.Color.create(0, 204, 0, 0)
# Assign it to the body.
body.appearance = newColor
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
hope this helps