AssetPropertyAddCopyAsConnectedAsset Method |
Makes a copy of the asset and connects it to this property.
Namespace: Autodesk.Revit.DB.VisualAssembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntaxpublic void AddCopyAsConnectedAsset(
Asset pRenderingAsset
)
Public Sub AddCopyAsConnectedAsset (
pRenderingAsset As Asset
)
public:
void AddCopyAsConnectedAsset(
Asset^ pRenderingAsset
)
member AddCopyAsConnectedAsset :
pRenderingAsset : Asset -> unit
Parameters
- pRenderingAsset Asset
-
The asset to duplicate and associate with this property as a connected asset.
ExceptionsException | 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.
|
Examplepublic void CopyAndAddConnectedAsset(Material sourceMaterial, Material targetMaterial)
{
Document doc = targetMaterial.Document;
ElementId otherAppearanceAssetId = sourceMaterial.AppearanceAssetId;
AppearanceAssetElement otherAssetElem = doc.GetElement(otherAppearanceAssetId) as AppearanceAssetElement;
Asset otherAsset = otherAssetElem.GetRenderingAsset();
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);
AssetProperty genericDiffuseProperty = editableAsset.FindByName(Generic.GenericDiffuse);
Asset genericDiffuseConnectedAsset = genericDiffuseProperty.GetSingleConnectedAsset();
if (genericDiffuseConnectedAsset == null)
{
genericDiffuseProperty.AddCopyAsConnectedAsset(otherGenericDiffuseConnectedAsset);
}
editScope.Commit(true);
}
t.Commit();
}
}
Public Sub CopyAndAddConnectedAsset(sourceMaterial As Material, targetMaterial As Material)
Dim doc As Document = targetMaterial.Document
Dim otherAppearanceAssetId As ElementId = sourceMaterial.AppearanceAssetId
Dim otherAssetElem As AppearanceAssetElement = TryCast(doc.GetElement(otherAppearanceAssetId), AppearanceAssetElement)
Dim otherAsset As Asset = otherAssetElem.GetRenderingAsset()
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)
Dim genericDiffuseProperty As AssetProperty = editableAsset.FindByName(Generic.GenericDiffuse)
Dim genericDiffuseConnectedAsset As Asset = genericDiffuseProperty.GetSingleConnectedAsset()
If genericDiffuseConnectedAsset Is Nothing Then
genericDiffuseProperty.AddCopyAsConnectedAsset(otherGenericDiffuseConnectedAsset)
End If
editScope.Commit(True)
End Using
t.Commit()
End Using
End Sub
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
See Also