Download an appearance programmatically

Download an appearance programmatically

brad.bylls
Collaborator Collaborator
699 Views
5 Replies
Message 1 of 6

Download an appearance programmatically

brad.bylls
Collaborator
Collaborator

Can you download an appearance to use as a sample to copy and make your own color with the API programmatically?

Brad Bylls
0 Likes
Accepted solutions (1)
700 Views
5 Replies
Replies (5)
Message 2 of 6

BrianEkins
Mentor
Mentor

Take a look at this blog post.  I think it might answer your question.

https://ekinssolutions.com/setting-colors-in-fusion-360/

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

brad.bylls
Collaborator
Collaborator

Brian,

Thanks for the reply.

I used your code sample originally when writing my code.

I didn't use 'Paint - Enamel Glossy (Yellow)'

Instead I used 'Powder Coat (Blue)', I didn't want glossy.

It worked fine for me.

However, when I sent my add-in to the app store for publication, their test said it was a bad name.

I did some testing and found that only downloaded appearances would work.

Not knowing what the end user may have downloaded, I want to know if it is possible to download programmatically.

This is my original code taken from your sample.

	plateTCPext.name = 'Plate TCP'
	plateTCPbody = plateTCPext.faces[0].body
	plateTCPbody.name = 'Plate TCP'
	fusionMaterials = _app.materialLibraries.itemByName('Fusion 360 Appearance Library')
	appear = fusionMaterials.appearances.itemByName('Powder Coat (Blue)')
	yellowColor = design.appearances.addByCopy(appear, 'YellowColor')
	colorProp = adsk.core.ColorProperty.cast(yellowColor.appearanceProperties.itemByName('Color'))
	colorProp.value = adsk.core.Color.create(204, 204, 0, 0)
	plateTCPbody.appearance = yellowColor

 

Brad Bylls
0 Likes
Message 4 of 6

BrianEkins
Mentor
Mentor

I understand.  Unfortunately, the API doesn't have support for appearances that have not been downloaded.  Ideally, the list of appearances would contain both those that are downloaded and those that are not and have a property that would indicate if it has been downloaded or not and then either provide a way for you to download it or automatically download it if you attempt to use one that has not been downloaded.  In any case, that support is currently not available.

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

JeromeBriot
Mentor
Mentor
Accepted solution

Hello,

 

Create your own materials library. Then save it in a adsklib file that you place in your add-in folder. So the appearance will be available even if the user didn't download it previously.

 

I did this for the IDF import add-in and it works perfectly.

 

To load the appearance from the library:

import adsk.core, adsk.fusion, traceback
import os

def run(context):

    try:

        app = adsk.core.Application.get()
        ui = app.userInterface

        product = app.activeProduct

        lib = app.materialLibraries.itemByName('myLib')

        if not lib:
            
            lib = app.materialLibraries.load(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'myLib.adsklib'))

            appearance = lib.appearances.itemById('Prism-097')
            # appearance = lib.appearances.itemByName('Powder Coat (Blue)')

            product.appearances.addByCopy(appearance, appearance.name)

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

 

That's the idea.

 

Message 6 of 6

brad.bylls
Collaborator
Collaborator

Thanks Jerome.

Thant worked out great.

Loaded F360 on a new computer for testing, so no appearances were downloaded.

 

Brad Bylls
0 Likes