2023 Method
Changes 4
M

Material.Duplicate

Description:
Duplicates the material
Remarks:
If duplication fails for reasons unrelated to the name, .a null reference (Nothing in Visual Basic) will be returned.
public Material Duplicate(
	string name
)
  • String
    name
    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. The new material.
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;
}