Duplicate Method


Duplicates the material

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 23.0.0.0 (23.1.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 - this name must be correctly structured for Revit use and not duplicate the name of another material in the document.

Return Value

The new material.

Remarks

If duplication fails for reasons unrelated to the name, a null reference ( Nothing in Visual Basic) will be returned.

Examples

Copy C#
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;
}
Copy VB.NET
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, such as "{, }, [, ], |, ;, less-than sign, greater-than sign, ?, `, ~". -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

See Also