import c4d, string
from c4d import documents, plugins
PID_MESSAGE = 1029730
PID_CMDDATA = 1029729
TOOLID = 14055
class fhFreehandMessageData(plugins.MessageData):
def __init__ (self):
self.Cache = None
self.IsActive = False
self.Counter = 0
def CoreMessage(self, id, bc):
doc = documents.GetActiveDocument()
# set the cache when the plugin instance has been created
# and there is no cache yet
if not self.Cache:
self.Cache = doc.GetFirstObject()
# ---> here it happens
# listen for our commanddata id and togle the state
if id == PID_CMDDATA:
self.IsActive = not self.IsActive
if self.IsActive:
print 'Yay, i am back again.'
else:
print 'I should shut up ? You will be doomed without me !'
# listen if c4d send EventAdd(EVMSG_CHANGE) and check if the
# currently topmost object is the same to our stored / cached
# object, if not there has been inserted a new object.
elif id == c4d.EVMSG_CHANGE and doc.GetAction() == TOOLID:
# add 'and self.IsActive, which is the short form for and self.IsActive == True'
if self.Cache and self.Cache is not doc.GetFirstObject() and self.IsActive:
self.Cache = doc.GetFirstObject()
if self.Cache.GetType() == c4d.Ospline:
print "Spline No.{0}, named {1} - this boring , can we do somethingg else please ?".format(self.Counter, self.Cache.GetName())
self.Counter += 1
# object is inserted but the plugin is not 'active'
elif self.Cache and self.Cache is not doc.GetFirstObject() and not self.IsActive:
print 'I am not allowed to say something... Ooops.'
return True
class FreehandPlusToggle(c4d.plugins.CommandData):
def __init__ (self):
self.isActive = False
def Execute(self, doc):
self.isActive = not self.isActive
# ---> send the message
c4d.SpecialEventAdd(PID_CMDDATA, 0,0)
return True
def GetState(self, doc):
if (self.isActive):
return c4d.CMD_VALUE + c4d.CMD_ENABLED
else:
return c4d.CMD_ENABLED
if __name__ == "__main__":
plugins.RegisterMessagePlugin(id = PID_MESSAGE,
str = "fhFreeHandMessage",
info = c4d.PLUGINFLAG_SMALLNODE,
dat = fhFreehandMessageData())
plugins.RegisterCommandPlugin(id = PID_CMDDATA,
str = "FreehandPlusToggle",
info = 0,
icon = None,
help = "This is a Tooltip for FreehandPlusToggle.",
dat = FreehandPlusToggle())