Important Notice: This is a repost of The Building Coder by Jeremy Tammik. Provided for the community.
Looking for AI-powered Revit automation? Check out ArchiLabs →

Setting Material Render Appearance

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.

Visual Materials API

SD124625 – Visual Materials API

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:

Learning Objectives

Learn how to

The Basics

Materials API

Terminology

Material API building blocks

Visual Materials UI

New Editing Capabilities in Materials API

Edit Scope

New Writable Properties

New Methods

Coding Workflow to Edit a Color

  usingAppearanceAssetEditScope editScope
    = new AppearanceAssetEditScope( document ) )
  {
    Asset editableAsset = editScope.Start( assetElem.Id );
    AssetPropertyDoubleArray4d genericDiffuseProperty
      = editableAsset["generic_diffuse"]
        as AssetPropertyDoubleArray4d;
    genericDiffuseProperty.SetValueAsColor( color );
    editScope.Commit( true );
  }

Connected Assets

Coding Workflow to Edit a Connected Asset

  usingAppearanceAssetEditScope 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 );
  }

Schemas and Property Names

Standard Material Schemas

Advanced Material Schemas

Common Schema

Schemas for Connected Assets

UnifiedBitmap

Property Names

  AssetPropertyDoubleArray4d genericDiffuseProperty 
    = editableAsset["generic_diffuse"] 
      as AssetPropertyDoubleArray4d;

Equivalent:

  AssetPropertyDoubleArray4d genericDiffuseProperty 
    = editableAsset[Generic.GenericDiffuse] 
      as AssetPropertyDoubleArray4d;

Special Cases

  AssetPropertyString path
    = asset[UnifiedBitmap.UnifiedbitmapBitmap] 
      as AssetPropertyString;
  AssetPropertyDoubleArray4d color
    = asset[Generic.DiffuseColor] 
      as AssetPropertyDoubleArray4d;

SDK Sample

AppearanceAssetEditing

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: