Setting AppearanceAsset properties of newly created Revit Material

By Naveen Kumar

Question: One can change the AppearanceAsset properties of a UI-generated Revit material. However, the AppearanceAssetId value is null if the material is API-generated. The AppearanceAsset properties cannot be set for the material created by the API. Is it possible to modify or set the AppearanceAsset properties of an API-generated Material?

Answer: Since the API-generated material lacks an AppearanceAssetId , it should be set explicitly. In this case, the simplest way to create a new material is to duplicate an existing one and then modify it.

In the code below, red carpet material has been duplicated, and the AppearanceAsset properties of the duplicated material have been modified.


public void DuplicateAndModifyMaterial(Material material)
        ElementId appearanceAssetId = material.AppearanceAssetId;
        AppearanceAssetElement assetElem = material.Document
.GetElement(appearanceAssetId) as AppearanceAssetElement;
ElementId duplicateAssetElementId = ElementId.InvalidElementId; using (Transaction t = new Transaction(material.Document)) { t.Start("Duplicate Red Carpet Material"); // Duplicate the material Material duplicateMaterial = material.Duplicate("Blue Carpet");
// Duplicate the appearance asset and the asset in it AppearanceAssetElement duplicateAssetElement = assetElem.Duplicate("Blue Carpet");
// Assign the asset element to the material duplicateMaterial.AppearanceAssetId = duplicateAssetElement.Id; duplicateAssetElementId = duplicateAssetElement.Id; t.Commit(); } // Make changes to the duplicate asset using (Transaction t2 = new Transaction(material.Document)) { t2.Start("Change blue carpet material assets"); using (AppearanceAssetEditScope editScope
= new AppearanceAssetEditScope(assetElem.Document)) {

// returns an editable copy of the appearance asset Asset editableAsset = editScope.Start(duplicateAssetElementId);
// Description AssetPropertyString descriptionProperty =editableAsset
.FindByName("description") as AssetPropertyString; descriptionProperty.Value = "blue carpet";

// Diffuse image AssetPropertyDoubleArray4d genericDiffuseProperty = editableAsset
.FindByName("generic_diffuse") as AssetPropertyDoubleArray4d;
.SetValueAsColor(new Autodesk.Revit.DB.Color(0x00, 0x00, 0xFF));
Asset connectedAsset = genericDiffuseProperty.GetSingleConnectedAsset(); AssetPropertyString bitmapProperty = connectedAsset
.FindByName("unifiedbitmap_Bitmap") as AssetPropertyString;

//Appearance tab >>> Generic >>> Image bitmapProperty.Value = @"Your image Path here"; editScope.Commit(true); } t2.Commit(); } }

Please note: Here in this instance, the "generic_diffuse" property has been accessed. However, not every AppearanceAsset will have the "generic_diffuse" property. So, please use the RevitLookup tool to explore the material element, find the relevant property, and modify it accordingly.










April 2024

Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30        

Autodesk Blogs