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

    Github Example group_nodes_r26 is broken.

    Cinema 4D SDK
    sdk python 2023
    2
    4
    467
    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

      Hi there !

      I want wo get selected node or wires , but the github group_nodes_r26 has a problem happened, and I didn't find IsSelected . how do I fix this?

      here is my material:
      9903e008-2f83-4e29-aebf-4f500c858e4e-image.png

      here is the console feedback:

      Traceback (most recent call last):
        File "C:\Program Files\Maxon Cinema 4D 2023\resource\modules\python\libs\python310\maxon\data.py", line 84, in __getattribute__
          return Data_GetMember(self, name, o)
      AttributeError
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "scriptmanager", line 68, in <module>
        File "scriptmanager", line 51, in main
        File "C:\Program Files\Maxon Cinema 4D 2023\resource\modules\python\libs\python310\maxon\data.py", line 86, in __getattribute__
          return object.__getattribute__(self, name)
      AttributeError: 'GraphNode' object has no attribute 'IsSelected'
      

      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 and for pointing out the error in this script.

        The script has not been updated yet for 2023 and is still using old Nodes API calls. The S26 method maxon.GraphNode.IsSelected was already deprecated in S26 in favor of the S26 method maxon.GraphModelHelper.IsNodeSelected. In 2023, the GraphNode method has been removed and you now must use maxon.GraphModelHelper.IsNodeSelected (2023.2).

        I.e., you must change this:

        # Create a list of the selected ones.
        selectedNodes = []
        
        for node in nodes:
            if node.IsSelected():
                selectedNodes.append(node)
        

        to this:

        # Create a list of the selected ones.
        selectedNodes = []
        
        for node in nodes:
            if maxon.GraphModelHelper.IsNodeSelected(node):
                selectedNodes.append(node)
        

        As an FYI: A lot of functionalities have been moved from GraphNode and GraphModelRef to GraphModelHelper. We will update the GitHub script/provide a new one for 2023. Find below the full script updated for 2023.

        Cheers,
        Ferdinand

        Code:

        """
        Copyright: MAXON Computer GmbH
        Author: Manuel Magalhaes
        Description:
            Retrieve the selected node material and group the node that are selected.
            
        Class/method highlighted:
            - MoveToGroup
            - IsSelected
        """
        import c4d
        import maxon
        
        
        def main():
            # Retrieve the selected BaseMaterial
            mat = doc.GetActiveMaterial()
            if mat is None:
                raise ValueError("There is no selected BaseMaterial")
        
            # Retrieve the reference of the material as a node material.
            nodeMaterial = mat.GetNodeMaterialReference()
            if nodeMaterial is None:
                raise ValueError("Cannot retrieve node material reference")
        
            # Retrieve the current node space Id
            nodespaceId = c4d.GetActiveNodeSpaceId()
        
            # Retrieve the Nimbus reference for a specific node space
            nimbusRef = mat.GetNimbusRef(nodespaceId)
            if nimbusRef is None:
                raise ValueError("Cannot retrieve the nimbus ref for that node space")
        
            # Retrieve the graph corresponding to that node space.
            graph = nimbusRef.GetGraph()
            if graph is None:
                raise ValueError("Cannot retrieve the graph of this nimbus ref")
        
            # Get the root of the GraphNode
            root = graph.GetRoot()
        
            # Retrieve all nodes, child of the root node
            nodes = []
            root.GetChildren(nodes, maxon.NODE_KIND.NODE)
        
            # Create a list of the selected ones.
            selectedNodes = []
        
            for node in nodes:
                if maxon.GraphModelHelper.IsNodeSelected(node):
                    selectedNodes.append(node)
        
            # Group all the selected nodes in an empty node.
            groupRoot = maxon.GraphNode()
        
            # To modify a graph, modification must be done inside a transaction. After
            # modifications are done, the transaction must be committed.
            with graph.BeginTransaction() as transaction:
                graph.MoveToGroup(groupRoot, maxon.Id("idOfMyGroup"), selectedNodes)
                transaction.Commit()
        
            # Pushes an update event to Cinema 4D
            c4d.EventAdd()
        
        
        if __name__ == "__main__":
            main()
        

        MAXON SDK Specialist
        developers.maxon.net

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

          @ferdinand Hei thanks for point that, it worked as expected .

          I noticed maxon api changed every version and almost the major part of sdk change log , and maxon api is not like c4d old api ( is more friendly to a beginner ) I know it's been repeated over and over,but more github examples please, 👏

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

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

            Hello @Dunhou,

            I noticed maxon api changed every version and almost the major part of sdk change log

            We are aware that this fact is disliked by especially technical artists. But the Nodes API is still under active development and probably will be for the intermediate foreseeable future. Some changes from time to time are therefore inevitable. But we usually do not just remove something, but first mark it as deprecated and then remove it one or two cycles later, giving third parties more time to adapt. For S26, GraphModelInterface::IsSelected in graph.h changed for example into this:

            [[deprecated("Use GraphModelHelper static functions")]] MAXON_METHOD Result<Bool> IsSelected(const GraphNode& node);
            

            The problem is that this information is not visible at all for Python developers and still could also be improved for C++. We are aware of the problem, and working on the quality of change notes is something we already did over the last cycles and are still doing. Mapping such information to Python is certainly something I would like to do, but my main focus was for now gathering C++ API change notes in a more consistent manner. For now, I would recommend having an eye on the C++ change notes as a Python developer. The color coded deprecated markup should make it fairly easy to find upcoming removals, see for example the 2023.2 C++ API change notes.

            We are still working on improving API change notes for C++ and Python, because we are aware that it is crucial to clearly communicate our intentions with an API. I for example would like to make such information more searchable or pull it into the relevant documentary units. I.e., pull change notes also into the class, method, etc. descriptions, which are the subject of change. But that will be very hard to do with our current solutions might therefore have to wait a bit.

            Cheers,
            Ferdinand

            MAXON SDK Specialist
            developers.maxon.net

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