get color of imported CAD meshes

get color of imported CAD meshes

uwewoessner
Participant Participant
476 Views
1 Reply
Message 1 of 2

get color of imported CAD meshes

uwewoessner
Participant
Participant

I have a revit project with an imported DWG file.
The GeometryInstance contains meshes and the meshes show different colors when rendered in Revit.
Both the MaterialElementId and GraphicsStyleId properties of the Mesh objects are null.

Is there any way of accessing the color of the meshes through the API?

Regards,
 Uwe

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

Anonymous
Not applicable

Hi Uwe,

 

I used the following:

 

Type typecontroller = typeof(Mesh);
PropertyInfo fieldInfo = typecontroller.GetProperty("InternalMaterialElement", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty);
Material mat = fieldInfo.GetValue(mesh) as Material;
var colour = mat.Color;

 

It's not ideal as it uses System.Reflection which has a performance cost. There may be a better way to access this information, but this worked for me.

 

Hope this helps,

Pete