Solved how to control the on/off of a node in expresso?

I want to control the on/off of a node in expresso.
and i found the "on" attribute can do it.
but I can't add the input port in python.
anyone can help me ?
thank you very much!

Hi @milkliu

Please provides us more information about the initial setup and the expected behavior.
Are you trying to control the enable state of the current python node, or any other nodes?
Should these nodes be linked together?


I guess you want to create a node of the node.
alt text

sorry,I should put more information about my question.
I want to add the "on" port in the gif below use python.

alt text

Do you want to add the port with a script from the script manager or a Python GvNode?

@m_adam I want to add it with a script from the script manager

Hi @milkliu,

Unfortunately, I do have bad news, after some research it's currently not possible to add the "On" port in Python due to a bug.

With that's said here is an example of how to creates Node and Port in Xpresso. (As I said it does not work for the On port, and some generics ports so this example will currently not work)

import c4d

def main():
    # Checks if selected object is valid
    if op is None:
        raise ValueError("op is none, please select one object.")

    # Retrieves the xpresso Tag
    xpressoTag = op.GetTag(c4d.Texpresso)
    if xpressoTag is None:
        raise ValueError("Make sure the selected object get an Xpresso Tag.")

    # Retrieves the node master
    gvNodeMaster = xpressoTag.GetNodeMaster()
    if gvNodeMaster is None:
        raise RuntimeError("Failed to retrieves the Node Master.")

    # Retrieves the Root node (the Main XGroup) that holds all others nodes
    gvRoot = gvNodeMaster.GetRoot()
    if gvRoot is None:
        raise RuntimeError("Failed to retrieves the Root Node.")

    # Creates a Link node in the GvRoot
    linkNode = gvNodeMaster.CreateNode(gvRoot, c4d.ID_OPERATOR_OBJECT, x=100, y=100)
    if linkNode is None:
        raise RuntimeError("Failed to creates the link Node.")

    # Defines the target of the link node to the host object of the Xpresso (in this case objHost, is the same as op)
    objHost = linkNode.GetNodeMaster().GetOwner().GetObject()
    linkNode[c4d.GV_OBJECT_OBJECT_ID] = objHost

    # Creates the "On" Port
    onPort = None
    if linkNode.AddPortIsOK(c4d.GV_PORT_INPUT, c4d.GV_OBJECT_OPERATOR_ON):
        onPort = linkNode.AddPort(c4d.GV_PORT_INPUT, c4d.DescID(c4d.DescLevel(c4d.GV_OBJECT_OPERATOR_ON)), c4d.GV_PORT_FLAG_IS_VISIBLE, True)

    if onPort is None:
        raise RuntimeError("Failed to creates the On Port.")

    # Updates Cinema 4D

if __name__ == '__main__':

Hopefully, it will be fixed in the next release, but I can't promise anything.
In any case, I will bump this thread when the fix is available.

@m_adam Although I didn't get a solution to this problem, I found a solution to my own problem. Thank you very much.

This issue is now fixed in R21.