Asset Class


Represents the properties of a material pertinent to rendering.

Namespace: Autodesk.Revit.Utility
Assembly: RevitAPI (in RevitAPI.dll) Version: 2015.0.0.0 (2015.0.0.0)

Syntax

C#
public class Asset : AssetProperties
Visual Basic
Public Class Asset _
	Inherits AssetProperties
Visual C++
public ref class Asset : public AssetProperties

Examples

Copy C#
public void ReadAsset(Asset asset)
{
   // Get the asset name, type and library name.
   AssetType type = asset.AssetType;
   string name = asset.Name;
   string libraryName = asset.LibraryName;

   // travel the asset properties in the asset.
   for (int idx = 0; idx < asset.Size; idx++)
   {
      AssetProperty prop = asset[idx];
      ReadAssetProperty(prop);
   }
}

public void ReadAssetProperty(AssetProperty prop)
{
   switch (prop.Type)
   {
      // Retrieve the value from simple type property is easy.
      // for example, retrieve bool property value.
      case AssetPropertyType.APT_Boolean:
         AssetPropertyBoolean boolProp = prop as AssetPropertyBoolean;
         bool propValue = boolProp.Value;
         break;

      // When you retrieve the value from the data array property,
      // you may need to get which value the property stands for.
      // for example, the APT_Double44 may be a transform data.
      case AssetPropertyType.APT_Double44:
         AssetPropertyDoubleArray4d transformProp = prop as AssetPropertyDoubleArray4d;
         Autodesk.Revit.DB.DoubleArray tranformValue = transformProp.Value;
         break;

      // The APT_List contains a list of sub asset properties with same type.
      case AssetPropertyType.APT_List:
         AssetPropertyList propList = prop as AssetPropertyList;
         IList<AssetProperty> subProps = propList.GetValue();
         if (subProps.Count == 0)
            break;
         switch (subProps[0].Type)
         {
            case AssetPropertyType.APT_Integer:
               foreach (AssetProperty subProp in subProps)
               {
                  AssetPropertyInteger intProp = subProp as AssetPropertyInteger;
                  int intValue = intProp.Value;
               }
               break;
         }
         break;

      case AssetPropertyType.APT_Asset:
         Asset propAsset = prop as Asset;
         ReadAsset(propAsset);
         break;
      default:
         break;
   }

   // Get the connected properties.
   // please notice that the information of many texture stores here.
   if (prop.NumberOfConnectedProperties == 0)
      return;
   foreach (AssetProperty connectedProp in prop.GetAllConnectedProperties())
   {
      // Note: Usually, the connected property is an Asset.
      ReadAssetProperty(connectedProp);
   }
}
Copy VB.NET
Public Sub ReadAsset(asset As Asset)
    ' Get the asset name, type and library name.
    Dim type As AssetType = asset.AssetType
    Dim name As String = asset.Name
    Dim libraryName As String = asset.LibraryName

    ' travel the asset properties in the asset.
    For idx As Integer = 0 To asset.Size - 1
        Dim prop As AssetProperty = asset(idx)
        ReadAssetProperty(prop)
    Next
End Sub

Public Sub ReadAssetProperty(prop As AssetProperty)
    Select Case prop.Type
        ' Retrieve the value from simple type property is easy.
        ' for example, retrieve bool property value.
        Case AssetPropertyType.APT_Boolean
            Dim boolProp As AssetPropertyBoolean = TryCast(prop, AssetPropertyBoolean)
            Dim propValue As Boolean = boolProp.Value
            Exit Select

            ' When you retrieve the value from the data array property,
            ' you may need to get which value the property stands for.
            ' for example, the APT_Double44 may be a transform data.
        Case AssetPropertyType.APT_Double44
            Dim transformProp As AssetPropertyDoubleArray4d = TryCast(prop, AssetPropertyDoubleArray4d)
            Dim tranformValue As Autodesk.Revit.DB.DoubleArray = transformProp.Value
            Exit Select

            ' The APT_List contains a list of sub asset properties with same type.
        Case AssetPropertyType.APT_List
            Dim propList As AssetPropertyList = TryCast(prop, AssetPropertyList)
            Dim subProps As IList(Of AssetProperty) = propList.GetValue()
            If subProps.Count = 0 Then
                Exit Select
            End If
            Select Case subProps(0).Type
                Case AssetPropertyType.APT_Integer
                    For Each subProp As AssetProperty In subProps
                        Dim intProp As AssetPropertyInteger = TryCast(subProp, AssetPropertyInteger)
                        Dim intValue As Integer = intProp.Value
                    Next
                    Exit Select
            End Select
            Exit Select

        Case AssetPropertyType.APT_Asset
            Dim propAsset As Asset = TryCast(prop, Asset)
            ReadAsset(propAsset)
            Exit Select
        Case Else
            Exit Select
    End Select

    ' Get the connected properties.
    ' please notice that the information of many texture stores here.
    If prop.NumberOfConnectedProperties = 0 Then
        Return
    End If
    For Each connectedProp As AssetProperty In prop.GetAllConnectedProperties()
        ' Note: Usually, the connected property is an Asset.
        ReadAssetProperty(connectedProp)
    Next
End Sub

Inheritance Hierarchy

See Also

ArchiLabs

Stop fighting Revit automation.

Build repeatable BIM design and documentation workflows with scripts, data, and AI in one place, without wrestling brittle one-off automations.

Try ArchiLabs →