@Holo wrote:
Hi guys, I am making a material with Python but I encounter a bug where Rhino removes the previous made material if I change the “NAME” in the script. It appears to make a new material OK, with a new index and all, but where is the old one?
import rhinoscriptsyntax as rs import scriptcontext import random ### --- Make Material newMatIndex = scriptcontext.doc.Materials.Add() print "newMatIndex= "+str(newMatIndex) rs.MaterialName(newMatIndex, str(int(100000*random.random() ))) color =(int(random.random()*250),int(random.random()*250),int(random.random()*250) ) rs.MaterialColor(newMatIndex, color) print "MaterialName= "+str(rs.MaterialName(newMatIndex)) scriptcontext.doc.Materials.Add()
This is just a modified and simplified script to illustrate the problem.
My real big problem is that I generate a gradient PNG and assign this in a larger script, and when I run the script the second time the material turns black, I presume some bug is going on internally in Rhino’s material handling and I can not seem to find a workaround. Because IF I make a new material in Rhino’s material editor and name that “NAME” too, then that is fine, but if I do it one more time then I get an error message saying that the name is already in use. (But now I already have two materials named the same… odd)Also if I delete the generated material in the material library then I can run the script again.
But if I autogeneate names with random then the old materials just disappear…
Posts: 5
Participants: 2