Appearance Bug??

Appearance Bug??

brad.bylls
Collaborator Collaborator
735 Views
6 Replies
Message 1 of 7

Appearance Bug??

brad.bylls
Collaborator
Collaborator

I have some code from an add-in I'm working on that worked several months ago.

    # Set the spring color
    fusionMaterials = _app.materialLibraries.itemByName('Fusion 360 Appearance Library')
    appear = fusionMaterials.appearances.itemByName('Powder Coat (Blue)')
    if strColor == 'Blue':
        blueColor = design.appearances.addByCopy(appear'BlueColor')  <<< Line 290
        colorProp = adsk.core.ColorProperty.cast(blueColor.appearanceProperties.itemByName('Color'))
        colorProp.value = adsk.core.Color.create(002550)
        bd.appearance = blueColor
    elif strColor == 'Red':  
        redColor = design.appearances.addByCopy(appear'RedColor')
        colorProp = adsk.core.ColorProperty.cast(redColor.appearanceProperties.itemByName('Color'))
        colorProp.value = adsk.core.Color.create(255000)
        bd.appearance = redColor
    elif strColor == 'Gold':
        goldColor = design.appearances.addByCopy(appear'GoldColor')
        colorProp = adsk.core.ColorProperty.cast(goldColor.appearanceProperties.itemByName('Color'))
        colorProp.value = adsk.core.Color.create(20420400)
        bd.appearance = goldColor
    else:
        greenColor = design.appearances.addByCopy(appear'GreenColor')
        colorProp = adsk.core.ColorProperty.cast(greenColor.appearanceProperties.itemByName('Color'))
        colorProp.value = adsk.core.Color.create(015300)
        bd.appearance = greenColor
 

I am now revising the code and I get this error message:

error.png

Has something changed in the API or is it my code?

Thanks in advance for any help.

Brad Bylls
0 Likes
Accepted solutions (2)
736 Views
6 Replies
Replies (6)
Message 2 of 7

kandennti
Mentor
Mentor
Accepted solution

Hi @brad.bylls .

 

Isn't there already an appearance with the same name ('BlueColor') in design.apppearances?

Message 3 of 7

brad.bylls
Collaborator
Collaborator

kandennti,

 

I only know of this:

     fusionMaterials.appearances.itemByName('Powder Coat (Blue)')

I will change the name to BluColor and see what happens.

Thanks.

 
Brad Bylls
0 Likes
Message 4 of 7

brad.bylls
Collaborator
Collaborator
Accepted solution

Thanks kandennti.

That worked.

Just strange that it worked before and not now.

Brad Bylls
0 Likes
Message 5 of 7

brad.bylls
Collaborator
Collaborator

Okay.

I changed the names of the colors.

 
    # Set the spring color
    fusionMaterials = _app.materialLibraries.itemByName('Fusion 360 Appearance Library')
    appear = fusionMaterials.appearances.itemByName('Powder Coat (Blue)')
    if strColr == 'Blue':
        blueColr = design.appearances.addByCopy(appear'BlueColr')
        colorProp = adsk.core.ColorProperty.cast(blueColr.appearanceProperties.itemByName('Color'))
        colorProp.value = adsk.core.Color.create(002550)
        bd.appearance = blueColr
    elif strColr == 'Red':  
        redColr = design.appearances.addByCopy(appear'RedColr')
        colorProp = adsk.core.ColorProperty.cast(redColr.appearanceProperties.itemByName('Color'))
        colorProp.value = adsk.core.Color.create(255000)
        bd.appearance = redColr
    elif strColr == 'Gold':
        goldColr = design.appearances.addByCopy(appear'GoldColr')
        colorProp = adsk.core.ColorProperty.cast(goldColr.appearanceProperties.itemByName('Color'))
        colorProp.value = adsk.core.Color.create(20420400)
        bd.appearance = goldColr
    else:
        greenColr = design.appearances.addByCopy(appear'GreenColr')
        colorProp = adsk.core.ColorProperty.cast(greenColr.appearanceProperties.itemByName('Color'))
        colorProp.value = adsk.core.Color.create(015300)
        bd.appearance = greenColr
 

But then I found out that if I run the add-in script a second time, I get the same message.

I think what I need to do is delete that color at the end of the script so if it runs again I won't get the message.

Do you know how to delete a color?

Thank you.

Brad Bylls
0 Likes
Message 6 of 7

BrianEkins
Mentor
Mentor

I did some testing a while ago and found some problems with appearances.  Autodesk is aware of the problems.  So, it may not be your code but a bug you've run into.

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

brad.bylls
Collaborator
Collaborator

Thanks Brian.

Just did some if . . . else to get around the problem.

Brad Bylls
0 Likes