Makes a copy of the asset and connects it to this property.
Namespace: Autodesk.Revit.DB.Visual
Assembly: RevitAPI (in RevitAPI.dll) Version: 26.1.0.0 (26.1.0.34)
Syntax
C#
public void AddCopyAsConnectedAsset( Asset pRenderingAsset )
Parameters
- pRenderingAsset Asset
- The asset to duplicate and associate with this property as a connected asset.
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | A non-optional argument was null |
InvalidOperationException | The asset property is not editable. -or- Cannot check validity for a property not being edited in AppearanceAssetEditScope. -or- Asset property is already connected to one asset. |
Example
C#
public void CopyAndAddConnectedAsset(Material sourceMaterial, Material targetMaterial) { Document doc = targetMaterial.Document; // Get the appearance asset of the source material ElementId otherAppearanceAssetId = sourceMaterial.AppearanceAssetId; AppearanceAssetElement otherAssetElem = doc.GetElement(otherAppearanceAssetId) as AppearanceAssetElement; Asset otherAsset = otherAssetElem.GetRenderingAsset(); // Get the connected asset of the source material appearance asset (that contains the bitmap) AssetProperty otherGenericDiffuseProperty = otherAsset.FindByName(Generic.GenericDiffuse); Asset otherGenericDiffuseConnectedAsset = otherGenericDiffuseProperty.GetSingleConnectedAsset(); using (Transaction t = new Transaction(doc, "Change a connected asset by a copy")) { t.Start(); using (AppearanceAssetEditScope editScope = new AppearanceAssetEditScope(doc)) { ElementId appearanceAssetId = targetMaterial.AppearanceAssetId; Asset editableAsset = editScope.Start(appearanceAssetId); // returns an editable copy of the appearance asset AssetProperty genericDiffuseProperty = editableAsset.FindByName(Generic.GenericDiffuse); // Find the connected asset (with a shortcut to get the only one) Asset genericDiffuseConnectedAsset = genericDiffuseProperty.GetSingleConnectedAsset(); if (genericDiffuseConnectedAsset == null) { // Target material has only a color for �GenericDiffuse� // This will assign a bitmap to it instead // by making a copy of the asset and use it as connected asset genericDiffuseProperty.AddCopyAsConnectedAsset(otherGenericDiffuseConnectedAsset); } editScope.Commit(true); } t.Commit(); } }
VB
Public Sub CopyAndAddConnectedAsset(sourceMaterial As Material, targetMaterial As Material) Dim doc As Document = targetMaterial.Document ' Get the appearance asset of the source material Dim otherAppearanceAssetId As ElementId = sourceMaterial.AppearanceAssetId Dim otherAssetElem As AppearanceAssetElement = TryCast(doc.GetElement(otherAppearanceAssetId), AppearanceAssetElement) Dim otherAsset As Asset = otherAssetElem.GetRenderingAsset() ' Get the connected asset of the source material appearance asset (that contains the bitmap) Dim otherGenericDiffuseProperty As AssetProperty = otherAsset.FindByName(Generic.GenericDiffuse) Dim otherGenericDiffuseConnectedAsset As Asset = otherGenericDiffuseProperty.GetSingleConnectedAsset() Using t As New Transaction(doc, "Change a connected asset by a copy") t.Start() Using editScope As New AppearanceAssetEditScope(doc) Dim appearanceAssetId As ElementId = targetMaterial.AppearanceAssetId Dim editableAsset As Asset = editScope.Start(appearanceAssetId) ' returns an editable copy of the appearance asset Dim genericDiffuseProperty As AssetProperty = editableAsset.FindByName(Generic.GenericDiffuse) ' Find the connected asset (with a shortcut to get the only one) Dim genericDiffuseConnectedAsset As Asset = genericDiffuseProperty.GetSingleConnectedAsset() If genericDiffuseConnectedAsset Is Nothing Then ' Target material has only a color for “GenericDiffuse” ' This will assign a bitmap to it instead ' by making a copy of the asset and use it as connected asset genericDiffuseProperty.AddCopyAsConnectedAsset(otherGenericDiffuseConnectedAsset) End If editScope.Commit(True) End Using t.Commit() End Using End Sub