On 04/04/2013 at 13:47, xxxxxxxx wrote:
Okay, I'm not sure if this is the best method, but I listen for c4d.EVMSG_CHANGE and then I check to see whether a new object, or material has been selected by comparing the active object to a cache from the last time the EVMSG_CHANGE message was received. Because the code I'm running is rather light, I'm okay with the number of false-positives this will receive:
class MyMessageData(c4d.plugins.MessageData) :
def __init__(self) :
#Caches to help test whether there are new objects or materials
self.active_object_cache = None
self.active_mat_cache = None
pass
def GetTimer(self) :
return 0 #Don't update on a timer
def CoreMessage(self, id, bc) :
#Listen for a change to the document
if id == c4d.EVMSG_CHANGE:
doc = c4d.documents.GetActiveDocument()
active_object = doc.GetActiveObject()
active_mat = doc.GetActiveMaterial()
#Check to see whether a new object or material has been selected
#This is a hack way of checking for new objects in the scene
#NOTE: This will result in some false positives every time
#selection changes but no object has been created
diff_obj = active_object != self.active_object_cache
diff_mat = active_mat != self.active_mat_cache
if diff_obj or diff_mat:
#There's a new selection
self.active_object_cache = active_object
self.active_mat_cache = active_mat
#EXECUTING CODE GOES HERE
return True