Using custom appearance libraries in add-ins

Using custom appearance libraries in add-ins

nnikbin
Collaborator Collaborator
1,000 Views
4 Replies
Message 1 of 5

Using custom appearance libraries in add-ins

nnikbin
Collaborator
Collaborator

Hi Everyone,

 

My add-in (Fracture) has a custom appearance library. In current version of the add-in the appearance library is placed in resources folder under the add-in folder. To use this library, users should first open it in material browser which is a difficult task, because the path of the add-in's resources folder is too long. Regarding this issue, I have 2 questions:

 

  1. Is there any method for opening an appearance library by code (to add it to MaterialLibraries object) ?
  2. Are add-in packages able to install an appearance library beside Autodesk libraries?

Thanks,

Navid

 

Fracture.png

0 Likes
Accepted solutions (1)
1,001 Views
4 Replies
Replies (4)
Message 2 of 5

ekinsb
Alumni
Alumni

Unfortunately, this is an oversight in the API and there isn't any support for custom libraries.  This is the first time this has come up, so we hadn't noticed it before. Thanks for pointing it out.  I've added it to our backlog. 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 5

nnikbin
Collaborator
Collaborator

Hi Brian,

 

Many thanks for your prompt response.

0 Likes
Message 4 of 5

ekinsb
Alumni
Alumni
Accepted solution

This has been resolved a couple of updates ago.  Here's some code that I used to test the new functionality:

 

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        des = adsk.fusion.Design.cast(app.activeProduct)
        
        # Get the library.
        lib = app.materialLibraries.itemByName('BrianTest')
        if not lib:
            # Load it, since it isn't loaded.
            lib = app.materialLibraries.load('C:\Temp\BrianTest.adsklib')

        # Get the appearance named "Red"
        red = lib.appearances.itemByName('Red')
        
        # Copy the appearance into the active design so it can be used.
        des.appearances.addByCopy(red, red.name)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 5 of 5

nnikbin
Collaborator
Collaborator

Hi @ekinsb

Many thanks for providing sample code

0 Likes