Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Inventor api, Appearances and non-updated Preview pic

6 REPLIES 6
Reply
Message 1 of 7
info
783 Views, 6 Replies

Inventor api, Appearances and non-updated Preview pic

Hi all,

When creating generic appearance from sample code:

Public Sub CreateSimpleColorAppearance()
    Dim doc As Document
    Set doc = ThisApplication.ActiveDocument
    
    ' Only document appearances can be edited, so that's what's created.
    ' This assumes a part or assembly document is active.
    Dim docAssets As Assets
    Set docAssets = doc.Assets
    
    ' Create a new appearance asset.
    Dim appearance As Asset
    Set appearance = docAssets.Add(kAssetTypeAppearance, "Generic", _
                                    "MyShinyRed", "My Shiny Red Color")
    
    Dim tobjs As TransientObjects
    Set tobjs = ThisApplication.TransientObjects


    Dim color As ColorAssetValue
    Set color = appearance.Item("generic_diffuse")
    color.value = tobjs.CreateColor(255, 15, 15)
    
    Dim floatValue As FloatAssetValue
    Set floatValue = appearance.Item("generic_reflectivity_at_0deg")
    floatValue.value = 0.5
    
    Set floatValue = appearance.Item("generic_reflectivity_at_90deg")
    floatValue.value = 0.5
End Sub

The appearance preview pic in Appearance Browser seems to be ok.

 

If I make e.g. Plastic Material based on code as followes:

Public Sub CreateSimpleColorAppearance_plastic()
Dim doc As Document
Set doc = ThisApplication.ActiveDocument

' Only document appearances can be edited, so that's what's created.
' This assumes a part or assembly document is active.
Dim docAssets As Assets
Set docAssets = doc.Assets

' Create a new appearance asset.
Dim appearance As Asset
Set appearance = docAssets.Add(kAssetTypeAppearance, "Plastic", _
"MyShinyRed_Plastic", "My Shiny Red Color_Plastic")

Dim tobjs As TransientObjects
Set tobjs = ThisApplication.TransientObjects


Dim color As ColorAssetValue
Set color = appearance.Item("plasticvinyl_color")
color.value = tobjs.CreateColor(255, 15, 15)

End Sub

 

Now the preview pic is about the white, but if start the editor for the appearance preview pic will update ok. Strange.

It seems that other appearance types do not update the preview pic correctly.

Does anyone managed to have correctly created preview pics when creating appearances through API?

/matti

Appearance Browser Pic:

 

Appearance_Browser.png

Appearance Editor Pic

Appearance_Editor.png

 

 

6 REPLIES 6
Message 2 of 7
ggrier
in reply to: info

I see there has been no reply to this post but I have been trying to run this same sample program on Inventor 2018 and the program makes it to the "Set appearance =docAssets.Add(kAssetTypeAppearance….   line before it kicks out a "Run-time error '5': Invalid procedure call or argument message. 

 

I have tried changing the syntax and other fixes and have searched for a solution but to no avail.

 

It seems to have something to do with the Set command and many of the other sample problems in the API Reference manual seem to have a similar problem.

 

Is there any way to get around this and make this program work?

Also can an illogic version of this program be made. What would it look like?

Message 3 of 7
c_hoppen
in reply to: info

I just stumbled upon the same problem in Inventor 2023. Still no solution? All Appearences created by code look the same, although they have different colors:

choppen_0-1672408471697.png

choppen_1-1672408655079.png

Addition: 2023.2 Build 271

Message 4 of 7
A.Acheson
in reply to: c_hoppen

This is a bug. The thumbnail is not updated until you manually go into the appearance and hit the Apply Button.

Maybe @chandra.shekar.g or @MjDeck  might Kindly look into this. 

Before:

AAcheson_0-1672445860881.png

Make Any Change such as changing the Scene or switching a toggle and hit apply.  

AAcheson_2-1672446028232.png

 

After:

AAcheson_3-1672446074372.png

Dim doc As Document = ThisApplication.ActiveDocument

' Only document appearances can be edited, so that's what's created.
' This assumes a part or assembly document is active.
Dim docAssets As Assets = doc.Assets

' Create a new appearance asset.
Dim appearance As Asset = docAssets.Add(AssetTypeEnum.kAssetTypeAppearance, "Plastic", _
"MyShinyRed_Plastic1", "My Shiny Red Color_Plastic1")

Dim tobjs As TransientObjects = ThisApplication.TransientObjects


Dim color As ColorAssetValue = appearance.Item("plasticvinyl_color")
color.Value = tobjs.CreateColor(255, 15, 15)
If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 7
c_hoppen
in reply to: A.Acheson


@A.Acheson  schrieb:

This is a bug. The thumbnail is not updated until you manually go into the appearance and hit the Apply Button.


Yes, I have observed that behavior as well. But I don't want to manually edit >200 appearances one by one. 

This bug has been around for years and Autodesk doesn't seem to care.

Regards

Christoph

Message 6 of 7
MjDeck
in reply to: info

@c_hoppen and @A.Acheson , thanks for the reminder. Sorry about our delay in looking at it. This is internal issue INVGEN-66589. I think we can fix it soon.


Mike Deck
Software Developer
Autodesk, Inc.

Message 7 of 7
cencinaNB2ET
in reply to: MjDeck

Hello,

Is there a workaround in order to get the updated thumbnail showing the colour?

I just created 100+ appearances yesterday and would like the user to at least preview the colours.

Perhaps programmatically edit the asset?

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report