Inventor api, Appearances and non-updated Preview pic

Anonymous

Inventor api, Appearances and non-updated Preview pic

Anonymous
Not applicable

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:

 

undefined

Appearance Editor Pic

undefined

 

 

0 Likes
Reply
898 Views
6 Replies
Replies (6)

Anonymous
Not applicable

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?

0 Likes

c_hoppen
Advocate
Advocate

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

0 Likes

A.Acheson
Mentor
Mentor

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
0 Likes

c_hoppen
Advocate
Advocate

@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

0 Likes

MjDeck
Autodesk
Autodesk

@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.

cencinaNB2ET
Advocate
Advocate

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?

 

0 Likes

Type a product name