Several queries concerning rendering issues were discussed recently and solved by the new Visual Materials API included in Revit 2018.1:
Here comes another one, answered more completely by Boris Shafiro's Autodesk University class on this topic:
Question: How can I set the Material Render Appearance through the API in Revit 2018?
I can see there is the Autodesk.Revit.DB.Visual.Asset class, but how do I add to the list of Autodesk.Revit.DB.Visual.AssetProperty objects for a new material?
I noticed the forum thread on how to create or modify a rendering asset that seems to indicate limitations in this area...
Answer: Unfortunately, this is not possible in Revit 2018.
The good news is that it is possible in Revit 2018.1 using the Visual Materials API.
Check out Boris Shafiro's class at AU to learn about it.
The ability to use the Revit API to modify visual appearances of materials was among the top customer requests for years. This new API has been implemented in Revit 2018.1. This class presents the new Visual Materials API, coding workflows, and usage of multiple schemas for the visualization properties of materials in Revit software – by Boris Shafiro, Software Development Manager, Autodesk:
For the sake of completeness and search engine findability, here is the pure text copied out of the slide deck:
Learn how to
using( AppearanceAssetEditScope editScope = new AppearanceAssetEditScope( document ) ) { Asset editableAsset = editScope.Start( assetElem.Id ); AssetPropertyDoubleArray4d genericDiffuseProperty = editableAsset["generic_diffuse"] as AssetPropertyDoubleArray4d; genericDiffuseProperty.SetValueAsColor( color ); editScope.Commit( true ); }
using( AppearanceAssetEditScope editScope = new AppearanceAssetEditScope( document ) ) { Asset editableAsset = editScope.Start( assetElem.Id ); AssetProperty bumpMapProperty = editableAsset["generic_bump_map"]; Asset connectedAsset = bumpMapProperty.GetSingleConnectedAsset(); if( connectedAsset != null ) { AssetPropertyString bumpmapBitmapProperty = connectedAsset["unifiedbitmap_Bitmap"] as AssetPropertyString; if( bumpmapBitmapProperty.IsValidValue( bumpmapImageFilepath ) ) bumpmapBitmapProperty.Value = bumpmapImageFilepath; } editScope.Commit( true ); }
AssetPropertyDoubleArray4d genericDiffuseProperty = editableAsset["generic_diffuse"] as AssetPropertyDoubleArray4d;
Equivalent:
AssetPropertyDoubleArray4d genericDiffuseProperty = editableAsset[Generic.GenericDiffuse] as AssetPropertyDoubleArray4d;
AssetPropertyString path = asset[UnifiedBitmap.UnifiedbitmapBitmap] as AssetPropertyString;
AssetPropertyDoubleArray4d color = asset[Generic.DiffuseColor] as AssetPropertyDoubleArray4d;
The Value of this AssetProperty is ignored if there is a connected Asset.
AssetPropertyReference reference – Does not have a Value. Used only to have a connected Asset.
Edit appearance asset properties via a small control dialog – this sample demonstrates basic usage of the AppearanceAssetEditScope and AssetProperty classes to change the value of an asset property in a given material: