Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get the shading color of the Material through API

5 REPLIES 5
Reply
Message 1 of 6
gprofile
1413 Views, 5 Replies

Get the shading color of the Material through API

Is there a way to get the shading color of the Material through API?

 

Material BrowserMaterial Browser

5 REPLIES 5
Message 2 of 6
j.buijs
in reply to: gprofile

Isn't that just the Material.Color property?

See here.

For me it always is, but my materials settings may be different from you.

Message 3 of 6
jrtwigg
in reply to: gprofile

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

 

 

 

 

 

LinkedInLogo
Message 4 of 6
gprofile
in reply to: gprofile

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 ());
}

material 2.pngmaterial.PNG

How could I retrieve the RGB from this material?

Message 5 of 6
Revitalizer
in reply to: gprofile

Hi,

 

this may solve your problem:

 

https://thebuildingcoder.typepad.com/files/sd124625_visual_appearance_of_materials_api_boris_shafiro...

 

Page 9 shows how to get/set the value.

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 6 of 6
gprofile
in reply to: 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.

 

invalidId.PNG

 

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.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community