How to identify different calls to CoreMessage?
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/12/2012 at 14:50, xxxxxxxx wrote:
Hi,
does any body encountered with such C4D behavior?Place this code into *.pyp file as plugin and start C4D.
import c4d from c4d import plugins PLUGIN_ID = 1000001 class MyMessagePlugin(plugins.MessageData) : def GetTimer(self) : return 0 def CoreMessage(self, id, bc) : if id == PLUGIN_ID: print " ------------------------------------ " for i in range(0, len(bc)) : index = bc.GetIndexId(i) print " *", bc.GetData(index) return True if __name__ == "__main__": plugins.RegisterMessagePlugin(PLUGIN_ID, "Test Plugin", 0, MyMessagePlugin()) print "What python code needs to be written in CoreMessage(), to be able recognize two different messages?" print "\nShouldn't bc parameter in CoreMessage() contain values 1 and 2?" print "Does <PyCObject ...> contain these values? If do, how to access them?" # Simulate call from some other plugin A function 1. c4d.SpecialEventAdd(PLUGIN_ID, 1, 0) # Simulate call from some other plugin A function 2. c4d.SpecialEventAdd(PLUGIN_ID, 2, 0)
On R13 above code produces:
What python code needs to be written in CoreMessage(), to be able recognize two different messages? Shouldn't bc parameter in CoreMessage() contain values 1 and 2? Does <PyCObject ...> contain these values? If do, how to access them? ------------------------------------ * 1000001 * 4 * <PyCObject object at 0x11e83c120> * <PyCObject object at 0x11e83c120> ------------------------------------ * 1000001 * 4 * <PyCObject object at 0x11e83c120> * <PyCObject object at 0x11e83c120>
Any comments?
Thanks in advance
P.S.: Don't place above plugin code into C4D ScriptManager - studio will crash
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/12/2012 at 15:30, xxxxxxxx wrote:
i might be wrong, but i think you are using SpeceialEventAdd()in the wrong way. first of
all, the 2nd and 3rd arument are stated as private and optional in the python docs for R14,
so we are most likely not meant to use them. so it is not a big suprise that they get lost.also the first argument isn't called plugID or objectID, but messageID. the first argument
seems to be the messeage to be sent to the all classes listening, which could be also
your pluginID if your plugin only needs to send one message.c4d.SpecialEventAdd
( messageid[, p1=0][, p2=0] )
_<_t_<__<_t_<__<_t_<__<_t_<__<_t_<__<_t_<__<_t_>_Parameters:|- messageid ( int ) – The message ID. Use a unique ID, for example your plugin ID.
- p1 ( int ) – Private
- p2 ( int ) – Private
---|---
just as sidenote containers are dircetly iteratable, this means you do not have to do this python
version of a for loop, unless you really have to count something up or down. it is a good idea to
have some kind of recursive bc searcher helper fuction sitting in helper module.i am using this, which isn't really pretty , but it does the job:
def BcPrint(bc, indent) : print '{0}{1} | {2}'.format(indent, bc, type(bc)) if type(bc) == c4d.BaseContainer: for i in bc: BcPrint(i[1], " {0}".format(indent))
pps: please do not mind my typo, i'm kind of sick (my ear hurts) and the pain pills are really
starting to kick in, i think i just should go to bed now ... -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/12/2012 at 22:40, xxxxxxxx wrote:
Hi Ferdinand,
how is your ear, today?
Thanks for your quick replay I see your point, but I wandering how can I be sure to have a unique message ID (and not mess up with other plugins, from other developers) if I will be using some other number and not the plugin ID?
Simonas
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/12/2012 at 02:34, xxxxxxxx wrote:
Hi Simonas,
p1 and p2 parameters of SpecialEventAdd() aren't lost. They're private for the message because CINEMA and other plugins don't know anything about a special event.
But you can assign them custom data for your message.As you can see, p1 and p2 parameters are stored in the message container (BFM_CORE_PAR1 and BFM_CORE_PAR2 IDs) as opaque PyCObject values.
It's a bit tricky to convert them to a useful value, here's the code:from ctypes import pythonapi, c_void_p, py_object # In your MessageData.CoreMessage() : for id, data in bc: if str(type(data))=="<type 'PyCObject'>": pythonapi.PyCObject_AsVoidPtr.restype = c_void_p pythonapi.PyCObject_AsVoidPtr.argtypes = [py_object] data = pythonapi.PyCObject_AsVoidPtr(data) print " *", data
About the message ID, as stated by the docs it has to be unique (generated as a
plugin ID
[URL-REMOVED]).
[URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/12/2012 at 03:01, xxxxxxxx wrote:
Nice
Thank you, Yannick!