Hi soccerbatman
Try this code ,I hope this help you.
def LayerNameToMaterial():
layers = rs.LayerNames()
for i in layers:
objs = rs.ObjectsByLayer(i)
for obj in objs:
index = rs.ObjectMaterialIndex(obj)
print index
if index==0:
rs.MaterialName(index, i)
LayerNameToMaterial()
Hi NARUTO, thanks for the reply. While I understand your method and it perfectly makes sense (lopping through every single object and layer) but still materials do not get any names.
Hi
If you are modifying the rdk material, try this code.
import rhinoscriptsyntax as rs
def LayerNameToMaterial():
rdk = rs.GetPlugInObject("Renderer Development Kit")
con = rdk.ContentList("material")
layers = rs.LayerNames()
print layers
for i in layers:
objs = rs.ObjectsByLayer(i)
for obj in objs:
index = rs.ObjectMaterialIndex(obj)
mateName = rs.MaterialName(index)
rdkNames = [rdk.ContentInstanceName(con[j]) for j in xrange(len(con))]
index2 = rdkNames.index(mateName)
rdk.ContentInstanceName(con[index2],i)
if __name__ == "__main__":
LayerNameToMaterial()
Here is my own solution to it. Very useful if you are importing a rhino model into Lumion.
In order to assign each object a different material, Lumion requires you to set a material name for each layer (in Rhino). With this script, you can add material to each layer matching its layer’s name. For instance, if a layer is called ‘Curtain Wall Glass’ then it would get ‘Curtain Wall Glass’ material name. The only downside here is that you have to manually match/rename some materials if you want them to be the same material in Lumion.
import rhinoscriptsyntax as rs #Set Material Name by Layer Name