Revit 2015 API |
Material..::..Duplicate Method |
Material Class Example See Also |
Duplicates the material
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 2015.0.0.0 (2015.0.0.0)
Syntax
C# |
---|
public Material Duplicate( string name ) |
Visual Basic |
---|
Public Function Duplicate ( _ name As String _ ) As Material |
Visual C++ |
---|
public: Material^ Duplicate( String^ name ) |
Parameters
- name
- Type: System..::..String
Name of the new material.
Return Value
The new material.
Remarks
If the name specified contains invalid characters,
or the name has been used by other materials in the project, an ArgumentException will
be thrown. If duplication fails, nullNothingnullptra null reference (Nothing in Visual Basic) will be returned.
Examples

private bool DuplicateMaterial(Material material) { bool duplicated = false; //try to duplicate a new instance of Material class using duplicate method //make sure the name of new material is unique in MaterailSet string newName = "new" + material.Name; Material myMaterial = material.Duplicate(newName); if (null == myMaterial) { TaskDialog.Show("Revit", "Failed to duplicate a material!"); } else { duplicated = true; } return duplicated; }

Private Function DuplicateMaterial(material As Material) As Boolean Dim duplicated As Boolean = False 'try to duplicate a new instance of Material class using duplicate method 'make sure the name of new material is unique in MaterailSet Dim newName As String = "new" & Convert.ToString(material.Name) Dim myMaterial As Material = material.Duplicate(newName) If myMaterial Is Nothing Then TaskDialog.Show("Revit", "Failed to duplicate a material!") Else duplicated = True End If Return duplicated End Function
Exceptions
Exception | Condition |
---|---|
Autodesk.Revit.Exceptions..::..ArgumentException | name cannot include prohibited characters. -or- The given value for name is already in use as a material element name. |
Autodesk.Revit.Exceptions..::..ArgumentNullException | A non-optional argument was NULL |