Message to GetVirtualObjects communication[SOLVED]
-
On 16/07/2015 at 11:09, xxxxxxxx wrote:
From time to time I run up against the problem of the need of passing a message in a plugin such as a button press to the rest of my code in GetVirtualObjects. I've missed some basic coding lesson somewhere. Here is (hopefully) the relevant code:
ABITMAPBUTTON_A = 1042, ABITMAPBUTTON_B = 1043, ABITMAPBUTTON_C = 1044, def Message(self, node, type, data) : if type==c4d.MSG_DESCRIPTION_COMMAND: if data['id'][0].id==1042: self.thePedalA = True self.thePedalB = False self.thePedalC = False if data['id'][0].id==1043: self.thePedalB = True self.thePedalA = False self.thePedalC = False if data['id'][0].id==1044: self.thePedalC = True self.thePedalA = False self.thePedalB = False return True def GetVirtualObjects(self, op, hierarchy help) : if self.thePedalA == True: thePedal = pedal_A if self.thePedalB == True: thePedal = pedal_B if self.thePedalC == True: thePedal = pedal_C
This code works but the changes don't update till I make a change to an element in the plugin to update it. Is this the way that I should be passing info between these two functions, by global variables (this causes errors till a button is pressed), or is there another way?
-
On 17/07/2015 at 02:32, xxxxxxxx wrote:
Hello,
when you press the button Cinema cannot know that you changed internal data and want to recalculate the cache. So you have to inform Cinema that you changed something.
You can do this by sending the corresponding message the the node itself in the code that reacts to the button:
def Message(self, node, type, data) : if type==c4d.MSG_DESCRIPTION_COMMAND: if data['id'][0].id == 1010: print("button pressed") node.Message(c4d.MSG_CHANGE) return True
best wishes,
Sebastian -
On 17/07/2015 at 08:49, xxxxxxxx wrote:
Thanks for your help Sebastian.
I was afraid of this, just because with so much work figuring out what works in the GetVirtualObjects function, I'm hesitant to toss my code into a shiny new and different wrapper. I guess that the home place that I usually place my main code just needs to shift a bit to accommodate messages from input.
-David
-
On 17/07/2015 at 10:03, xxxxxxxx wrote:
Hello,
I don't really understand what you are talking about, what "wrapper" do you mean? I think all you have to do is to add the one line of code that sends the message to your code and it should work.
Best wishes,
Sebastian -
On 17/07/2015 at 10:10, xxxxxxxx wrote:
Aha! Sorry for missing your line of code Sebastian. Now it works perfectly! i guess that I got too used to disappointment to see a solution. Also, I suppose that I should avoid words such as "wrapper" that are also coding words in my posts. I meant wrapper in the wrapped gift sense.