Is there a way to get the shading color of the Material through API?
Hi,
I looked up a material in RevitLoopUp and the shading color seems to be retrieved simply by:
Color c = material.Color;
string colorString = string.Format("Red [{0}] Green [{1}] Blue [{2}]", c.Red, c.Green, c.Blue)
Look here for more information about the Material class, at the bottom it has sample code on how to retrieve the other colors for cut and surface.
https://www.revitapidocs.com/2020/2ec33007-7a2a-f86a-009b-d4c5d235a307.htm
This link will have more information about the color class.
https://www.revitapidocs.com/2020/9797a83f-d91b-7fa6-c381-ac5ecb527d36.htm
I hope this help!
Sincerely,
Jason Twigg
Sorry for not posting the code and making my intention not clear. I tried using property
Material.Color
It works but the materials imported from Rhino/SAT throws invalid or uninitialized color, below the working code for it
public void GetMaterialColor () { Document doc = this.ActiveUIDocument.Document; List<Element> materials = new FilteredElementCollector (doc).OfClass (typeof (Material)).ToList (); var message = new StringBuilder (); foreach (Material material in materials) { string name = material.Name; try { string red = material.Color.Red.ToString (); string green = material.Color.Green.ToString (); string blue = material.Color.Blue.ToString (); message.AppendLine (name + "-" + red + "_" + green + "_" + blue + "."); } catch (Exception e) { message.AppendLine (name + " - " + e.Message); } } TaskDialog.Show ("Materials in the project", message.ToString ()); }
How could I retrieve the RGB from this material?
Hi,
this may solve your problem:
Page 9 shows how to get/set the value.
Revitalizer
@Revitalizer Thanks for the link. It has in depth explanation about the materials. I tried to use this method to extract the color, but I see that according to API docs, the AppearanceAssetId returns invalid Id for the materials imported from external geometry.
ElementId appearanceAssetId = material.AppearanceAssetId; AppearanceAssetElement assetElem = material.Document.GetElement(appearanceAssetId) as AppearanceAssetElement;
So I could not proceed further since the assetElem will return null. Any thoughts on that or am I missing anything in between.