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: 

Appearance Bug??

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
brad.bylls
238 Views, 6 Replies

Appearance Bug??

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
6 REPLIES 6
Message 2 of 7
kandennti
in reply to: brad.bylls

Hi @brad.bylls .

 

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

Message 3 of 7
brad.bylls
in reply to: kandennti

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

Thanks kandennti.

That worked.

Just strange that it worked before and not now.

Brad Bylls
Message 5 of 7
brad.bylls
in reply to: kandennti

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

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

Thanks Brian.

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

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