AppearanceAssetElementDuplicate Method |
Duplicates the appearance asset element.
Namespace: Autodesk.Revit.DBAssembly: RevitAPI (in RevitAPI.dll) Version: 27.0.4.0 (27.0.4.0)
Syntaxpublic AppearanceAssetElement Duplicate(
string name
)
Public Function Duplicate (
name As String
) As AppearanceAssetElement
public:
AppearanceAssetElement^ Duplicate(
String^ name
)
member Duplicate :
name : string -> AppearanceAssetElement Parameters
- name String
-
Name of the new appearance asset element - this name must be correctly structured for Revit use and not duplicate the name
of another appearance asset in the document.
Return Value
AppearanceAssetElement
The new AppearanceAssetElement.
Exceptions| Exception | Condition |
|---|
| ArgumentException |
name cannot include prohibited characters, such as "{, }, [, ], |, ;, less-than sign, greater-than sign, ?, `, ~".
-or-
The given value for name is already in use as an appearance asset name.
|
| ArgumentNullException |
A non-optional argument was null
|
Remarks
The asset contained by this element will be duplicated as well. Changes to the duplicated element or its asset do not affect the original element and asset.
Examplepublic void DuplicateAndModifyMaterial(Material material)
{
ElementId appearanceAssetId = material.AppearanceAssetId;
AppearanceAssetElement assetElem = material.Document.GetElement(appearanceAssetId) as AppearanceAssetElement;
ElementId duplicateAssetElementId = ElementId.InvalidElementId;
using (Transaction t = new Transaction(material.Document, "Duplicate Red Carpet Material"))
{
t.Start();
Material duplicateMaterial = material.Duplicate("Blue Carpet");
AppearanceAssetElement duplicateAssetElement = assetElem.Duplicate("Blue Carpet");
duplicateMaterial.AppearanceAssetId = duplicateAssetElement.Id;
duplicateAssetElementId = duplicateAssetElement.Id;
t.Commit();
}
using (Transaction t2 = new Transaction(material.Document, "Change blue carpet material"))
{
t2.Start();
using (AppearanceAssetEditScope editScope = new AppearanceAssetEditScope(assetElem.Document))
{
Asset editableAsset = editScope.Start(duplicateAssetElementId);
AssetPropertyString descriptionProperty =
editableAsset.FindByName("description") as AssetPropertyString;
descriptionProperty.Value = "blue carpet";
AssetPropertyDoubleArray4d genericDiffuseProperty = editableAsset.FindByName("generic_diffuse") as AssetPropertyDoubleArray4d;
genericDiffuseProperty.SetValueAsColor(new Color(0x00, 0x00, 0xFF));
Asset connectedAsset = genericDiffuseProperty.GetSingleConnectedAsset();
AssetPropertyString bitmapProperty = connectedAsset.FindByName("unifiedbitmap_Bitmap") as AssetPropertyString;
bitmapProperty.Value = "Finishes.Flooring.Carpet.4.png";
editScope.Commit(true);
}
t2.Commit();
}
}
See Also