Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Occurrence Appearance batch render fails

3 REPLIES 3
Reply
Message 1 of 4
gvisca44
167 Views, 3 Replies

Occurrence Appearance batch render fails

No sure whether this is the correct part of the forum for this post, but because its API based - I'll start here and see where we land.

 

I've written a script that will read a CSV file containing components and their desired appearances, and then applies those appearances to the current design model.

 

An example of the CSV would be as follows:

Comp1, Powder Coat (Red)
Comp2, Powder Coat (Black)

 

I should point out that in my script I have intentionally elected to have the appearances applied to the component occurrence, rather than the component object. I made this choice because I use a reasonable number of components in multiple designs - so I was trying to make any color choices strictly local to the current design.

 

It turns out that where components are linked into the current design, and are being used in other designs too, applying an appearance to the component occurrence is not honoured when submitting the job for batch rendering (either local or coud).  However, in-canvas rendering is successful.

 

The result is the same when local or clould rendering is used - so it seems to me that the process of packaging up the rendering job doesn't capture the occurrence's appearance - or the appearance gets lost / removed from the occurrence (and I say this without having any concept of the background rendering preparation process).

 

I'm not sure whether this is the intended outcome or not.

 

Any advice ?

 

def processAppearanceFile(filename):
    occs = []
    root = design.rootComponent
    occs = root.allOccurrences

    # Open the appearances file 
    with open(filename) as f:

        reader = csv.reader(f)
            
        #for line in f:
        for line in reader:

            componentName = line[0]

            if componentName[0] == '#':
                continue                        # if component name in file is commented - ignore and move to next line.

            if line[1] == 'None':
                componentAppearance = None      # if the specified appearance is None - this sets up to remove any appearances from the Occurrence.
            else:
                componentAppearance: adsk.core.Appearance = getAppearance(line[1])

                if not componentAppearance:     # if we dont get an appearances from the CSV file - message and exit.
                    msg = f'Cancelled - "Appearance" in CSV file cannot be obtained: \n Component: \n \t{line[0]} \n Appearance: \n \t{line[1]} \n Script terminating' 
                    ui.messageBox(msg, CMD_NAME)
                    return
                
            for occ in occs:
                occComponentName = futil.filterFusionCompNameInserts(occ.component.name)
                msg = f'Examining Occ Name: "{occ.name}" \t Occ Component Name: "{occComponentName}" '
                futil.log(msg)

                if occComponentName == componentName:
                    msg = f'Match with model.  \t Input: "{componentName}" \t Model: "{occComponentName}" '
                    futil.log(msg)

                    if componentAppearance:
                        occ.appearance = componentAppearance
                        msg = f'Appearance "{componentAppearance.name}" from: "{componentAppearance.parent}" applied to "{occ.name}" ' 
                        futil.log(msg)

                        physProps = occ.physicalProperties
                        msg = f'Area is: {physProps.area} '
                        futil.log(msg)
                    else:
                        occ.appearance = componentAppearance
                        msg = f'Appearance removed from "{occ.name}"' 
                        futil.log(msg)

 

3 REPLIES 3
Message 2 of 4
gvisca44
in reply to: gvisca44
Message 3 of 4
BrianEkins
in reply to: gvisca44

Does this only happen when you assign the appearance using the API? Is it OK if you do it interactively through the UI?

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 4 of 4
gvisca44
in reply to: BrianEkins

Hi @BrianEkins , 

 

Yes - this only occurs when using the API. There are other errors (?) I discovered when I used a more methodical approach too - which are documented in the bug report.

 

G

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report