How to transfer variable to xpresso from Python tag


Hello everyone. I have python tag and xpresso. How can I get the variable from Python tag in xpresso?
I get an error in console “SyntaxError: can’t assign to function call”


Every Python tag and node has its own execution context, so you need to handle them like separate programs, which are executed under different triggers. So you cannot just pass a variable from one Python “something” to another Python “something” like this.

In this case, it is even more difficult as the variable seems to be set in a message function - which is triggered by the program-wide messaging system - but needs to be read by an XPresso - which is triggered during the object tree evaluation. So, the XPresso is not even part of the same execution sequence.

You need to treat both parts as separate and asynchronous sub-programs, not functions that must be called in sequence. Store the value in a User Data for example, and do not rely on the XPresso to be evaluated between a press and a release of your button at all (it may be, or it may not be).

(Provided I read your screenshot right…)


Okay, can you say me how can I change user data by id? Google haven’t helped.


User data is accessed in Python as:
where obj is the item where the user data is added, and index is the index number of the GUI control.

The following code (based on your own code) can be applied as Python tag to an object which contains one integer user data field with index 1 and a button with index 2. It will count the integer field up by 1 every time you press the button.

import c4d

def message(msg_type,data):
    if msg_type == c4d.MSG_NOTIFY_EVENT:
        event_data = data['event_data']
        if event_data['msg_id'] == c4d.MSG_DESCRIPTION_COMMAND:
            desc_id = event_data['msg_data']['id']
            if desc_id[1].id == 2:
                print "Increase"
                obj = op.GetObject()
                obj[c4d.ID_USERDATA,1] += 1 # 1 is index of an integer input field
                print "whatever"
def main():
    obj = op.GetObject()
    bc = c4d.BaseContainer()
    obj.AddEventNotification(op, c4d.NOTIFY_EVENT_MESSAGE, 0, bc)