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: 

Download an appearance programmatically

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
brad.bylls
175 Views, 5 Replies

Download an appearance programmatically

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

Brad Bylls
5 REPLIES 5
Message 2 of 6
BrianEkins
in reply to: brad.bylls

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
Message 3 of 6
brad.bylls
in reply to: BrianEkins

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
Message 4 of 6
BrianEkins
in reply to: brad.bylls

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
Message 5 of 6
JeromeBriot
in reply to: brad.bylls

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
in reply to: JeromeBriot

Thanks Jerome.

Thant worked out great.

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

 

Brad Bylls

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