Gets the single connected asset attached to this asset property, if it exists.

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

Syntax

C#
public Asset GetSingleConnectedAsset()
Visual Basic
Public Function GetSingleConnectedAsset As Asset
Visual C++
public:
Asset^ GetSingleConnectedAsset()

Return Value

The connected asset, or nullNothingnullptra null reference (Nothing in Visual Basic) if there is no connected asset.

Remarks

Throws if there is more than one connected asset.

Examples

CopyC#
private void SetBumpmapBitmap(Material material, String bumpmapImageFilepath)
{
   ElementId appearanceAssetId = material.AppearanceAssetId;

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

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

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

         AssetProperty bumpMapProperty = editableAsset.FindByName("generic_bump_map");

         // Find the connected asset (with a shortcut to get the only one)

         Asset connectedAsset = bumpMapProperty.GetSingleConnectedAsset();

         if (connectedAsset == null)
         {
            // Add a new default connected asset
            bumpMapProperty.AddConnectedAsset("UnifiedBitmap");

            connectedAsset = bumpMapProperty.GetSingleConnectedAsset();
         }

         if (connectedAsset != null)
         {
            // Find the target asset property
            AssetPropertyString bumpmapBitmapProperty = connectedAsset.FindByName("unifiedbitmap_Bitmap") as AssetPropertyString;

            if (bumpmapBitmapProperty.IsValidValue(bumpmapImageFilepath))

               bumpmapBitmapProperty.Value = bumpmapImageFilepath;
         }


         editScope.Commit(true);
      }

      t.Commit();
   }
}
CopyVB.NET
Private Sub SetBumpmapBitmap(material As Material, bumpmapImageFilepath As [String])
    Dim appearanceAssetId As ElementId = material.AppearanceAssetId

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

    Using t As New Transaction(material.Document, "Change material bumpmap bitmap")
        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
       Dim bumpMapProperty As AssetProperty = editableAsset.FindByName("generic_bump_map")

       ' Find the connected asset (with a shortcut to get the only one)


       Dim connectedAsset As Asset = bumpMapProperty.GetSingleConnectedAsset()

            If connectedAsset Is Nothing Then
                ' Add a new default connected asset
                bumpMapProperty.AddConnectedAsset("UnifiedBitmap")

                connectedAsset = bumpMapProperty.GetSingleConnectedAsset()
            End If

            If connectedAsset IsNot Nothing Then
          ' Find the target asset property
          Dim bumpmapBitmapProperty As AssetPropertyString = TryCast(connectedAsset.FindByName("unifiedbitmap_Bitmap"), AssetPropertyString)

          If bumpmapBitmapProperty.IsValidValue(bumpmapImageFilepath) Then

                    bumpmapBitmapProperty.Value = bumpmapImageFilepath
                End If
            End If


            editScope.Commit(True)
        End Using

        t.Commit()
    End Using
End Sub

Exceptions

ExceptionCondition
Autodesk.Revit.Exceptions..::..InvalidOperationException Asset is connected to more than one asset.

See Also