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
    • Recent
    • Tags
    • Users
    • Register
    • Login

    Objects with tags inside python generator

    Scheduled Pinned Locked Moved PYTHON Development
    17 Posts 0 Posters 1.7k Views
    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.
    • H Offline
      Helper
      last edited by

      On 21/09/2015 at 09:42, xxxxxxxx wrote:

      Hello,

      like most classes of the API, GvNode ist based on BaseList2D and GeListNode. This means you can get the child objects of the root node with GeListNode.GetDown(). Then you can loop through the nodes using GeListNode. GetNext().

      As long as your questions are related to the topic of creating Xpresso nodes you can continue in this threads. For other questions please open a new thread.

      Best wishes,
      Sebastian

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 21/09/2015 at 13:31, xxxxxxxx wrote:

        Nice! Thank you.

        I'm able to get node's ID with this script. I leave it here so it might be helpful for those who are struggling with same problem.

        (Run in Script Manager)

        import c4d  
          
        # make xpresso tag and node manually  
        # select xpresso tag and run the script  
          
        def main() :  
          selection = doc.GetSelection()  
            
          for x in selection:  
                
              nm = x.GetNodeMaster()  
              root = nm.GetRoot()  
            
              firstNode = root.GetDown()          
              firstNodeID = firstNode.GetOperatorID()  
                
              print firstNodeID  
            
          c4d.EventAdd()  
          
        if __name__=='__main__':  
          main()  
        

        I'm almost there. Messing with ports are now giving me a headache.

        nm = x.GetNodeMaster()  
        root = nm.GetRoot()  
          
        objectNode = nm.CreateNode(nm.GetRoot(), 400001000, None, 0, 0)  
        objectIndexNode = nm.CreateNode(nm.GetRoot(), 400001152, None, 0, 0)  
          
        # Check it is OK to add port?  
        print objectNode.AddPortIsOK(c4d.GV_PORT_INPUT, c4d.GV_OBJECT_OPERATOR_OBJECT_IN)  
         **# prints True - everything should be fine**  
          
        # Try to add port  
        objectNode.AddPort(c4d.GV_PORT_INPUT, c4d.GV_OBJECT_OPERATOR_OBJECT_IN)  
         **# Nothing happens - port does not appear**  
          
        # Try to connect two ports  
        portA_IN = objectNode.GetInPort(0)  
        portB_OUT = objectIndexNode.GetOutPort(0)         
        portA_IN.Connect(portB_OUT)  
         **# AttributeError: 'NoneType' object has no attribute 'Connect'** 
        

        I'm not sure what is wrong.

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 22/09/2015 at 00:16, xxxxxxxx wrote:

          Hello,

          currently there is a bug with creating object ports. See "OBJECT_OPERATOR_OBJECT_OUT".

          best wishes,
          Sebastian

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            On 22/09/2015 at 07:14, xxxxxxxx wrote:

            Hi and thanks,

            So there is way to go around that object port bug with user data field. Very nice!

            I'm also able to add other kind of ports to nodes, but when I try to connect two ports together, no matter what nodes type is, I get error message: **AttributeError: 'NoneTpye' object has no attribute 'Connect'.
            **
            Sample code

            formulaNode = nm.CreateNode(nm.GetRoot(), 400001133, None, 0, 0)  
            mathNode = nm.CreateNode(nm.GetRoot(), 400001121, None, 0, 0)  
                
            portA = mathNode.GetPort(c4d.GV_MATH_INPUT)  
            portB = formulaNode.GetPort(c4d.GV_FORMULA_OUTPUT)  
                    
            portA.Connect(portB)
            
            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              On 22/09/2015 at 10:21, xxxxxxxx wrote:

              Hello,

              the problem is that the ports could not be found. Access the ports by the index:

                
              portA = mathNode.GetInPort(0)  
              portB = formulaNode.GetOutPort(0)  
                
              portA.Connect(portB)  
              

              best wishes,
              Sebastian

              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

                On 23/09/2015 at 00:28, xxxxxxxx wrote:

                Thank you so much!

                Now everything makes sense. Now I'm gonna work with this my thing and I will share the final product when and if I get it done.

                1 Reply Last reply Reply Quote 0
                • H Offline
                  Helper
                  last edited by

                  On 23/09/2015 at 12:48, xxxxxxxx wrote:

                  Hi,

                  I'm having now weird problems. Adding object port with DescID is not working. I'm using command:

                  basenode.AddPort(c4d.GV_PORT_OUTPUT, c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA, c4d.DTYPE_SUBCONTAINER, 0), c4d.DescLevel(1)), message = True)
                  

                  I "emulated" the problem with manually made objects and script manager.

                  Null
                  -->Cloner

                  This code works perfectly:

                  import c4d  
                    
                  def main() :  
                    #doc = c4d.documents.GetActiveDocument()  
                    #pointobject = doc.GetActiveObject()  
                       
                    userdata = c4d.GetCustomDatatypeDefault(c4d.DTYPE_BASELISTLINK)  
                    userdata[c4d.DESC_NAME] = "Object Data"  
                    
                    child = op.GetDown()  
                      
                    linkobject = child.AddUserData(userdata)  
                    child[linkobject] = child  
                    
                    xpressotag = c4d.BaseTag(c4d.Texpresso)  
                    xpressotag.SetName("PointLock XPresso")  
                      
                    child.InsertTag(xpressotag)  
                      
                    nodemaster = xpressotag.GetNodeMaster()  
                    basenode = nodemaster.CreateNode(nodemaster.GetRoot(), c4d.ID_OPERATOR_OBJECT, None, 100, 100)  
                      
                    basenodeobjectoutput = basenode.AddPort(c4d.GV_PORT_OUTPUT, c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA, c4d.DTYPE_SUBCONTAINER, 0),\  
                  c4d.DescLevel(1)), message = True)  
                      
                    #basenodepositionoutput = basenode.AddPort(c4d.GV_PORT_OUTPUT, c4d.ID_BASEOBJECT_REL_POSITION)  
                    #c4d.modules.graphview.RedrawMaster(nodemaster)  
                    
                      
                    c4d.EventAdd()  
                    
                  if __name__=='__main__':  
                    main()
                  

                  But when I try to run same kind of code with python generator it is not making the object port. I also first need to insert cloner under null object and return the null to get user data field to cloner. If I try to return only the cloner it comes without user data. Is it the bug or do I need to play with DescID?

                  1 Reply Last reply Reply Quote 0
                  • H Offline
                    Helper
                    last edited by

                    On 24/09/2015 at 00:53, xxxxxxxx wrote:

                    Hello,

                    in a Script Manager script "op" refers to the currently selected object. In a Python Generator it refers to the Generator Object. Maybe this is the difference.

                    Best wishes,
                    Sebastian

                    1 Reply Last reply Reply Quote 0
                    • H Offline
                      Helper
                      last edited by

                      On 24/09/2015 at 07:21, xxxxxxxx wrote:

                      Hi,

                      I know that. I'm not using op variable in Python Generator.

                      1 Reply Last reply Reply Quote 0
                      • H Offline
                        Helper
                        last edited by

                        On 24/09/2015 at 09:40, xxxxxxxx wrote:

                        Hello,

                        what code do you use in your Python Generator?

                        Best wishes,
                        Sebastian

                        1 Reply Last reply Reply Quote 0
                        • H Offline
                          Helper
                          last edited by

                          On 24/09/2015 at 14:01, xxxxxxxx wrote:

                          Hello,

                          I'm using this code in Python Generator.

                          import c4d  
                            
                          def main() :  
                            nul = c4d.BaseObject(5140)                                      # create a null  
                            clr = c4d.BaseObject(1018544)                                   # create a cloner  
                            link = op[c4d.ID_USERDATA,2]                                    # object  
                            num = 5                                                         # number  
                            userdata = c4d.GetCustomDatatypeDefault(c4d.DTYPE_BASELISTLINK) # user data type  
                            userdata[c4d.DESC_NAME] = "Object Data"                         # user data name  
                            clr.InsertUnder(nul)                                            # insert cloner under the null  
                            clr[c4d.ID_MG_MOTIONGENERATOR_MODE] = 0                         # set cloner to object mode  
                            clr[c4d.MG_OBJECT_LINK] = link                                  # link object to cloner  
                             
                            ###     
                             
                            # create user data field  
                            linkobject = clr.AddUserData(userdata)  
                            clr[linkobject] = clr  
                            
                            # xpresso stuff  
                            xpressotag = c4d.BaseTag(c4d.Texpresso)  
                            clr.InsertTag(xpressotag)  
                            nodemaster = xpressotag.GetNodeMaster()  
                              
                            # create nodes  
                            basenode = nodemaster.CreateNode(nodemaster.GetRoot(), c4d.ID_OPERATOR_OBJECT, None, 100, 100)  
                            datanode = nodemaster.CreateNode(nodemaster.GetRoot(), 1019010, None, 0, 0)  
                              
                            # create ports  
                            basenode.AddPort(c4d.GV_PORT_OUTPUT, c4d.DescID\  
                            (c4d.DescLevel(c4d.ID_USERDATA, c4d.DTYPE_SUBCONTAINER, 0), c4d.DescLevel(1)), message = True)  
                              
                            # create connections  
                            basenodeobjectoutput = basenode.GetOutPort(0)  
                              
                            datanodeinput = datanode.GetInPort(0)  
                            datanodeoutput = datanode.GetOutPort(0)  
                              
                            basenodeobjectoutput.Connect(datanodeinput)                     # << error >>  
                            
                            ####  
                            
                            for i in xrange(num) :  
                                obj = c4d.BaseObject(5159)                                  # base spline text  
                                obj.InsertUnderLast(clr)                                    # insert clone under the cloner  
                            
                            # return final object  
                            return nul  
                          

                          If I don't insert cloner under the null object I don't get user data tab to the cloner.

                          1 Reply Last reply Reply Quote 0
                          • H Offline
                            Helper
                            last edited by

                            On 25/09/2015 at 09:05, xxxxxxxx wrote:

                            Hello,

                            it seems that you are using the "op" variable in line 6 of your code. In the code you provided "basenodeobjectoutput" is not defined.

                            You are creating a Object Node without defining what object this node should reference. You can define the referenced object by setting the GV_OBJECT_OBJECT_ID parameter. Something like this:

                              
                            objectNode.SetParameter(c4d.GV_OBJECT_OBJECT_ID, linkedObject, c4d.DESCFLAGS_SET_0)  
                            

                            best wishes,
                            Sebastian

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