Legacy Appearance Library is the only one that works but I can't get it

Legacy Appearance Library is the only one that works but I can't get it

sophiadoan
Contributor Contributor
465 Views
2 Replies
Message 1 of 3

Legacy Appearance Library is the only one that works but I can't get it

sophiadoan
Contributor
Contributor
From help in this forum, the process of working with appearance is:
- Copy an appearance from a material library to the design
- Making changes (color, texture etc.) to the copied version
- Apply the copied version to a body or face.
 
I tried to manually (not programmatically) copy "Hardwood" from "Legacy Appearance Library"
and then programmatically changeTextureImage with a JPEG image, this works.
sophiadoan_0-1667664893880.png

 

If the same is done with "Mahogany" from "Fusion 360 Appearance Library", it does not work (manually or programmatically).
It failed at getting texture (value None returned):
prop = copiedMahogany.appearanceProperties.itemByName('Image')
            image = adsk.core.AppearanceTextureProperty.cast(prop) #OK
            texture = adsk.core.AppearanceTexture.cast(image.value) #return None

sophiadoan_2-1667664987302.png

So I tried to programmatically getting "Hardwood" from  "Legacy Appearance Library", it won't let me do it.

matLib = app.materialLibraries.itemByName("Legacy Appearance Library")
matLib value is None
but matLib = app.materialLibraries.itemByName("Fusion 360 Appearance Library")
return ok, 
I then programmatically copy an item "Mahogany" from "Fusion 360 Appearance Library" to design and changeTextureImage to a JPEG image , texture as shown above return None.
I am stuck. I hope this is not Fusion bug. Please help cause I would be funny to ask user to manually create an appearance from the "Legacy Appearance Library".
 
0 Likes
466 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor

Hi @sophiadoan .

 

I created a script like this and tried it out.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core

CLANE_MATERIAL_NAME = 'test'
IMAGE_PATH = r'C:\temp\1.png'

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

        # remove test appearance
        appearance_temp: adsk.core.Material = des.appearances.itemByName(CLANE_MATERIAL_NAME)
        if appearance_temp:
            appearance_temp.deleteMe()

        # Fusion 360 Appearance Library - BA5EE55E-9982-449B-9D66-9F036540E140
        matLib: adsk.core.MaterialLibrary = app.materialLibraries.itemById('BA5EE55E-9982-449B-9D66-9F036540E140')

        # Mahogany - Prism-140
        appearance_Prism_140: adsk.core.Appearance = matLib.appearances.itemById('Prism-140')
        dump_appearance_image_path('Prism_140', appearance_Prism_140)

        # clone appearance
        appearance_Clone: adsk.core.Appearance = des.appearances.addByCopy(appearance_Prism_140, CLANE_MATERIAL_NAME)
        dump_appearance_image_path('Exec Clone', appearance_Clone)

        # chenge Image path
        appearanceTextureProp: adsk.core.AppearanceTextureProperty = appearance_Clone.appearanceProperties.itemById('surface_normal')
        appearanceTexture: adsk.core.AppearanceTexture = appearanceTextureProp.value
        fileNameProp: adsk.core.FilenameProperty = appearanceTexture.properties.itemById('bumpmap_Bitmap')
        fileNameProp.value = IMAGE_PATH
        
        dump_appearance_image_path('Change Image', appearance_Clone)

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


def dump_appearance_image_path(msg: str, appearance: adsk.core.Appearance):
    appearanceTextureProp: adsk.core.AppearanceTextureProperty = appearance.appearanceProperties.itemById('surface_normal')
    appearanceTexture: adsk.core.AppearanceTexture = appearanceTextureProp.value
    fileNameProp: adsk.core.FilenameProperty = appearanceTexture.properties.itemById('bumpmap_Bitmap')

    dump(f'{msg} : {fileNameProp.value}')

def dump(s):
    adsk.core.Application.get().log(f'{s}')
    print(s)

 

My script may be wrong, but as a result I could not replace the image.

 

I think the way to get the path of the appearance image file is the dump_appearance_image_path function, am I wrong?

def dump_appearance_image_path(msg: str, appearance: adsk.core.Appearance):
    appearanceTextureProp: adsk.core.AppearanceTextureProperty = appearance.appearanceProperties.itemById('surface_normal')
    appearanceTexture: adsk.core.AppearanceTexture = appearanceTextureProp.value
    fileNameProp: adsk.core.FilenameProperty = appearanceTexture.properties.itemById('bumpmap_Bitmap')

    dump(f'{msg} : {fileNameProp.value}')

 

When I looked at the output, it is different from the Mahogany image path cloned in the GUI, so I was not sure what was correct.(Ver 2.0.14793)

1.png

0 Likes
Message 3 of 3

sophiadoan
Contributor
Contributor

@kandennti 

 

I think your code looks correct. I am more sure that it is Fusion bug that you cannot change the image if not using the Legacy Material. Even if you use Legacy Material, you have to manually create one to the Favorite category before you can programmatically change the material. I hope Fusion knows about this bug.