THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 25/11/2012 at 03:26, xxxxxxxx wrote:
Hi People.
I am trying to insert a shader field into the UserData of an object. It almost works, but there is a problem I could not yet solve. The UserData field is inserted successfully and shows up in the Attribute Manager. But I cannot insert a shader into it, it just doesn't work. When viewing the field in the UserData manager, I can see the "Interface" part missing.
"Shader Field" was inserted by my code, "Data" was inserted using the UserData manager.
This is the exact code I use:
def add_shader_pressed(self, op) :
name = c4d.gui.RenameDialog('Shader Field')
if not name:
return
accept = c4d.BaseContainer()
accept.SetString(c4d.Tbaselist2d, "")
container = c4d.BaseContainer()
container.SetString(c4d.DESC_NAME, name)
container.SetString(c4d.DESC_SHORT_NAME, name)
container.SetLong(c4d.DESC_VERSION, c4d.DESC_VERSION_ALL)
container.SetBool(c4d.DESC_ANIMATE, True)
container.SetLong(c4d.DESC_CUSTOMGUI, c4d.CUSTOMGUI_TEXBOX)
container.SetContainer(c4d.DESC_ACCEPT, accept)
container.SetBool(c4d.DESC_SCALEH, True)
container.SetLong(c4d.DESC_PARENTGROUP, c4d.ID_USERDATA)
# Search for a free UserData id.
free_id = 1
userdata = sorted(op.GetUserDataContainer(), key=lambda x: x[0][0].id)
for id, data in userdata:
uid = id[1].id
if uid >= free_id:
free_id = uid + 1
# Insert the shader field into the objects' UserData.
descid = c4d.DescID(c4d.DescLevel(700), c4d.DescLevel(free_id))
success = op.SetUserDataContainer(descid, container)
if not success:
c4d.gui.MessageDialog('fatal error, could not insert userdata.')
What am I missing?
Thanks in advance,
Niklas
UPDATE: Solution