RVTDocs.com

AppearanceAssetElement.Duplicate

Method
Description:
Duplicates the appearance asset element.
Remarks:
The asset contained by this element will be duplicated as well. Changes to the duplicated element or its asset do not affect the original element and asset.
Syntax
Examples
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, "Duplicate Red Carpet Material"))
   {
      t.Start();

      // 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, "Change blue carpet material"))
   {
      t2.Start();

      using (AppearanceAssetEditScope editScope = new AppearanceAssetEditScope(assetElem.Document))
      {
         Asset editableAsset = editScope.Start(duplicateAssetElementId);   // returns an editable copy of the appearance asset

         // Description
         AssetPropertyString descriptionProperty =
            editableAsset.FindByName("description") as AssetPropertyString;
         descriptionProperty.Value = "blue carpet";

         // Diffuse image
         AssetPropertyDoubleArray4d genericDiffuseProperty = editableAsset.FindByName("generic_diffuse") as AssetPropertyDoubleArray4d;

         genericDiffuseProperty.SetValueAsColor(new Color(0x00, 0x00, 0xFF));

         Asset connectedAsset = genericDiffuseProperty.GetSingleConnectedAsset();

         AssetPropertyString bitmapProperty = connectedAsset.FindByName("unifiedbitmap_Bitmap") as AssetPropertyString;

         bitmapProperty.Value = "Finishes.Flooring.Carpet.4.png";

         editScope.Commit(true);
      }

      t2.Commit();
   }
}
Parameters
Parameter Type Description
name String Name of the new appearance asset element - this name must be correctly structured for Revit use and not duplicate the name of another appearance asset in the document.
Return Value
Type Description
AppearanceAssetElement The new AppearanceAssetElement.
Exceptions
Exception Condition
ArgumentException name cannot include prohibited characters, such as "{, }, [, ], |, ;, less-than sign, greater-than sign, ?, `, ~". -or- The given value for name is already in use as an appearance asset name.
ArgumentNullException A non-optional argument was null