Sample to Modify AssetValue

Sample to Modify AssetValue

Maxim-CADman77
Advisor Advisor
207 Views
7 Replies
Message 1 of 8

Sample to Modify AssetValue

Maxim-CADman77
Advisor
Advisor

I'd like to know if it possible to modify AssetValue by means of API.
Is there any sample in API Help?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Accepted solutions (1)
208 Views
7 Replies
Replies (7)
Message 2 of 8

marcin_otręba
Advisor
Advisor

Hi, sample from api (Inventor 2026 Help | Create a simple appearance. | Autodesk) :

  Dim doc As Document
    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
    docAssets = doc.Assets
    
    ' Create a new appearance asset.
    Dim appearance As Asset
    appearance = docAssets.Add(kAssetTypeAppearance, "Generic", _
                                    "MyShinyRed", "My Shiny Red Color")
    
    Dim tobjs As TransientObjects
    tobjs = ThisApplication.TransientObjects


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

i use it like this:

materialasset.Item("physmat_Keywords").Value = sap_.Text
materialasset.Item("physmat_Label").Value = sap_.Text
materialasset.Item("physmat_Manufacturer").Value = Producent_.Text
materialasset.Item("physmat_Comments").Value = kategoria_.Text
materialasset.Item("physmat_Model").Value = wymiar_.Text
materialasset.Item("physmat_Type").Value = "physmat_" & assloctype.ToLower
materialasset.Item("physmat_class").Value = obr_czt.Text
materialasset.Item("physmat_Cost").Value = ilosc_.Text

or:

Dim generic_color As Inventor.TextureAssetValue
generic_color = app_ass.Item("hardwood_color")
Dim textureValue As TextureAssetValue = generic_color
Dim texture As AssetTexture = textureValue.Value
Dim textureSubValue As AssetValue = texture.Item("unifiedbitmap_Bitmap")
If texture.Item("texture_WAngle").Value <> 0 Then texture.Item("texture_WAngle").Value = 0

 

here is shown how to access assetvalues:

Inventor 2025 Help | Write out all physical properties to a file. | Autodesk

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 3 of 8

Maxim-CADman77
Advisor
Advisor

I try to modify values of materials directly in library.
I read initial value, set new value, read the value one more time (to make sure it changed), BUT
when I run my code one more time - it returns the same initial value..
Should I force save asset or whole parent Library after AssetValue edit somehow?

 

PS:

Target Library is not read only and it modified time does change after each run of my solution..

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 4 of 8

marcin_otręba
Advisor
Advisor

i think that it would work better if you change asset value in document material and then use copyto method:https://help.autodesk.com/view/INVNTOR/2025/ENU/?guid=Asset_CopyTo

 

 to update it in library, when you change it directly in library, you should use isreadonly method: https://help.autodesk.com/view/INVNTOR/2025/ENU/?guid=Asset_IsReadOnly

 

but also library must be set to have possibility to write it, as far i remember there was some issue when i was trying to do it as you wish and it was updated after library was released… for sure copyto approach will work

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 5 of 8

Maxim-CADman77
Advisor
Advisor

Modifying Asset after copy to document dosen't help - I'm again get same initial value.
I've also added the check of the Assets for ReadOnly before modify the value (to add context - I'm coding batch Material Density value updater).


I'm tired and puzzled - the issue disappears for those assets that were manually open in UI after modification.

 

This issue reproduced in actual Inventor release (2024.5) and for me it seems like some API defect.

 

Dear, @MjDeck, could you, please, comment?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 6 of 8

YuhanZhang
Autodesk
Autodesk

Hi @Maxim-CADman77 can you follow @marcin_otręba to modify your asset in document, and then save it to library. If you see problem when update any physical asset value, can you share your code snippet here so we can look into it?



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 7 of 8

marcin_otręba
Advisor
Advisor

@Maxim-CADman77  if you want to change material density then you must do it troug its phisical properties asset:

Dim material As MaterialAsset
material = projekt_asslib.MaterialAssets("mat name")
material.PhysicalPropertiesAsset.Item("structural_Density").Value=2
Logger.Info(material.PhysicalPropertiesAsset.Item("structural_Density").Value)

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 8 of 8

YuhanZhang
Autodesk
Autodesk
Accepted solution

@Maxim-CADman77 here is an iLogic rule sample demonstrating how to update the physical property value for a library asset:

 

Sub Main()
    Dim oDoc As PartDocument
    oDoc = ThisApplication.Documents.Add(kPartDocumentObject)
        
    ' Create a custom aslib which is read-write
    Dim oLib As AssetLibrary
    oLib = ThisApplication.AssetLibraries.Add("C:\Temp\TempLib.adsklib")
        
    ' Copy a material asfrom  Autodesk Material Library to custom lib
    Dim oLibAsset As Asset
    oLibAsset= ThisApplication.AssetLibraries.Item("AD121259-C03E-4A1D-92D8-59A22B4807AD").MaterialAssets("Material-001") ' Porcelain, Ivory
    
    oLibAsset.CopyTo(oLib)
    oLibAsset= oLib.MaterialAssets(1)
    
    Dim oLocalAsset As Asset
    oLocalAsset= oLibAsset.CopyTo(oDoc,False)
    
    Dim material As MaterialAsset
    material = oLocalAsset
    
    ' update the density value 
	Dim dDensity As Double
	dDensity = material.PhysicalPropertiesAsset.Item("structural_Density").Value
	Logger.Info("Initial density value: " & dDensity)
    material.PhysicalPropertiesAsset.Item("structural_Density").Value = material.PhysicalPropertiesAsset.Item("structural_Density").Value+ 550#
    Logger.Info("Updataed density value: " & material.PhysicalPropertiesAsset.Item("structural_Density").Value)
    
    ' Update the lib asset
    material.CopyTo (oLib, True)
    Logger.Info( "Lib density: " & oLib.MaterialAssets(1).PhysicalPropertiesAsset.Item("structural_Density").Value)
End Sub

 

Please try it there and let me if any more questions.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes