Rhino C++ Plugin : Materials not showing up after exploding blocks in C++ plugin

Hi,
So I am exporting Rhino models into another format.
I’m obtaining meshes using RhinoMeshObjects. So, whenever I explode some blocks in the model, and export it via my plugin, some of the exploded meshes do not have any material applied on them.
So does exploding a block instance change its material property?
Currently, I am using this code to get the material index (The materials themselves are being exported fine though):

        int GetMaterialIndex(CRhinoDoc& doc, const CRhinoObjectMesh& object_mesh, int default_material_index)
    {
    	char* name = GetNameFromONwStr(object_mesh.m_parent_object->Name());
    	if (name != nullptr)
    	{
    		::RhinoApp().Print("\nGetting the material index for object %s", name);
    	}
    	int material_index = -1;
    	int layer_index = -1;

	switch (object_mesh.m_mesh_attributes.MaterialSource())
	{
	case ON::material_from_object:
		::RhinoApp().Print("\nMaterial is from - OBJECT");
		material_index = object_mesh.m_mesh_attributes.m_material_index;
		break;

	case ON::material_from_layer:
		::RhinoApp().Print("\nMaterial is from - LAYER");
		layer_index = object_mesh.m_mesh_attributes.m_layer_index;
		material_index = doc.m_layer_table[layer_index].m_material_index;
		::RhinoApp().Print("\nMaterial Index is %d", material_index);
		break;

	case ON::material_from_parent:
	{
		::RhinoApp().Print("\nMaterial is from - PARENT");
		const CRhinoInstanceObject* iref_object = object_mesh.m_iref_object;
		if (iref_object)
		{
			switch (iref_object->Attributes().MaterialSource())
			{
			case ON::material_from_object:
				material_index = iref_object->Attributes().m_material_index;
				break;

			case ON::material_from_layer:
				layer_index = iref_object->Attributes().m_layer_index;
				material_index = doc.m_layer_table[layer_index].m_material_index;
				break;
			}
		}
	}
	break;

	default:
		::RhinoApp().Print("\n****NO MATERIAL IS FOUND FOR THIS OBJECT !!!!****");
		break;

	}
	if (material_index == -1)
	{
		return default_material_index;
	}
	else
	{
		return material_index;
	}

}

Hi @binigya,

Can you post a file with the block you are trying to explode?

– Dale