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

apply color combinations and export picture

Andy_rapid-ood
Participant

apply color combinations and export picture

Andy_rapid-ood
Participant
Participant

Hello,

 

I am sure that I found something similar in the past here, but I cannot find it anymore.

What I want to do is apply all possible color combinations from one appearance folder to a two body model and export each and every variant.

Assuming that I have an appearance folder with 5 colors, I'd like to have 5x5=25 pictures of the two body model with all related color combinations.

I am hoping that someone has some script fragments that can be utilized for my purpose

 

regards,

Andy

 

0 Likes
Reply
270 Views
2 Replies
Replies (2)

kandennti
Mentor
Mentor

Hi @Andy_rapid-ood .

 

We have created a sample that creates images of duplicate combinations of five randomly selected appearances.

With two bodies created in the root component, run the following script

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core
import random
import itertools
import pathlib

EXPORT_DIR = pathlib.Path(r'C:\temp')

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

        body1: adsk.fusion.BRepBody = root.bRepBodies[0]
        body2: adsk.fusion.BRepBody = root.bRepBodies[1]

        vp: adsk.core.Viewport = app.activeViewport

        appearances = getUniqueAppearances()
        appearances_combination = list(itertools.combinations_with_replacement(appearances, 2))
        for idx, apps in enumerate(appearances_combination):
            body1.appearance = apps[0]
            body2.appearance = apps[1]

            path = EXPORT_DIR / f'{idx}'
            vp.saveAsImageFile(str(path), 0, 0)

        ui.messageBox('Done')

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

def getUniqueAppearances() -> list:
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        appearances: adsk.core.Appearances = app.materialLibraries.itemById(
            'BA5EE55E-9982-449B-9D66-9F036540E140').appearances
        appearanceLst = [a for a in appearances]

        return random.sample(appearanceLst, 5)
    except:
        return []

1.png
I could not find a way to get the appearance folders in the API.

1 Like

BrianEkins
Mentor
Mentor

What is an "appearance folder"?

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes