AppearanceAssetEditScope Class


A scope object that provides special access and limitations related to editing appearance assets and their related elements.

Namespace: Autodesk.Revit.DB.Visual
Assembly: RevitAPI (in RevitAPI.dll) Version: 18.0.0.0 (18.2.0.13)
Since: 2018.1

Syntax

C#
public class AppearanceAssetEditScope : IDisposable
Visual Basic
Public Class AppearanceAssetEditScope _
	Implements IDisposable
Visual C++
public ref class AppearanceAssetEditScope : IDisposable

Remarks

You can use an AppearanceAssetEditScope to modify the values of the properties of appearance assets and connected assets (such as bitmaps). The following restrictions apply:
  • A single edit scope is allowed only to edit one top level rendering assets (and its connected assets). To edit more than one appearance asset you must start a different edit scope.
  • An edit scope may be reused for editing another asset, so long as it has been committed or canceled before using start to associate it to a new asset.
  • Multiple changes to the asset are allowed before commit.
  • A transaction must be started before using Commit() on the edited asset. The transaction may be opened before or after the edit scope is started, but must be open to allow the changes into the model.

Examples

Copy C#
private void SetDiffuseColor(Material material, Color color)
{
   ElementId appearanceAssetId = material.AppearanceAssetId;

   AppearanceAssetElement assetElem = material.Document.GetElement(appearanceAssetId) as AppearanceAssetElement;

   // A transaction is necessary.  Multiple changes to the same asset can be made in one transaction if required.

   using (Transaction t = new Transaction(assetElem.Document, "Change material color"))
   {
      t.Start();

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

         // unlike AppearanceAssetElement.GetRenderingAsset(), the edit scope

         // sets up the asset for editing using the classes and utilities from

         // MaterialsManager.  The scope can keep a mapping from asset to Protein

         // class members that are obtained from the asset, to permit use of

         // Protein validation.  If the Asset was not obtained from an edit scope,

         // the setter operations for asset properties must throw.

         // Try to change values

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

         genericDiffuseProperty.SetValueAsColor(color);  // 4 length double asset properties often represent colors.

         // Shortcut methods should be added to work directly with Color objects

         // for these types.

         // Commit the entire edit scope.  If the appearance asset element is used in one or more materials, they will be

         // updated to match any changes made.

         editScope.Commit(true);
      }

      t.Commit();
   }
}
Copy VB.NET
Private Sub SetDiffuseColor(material As Material, color As Color)
    Dim appearanceAssetId As ElementId = material.AppearanceAssetId

    Dim assetElem As AppearanceAssetElement = TryCast(material.Document.GetElement(appearanceAssetId), AppearanceAssetElement)

    ' A transaction is necessary.  Multiple changes to the same asset can be made in one transaction if required
    Using t As New Transaction(assetElem.Document, "Change material color")
        t.Start()

        Using editScope As New AppearanceAssetEditScope(assetElem.Document)
            Dim editableAsset As Asset = editScope.Start(assetElem.Id)
            ' returns an editable copy of the appearance asset
            ' unlike AppearanceAssetElement.GetRenderingAsset(), the edit scope
            ' sets up the asset for editing using the classes and utilities from
            ' MaterialsManager.  The scope can keep a mapping from asset to Protein
            ' class members that are obtained from the asset, to permit use of
            ' Protein validation.  If the Asset was not obtained from an edit scope,
            ' the setter operations for asset properties must throw.
            ' Try to change values


            Dim genericDiffuseProperty As AssetPropertyDoubleArray4d = TryCast(editableAsset("generic_diffuse"), AssetPropertyDoubleArray4d)
            genericDiffuseProperty.SetValueAsColor(color)
            ' 4 length double asset properties often represent colors.
            ' Shortcut methods should be added to work directly with Color objects
            ' for these types.
            ' Commit the entire edit scope.  If the appearance asset element is used in one or more materials, they will be
            ' updated to match any changes made.


            editScope.Commit(True)
        End Using

        t.Commit()
    End Using
End Sub

Inheritance Hierarchy

System Object
Autodesk.Revit.DB.Visual AppearanceAssetEditScope

See Also