Adding/Removing UserData from PlugingTag

On 09/02/2013 at 17:59, xxxxxxxx wrote:

Hi all,

Ive got a Plugin-tag and Id like to add or remove userdatas. Adding works, but removing is a problem. I have already tried out various things, but nothing has worked. Here are some naked lines. Which command do I need to update the userdatacontainer immediately?

import os  
import math  
import sys  
import c4d  
  
from c4d import plugins, utils, bitmaps, gui  
  
# be sure to use a unique ID obtained from www.plugincafe.com  
PLUGIN_ID = 145268788 #TestID  
  
class TagPlugin(plugins.TagData) :  
  
  def Init(self, node) :  
      return True  
  
  def Message(self, node, type, data) :  
      if type==c4d.MSG_DESCRIPTION_COMMAND:   
          if data["id"][0].id == 10001: self.AddUD(node)  
          elif data["id"][0].id == 10002: self.RemoveUD(node)  
      return True  
  
  def Execute(self, tag, doc, op, bt, priority, flags) :#  
      return c4d.EXECUTIONRESULT_OK  
  
  def AddUD(self, node) :  
      data = c4d.GetCustomDatatypeDefault(c4d.DTYPE_BOOL)  
      data[c4d.DESC_NAME] = "Enable"  
      node[node.AddUserData(data)] = False  
  
  def RemoveUD(self,node) :  
      node.RemoveUserData(1)  
  
  
if __name__ == "__main__":  
   
  dir, file = os.path.split(__file__)  
  bmp = bitmaps.BaseBitmap()  
  bmp.InitWith(os.path.join(dir, "res", "icon.tif"))  
  
  plugins.RegisterTagPlugin(id=PLUGIN_ID,  
                           str="TagPlugin",  
                           g=TagPlugin,  
                           description="TagPlugin",  
                           icon=bmp,  
                           info=c4d.TAG_MULTIPLE|c4d.TAG_EXPRESSION|c4d.TAG_VISIBLE)

Another problem Ive got are separators. For example:

def AddUD(self, node) :  
      data = c4d.GetCustomDatatypeDefault(c4d.DTYPE_BOOL)  
      data[c4d.DESC_NAME] = "Enable"  
      node[node.AddUserData(data)] = False  
  
      data = c4d.GetCustomDatatypeDefault(c4d.DTYPE_SEPARATOR)  
      data[c4d.DESC_SEPARATORLINE] = True  
      node.AddUserData(data)  
  
      data = c4d.GetCustomDatatypeDefault(c4d.DTYPE_BOOL)  
      data[c4d.DESC_NAME] = "Enable2"  
      node[node.AddUserData(data)] = False 

The separators are listed in the UserDataManager but hidden in the interface. I wasn´t able to get a solution. What is wrong?

Thanks in anticipation
rown
**

On 09/02/2013 at 18:47, xxxxxxxx wrote:

I ran into this same annoying problem trying to remove UD using C++.
Apparently the whole tag has to be updated when removing UD. But not when adding them.

Try this:

def RemoveUD(self,node) :  
  node.RemoveUserData(1)  
  c4d.SendCoreMessage(c4d.COREMSG_CINEMA, c4d.BaseContainer(c4d.COREMSG_CINEMA_FORCE_AM_UPDATE))

This is currently not documented in any of the SDK's. But it should be.

-ScottA

On 10/02/2013 at 04:08, xxxxxxxx wrote:

Hello Scott,

the command seems to be brutal, but works perfectly. Thank you very much.
One last little question: Do you happen to know the separator-problem, too?

Greetings
rown

On 10/02/2013 at 07:53, xxxxxxxx wrote:

Sorry. I can't help with the separator problem.
That's a strange one.

-ScottA

On 10/02/2013 at 15:53, xxxxxxxx wrote:

With some persistence I managed to figure it out.

def addSeparator(obj) :  
  if obj is None: return  
  
  bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_SEPARATOR) #Create default container  
  bc[c4d.DESC_NAME] = "My Separator"                     #Rename the entry  
  bc.SetLong(c4d.DESC_CUSTOMGUI,c4d.DTYPE_SEPARATOR)  
  bc.SetBool(c4d.DESC_SEPARATORLINE, False)  
  obj.AddUserData(bc)                                    #Add the userdata container  
  c4d.EventAdd()                                         #Update C4D

Again.
Things like this really should be documented better.

-ScottA

On 11/02/2013 at 02:39, xxxxxxxx wrote:

Wow, thank you very much. I'm very excited. Will try tonight.

Greeting
rown