How to Show Nodes API Nodes in the Node Editor?

And It is possiable to expose a inport without a input node?
AKA : can I do this when I create node mat in python?

Hello @dunhou,

Thank you for reaching out to us. Could you please clarify what you mean by "expose an inport without an input node"? The command "Show in Node Editor" will reveal the node on which this command has been invoked. When a port has no input, i.e., there is no node, then there is nothing to reveal.

Maybe I am not aware of a functionality of Cinema 4D here or misunderstanding you?


I want to create a Node mat with some pre-exposed ports(python)(It's painful to search so many daily port) ,like this picture said:

  1. By default , there is no Transmision Color port on the material, I want to expose some ports I always used without connect with a node input.
  2. It's like 2 and 3 in the picture, can I do this Show in Node Editor command function when I create my custom materials?

Hi @Dunhou, you should define the value maxon.NODE.ATTRIBUTE.HIDEPORTINNODEGRAPH of the port to False like so port.SetValue(maxon.NODE.ATTRIBUTE.HIDEPORTINNODEGRAPH, maxon.Bool(False)). When calling SetValue it is important to pass a maxon data as the current Python system is not able to automatically guess the expected result.

Find bellow a more complete example that expect you selected a Standard Node Material and will expose all fresnel port of all BSDF node in the node editor.

import c4d
import maxon
from c4d import gui

# Main function
def main():
    mat = doc.GetActiveMaterial()
    if mat is None:
        raise ValueError("can't create a BaseMaterial")

    # Retrieve the graph of the current NodeSpace
    nodespaceId = c4d.GetActiveNodeSpaceId()
    nimbusRef = mat.GetNimbusRef(nodespaceId)
    if nimbusRef is None:
        raise ValueError("can't retrieve the nimbus ref for that node space")
    graph = nimbusRef.GetGraph()
    if graph is None:
        raise ValueError("can't retrieve the graph of this nimbus ref")

    # Assume that the given node is a BSDF node and will display it's Fresnel port.
    # This function  will be passed to FindNodesByAssetId.
    def DisplayFresnelonBSDF(node):
        fresnelPort = node.GetInputs().FindChild("fresneltype")
        if not fresnelPort:
            raise ValueError("can't find a fresnel port")
        # Display the port in the node editor
        with graph.BeginTransaction() as tr:
            # This is mandatory to use a maxon.Bool, as Python is not able to 
            # deduce the expected type in this situation.
            fresnelPort.SetValue(maxon.NODE.ATTRIBUTE.HIDEPORTINNODEGRAPH, maxon.Bool(False))
        return True

    # Execute DisplayFresnelonBSDF on all BSDF nodes of the graph    
    maxon.GraphModelHelper.FindNodesByAssetId(graph, "net.maxon.render.node.bsdf", False, DisplayFresnelonBSDF)

# Execute main()

if __name__=='__main__':