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

    Node Method IsValid() Throws ValueError

    Cinema 4D SDK
    python r25
    3
    5
    439
    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.
    • B
      bentraje
      last edited by bentraje

      Hi,

      I'm trying to write a script that modify the selected nodes only if the node is an RS Texture node. And the way I can know if its an RS Texture Node is if it has the tex0 attribute (see below)

      My logic is something like this:

      rs_texture_node = node.GetInputs().FindChild("com.redshift3d.redshift4c4d.nodes.core.texturesampler.tex0")
      
      if rs_texture_node.IsValid():
             # Do something here
      

      It works if the node selected is a texture node but throws a ValueError: no target to copy for '<net.maxon.graph.interface.graphmodel>' if its otherwise.

      Which I don't get. It's either the node/port is valid or not. Why throw an error?

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

        Hello @bentraje,

        Thank you for reaching out to us. This is an error which is raised in the C++ part of our Python API (and not just the Python frameworks trampoline code). It happens when something is meant to be wrapped into a CPyObject (so that Python can deal with it) and the something is a null pointer.

        Without executable code it will be hard for us to replicate your problem. As always, you can send code to us privately via sdk_support(at)maxon(dot)net. In the meantime you could try if you have better luck with maxon.Data.IsNullValue() which we have added with 2023.0.0. It tests for a reference being the empty reference, i.e., what you want to do here. maxon.GraphNode is an instance of maxon.Data. So, you would have to do this isNull: bool = rs_texture_node.IsNullValue(). When you search for garbage, e.g., FindChild("blahblah"), the value should be true.

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

        B 1 Reply Last reply Reply Quote 0
        • B
          bentraje @ferdinand
          last edited by

          @ferdinand

          Thanks for response.

          RE: added 2023.
          I'm still at R25 so I can't use that route unfortunately.

          Anyhow, I just settled on the GetId() which works the same way. It's just that doing a split method is bit awkward.

          if node.GetId().split("@")[0] == 'texturesampler':
          
                  texPort = node.GetInputs().FindChild("com.redshift3d.redshift4c4d.nodes.core.texturesampler.tex0")
                  # do something more for the texPort
          
          1 Reply Last reply Reply Quote 0
          • M
            m_adam
            last edited by

            Hi @bentraje, as Ferdinand said without more code is hard to help you. Happy that you solved it, I just wanted to warn you that your code will not work anymore in newer version, since in 2023.0 everything that return a maxon.Id, does return a maxon.Id and not anymore a python string. So if yo uwant to be future proof, use if str(node.GetId()).split("@")[0] == 'texturesampler':

            Cheers,
            Maxime.

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

            B 1 Reply Last reply Reply Quote 0
            • B
              bentraje @m_adam
              last edited by

              @m_adam

              Gotcha. Thanks for the heads up!

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