Revit Material IDs

Revit Material IDs

h.f.h
Contributor Contributor
270 Views
1 Reply
Message 1 of 2

Revit Material IDs

h.f.h
Contributor
Contributor

Hello world,

 

I'm working in a simple code to paint all selected objetcts. I got this pice of code from the Revit API DOCs website, but my question is where can I find the revit material ID? Another question, there is a way to find this ID from a user input material name?

 

hfh_0-1653233660196.png

 

0 Likes
271 Views
1 Reply
Reply (1)
Message 2 of 2

steven.williams.as
Advocate
Advocate

You can use a FilteredElementCollector to get all the Material category elements and go from there. This macro may give you some hints.

 

public void ShowMaterials()
{
	IEnumerable<Material> materials = new FilteredElementCollector(doc).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Materials).ToElements().ToList().OfType<Material>();
	
	var glass = materials.FirstOrDefault(x => x.Name == "Glass");
	
	TaskDialog td = new TaskDialog("Materials");
	td.MainInstruction = string.Join("\n",materials.Select(x => x.Id + " (" + x.Name + ")"));
	td.MainContent = "Glass material has Id " + glass.Id.ToString();
	td.Show();
}

 

0 Likes