Hello,
you cannot create a Material in the main() function of a Python Generator object.
The main() function of the Python Generator object defines a cache of "virtual" BaseObjects which will appear in the scene.
Materials cannot be created this way. A material must be inserted into the BaseDocument. This must only happen from the main thread, typically in reaction to some user interaction.
One way of doing this would be to add a user data button to your Generator. Then your user could simply press that button to create the needed materials. Pressing the button can be detected by implementing the message() function.
This could look like this:
def main():
# search for material
mat = doc.SearchMaterial("Generator Material")
if mat is None:
return None
# create object
cube = c4d.BaseObject(c4d.Ocube)
# apply material
ttag = cube.MakeTag(c4d.Ttexture)
ttag[c4d.TEXTURETAG_MATERIAL] = mat
return cube
def message(id, data):
if id == c4d.MSG_DESCRIPTION_COMMAND:
buttonId = data['id']
# check button ID
if buttonId[1].id == 1:
# create material and insert it into the host document
c4d.StopAllThreads()
material = c4d.Material()
material.SetName("Generator Material")
material[c4d.MATERIAL_COLOR_COLOR] = c4d.Vector(1,0,0)
doc.InsertMaterial(material, None)
c4d.EventAdd()
Also, please use the Q&A system.
best wishes,
Sebastian