i’m really happy to see that it was useful, and you could incorporate the suggestions so well
def matlayer():
global move2, freeLayers
if move2+1 > len(freeLayers):
move2 -= len(freeLayers)
matlayer()
return()
this i dont wholly understand, but i guess it is dealing with the layer numbers, keeping track of what is where … as a style thing, it is usually better not to use globals in functions, but have them receive and return objects, but it does not really matter in a small script like this.
#move the objects to the different layers
if len(freeLayers) > 0:
for l in objectlist:
if l.getData().getMaterials():
material = l.getData().getMaterials()[0]
if material.getName() not in materiallist:
materiallist.append(material.getName())
move2 = materiallist.index(material.getName())
matlayer()
l.layers = [freeLayers[move2]]
so does materiallist have names of materials, with the list index matching the layer where objects with that material are put? or what? that part is a bit difficult to understand.
as mappings go, be sure to know how to use Python dictionaries - they are taught in every tutorial, and everyone should go through one of them.
for example, if you keep a list of material names and wanna know to which layer to put them, i’d have a dictionary that maps names to numbers, like this:
mat2layer = {}
mat2layer[material] = layernum
..
layernum = mat2layer[material]
anymore. The reason is that l.layers = [freeLayers[move2]] takes more than 90% of the entire time the script needs, and that command is absolutely necessary since it does the actual moving of the objects.
ok. that part is implemented in C in the API code -if the speed is a problem, you or someone can look how it is made there for possible improvements. but i guess the speed is not bad as it is?
~Toni