Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    How to Show Nodes API Nodes in the Node Editor?

    Cinema 4D SDK
    3
    5
    733
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DunhouD
      Dunhou
      last edited by

      And It is possiable to expose a inport without a input node?
      AKA : can I do this when I create node mat in python?
      416e097b-e450-42d8-9c1a-7f13385c6f9a-image.png

      https://boghma.com
      https://github.com/DunHouGo

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @Dunhou
        last edited by

        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?

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

        DunhouD 1 Reply Last reply Reply Quote 0
        • DunhouD
          Dunhou @ferdinand
          last edited by

          @ferdinand
          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?
            b34251ca-8ecc-4bd4-9bc9-38422b8b01b0-image.png

          https://boghma.com
          https://github.com/DunHouGo

          1 Reply Last reply Reply Quote 0
          • M
            m_adam
            last edited by

            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))
                        tr.Commit()
                    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__':
                main()
            

            Cheers,
            Maxime.

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

            DunhouD 1 Reply Last reply Reply Quote 1
            • DunhouD
              Dunhou @m_adam
              last edited by

              @m_adam
              Great Help!
              Thanks a lot for your help, the code works pretty well.
              I can go further with my works .

              https://boghma.com
              https://github.com/DunHouGo

              1 Reply Last reply Reply Quote 0
              • First post
                Last post