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
    • Login

    Custom Subdivide Generator

    Scheduled Pinned Locked Moved PYTHON Development
    8 Posts 0 Posters 772 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 25/07/2015 at 05:28, xxxxxxxx wrote:

      I've been experimenting with python and c4d to learn about it's basics, and made myself this python generator to subdivide the contained object.

      However, the code continues to subdivide on each mouse movement, it keeps subdividing the end result until everything is out of memory.

      What am I missing here?

      import c4d
      #Welcome to the world of Python

      def main() :
          frame=doc.GetTime().GetFrame(doc.GetFps())      
             
          child = op.GetDown()
          
          if child is None:
              return      
          
          settings = c4d.BaseContainer()
          settings[c4d.MDATA_SUBDIVIDE_SUB] = 1
          
          polyobj = op.GetAndCheckHierarchyClone(hh,child,c4d.HIERARCHYCLONEFLAGS_ASPOLY,False)["clone"]
          c4d.utils.SendModelingCommand(c4d.MCOMMAND_SUBDIVIDE,[polyobj],c4d.MODIFY_ALL,settings)
            
          return polyobj

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

        On 27/07/2015 at 00:17, xxxxxxxx wrote:

        Looking for a solution

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

          On 27/07/2015 at 05:30, xxxxxxxx wrote:

          Hello,

          GetAndCheckHierarchyClone() is an optimized function. It will return a cached polygon object if the generator or the child object are not dirty (you can actually read the C++ source code in c4d_baseobject.cpp ).

          As you know, GetAndCheckHierarchyClone() does not return an object but a dictionary. If the "dirty" value is true a new polygon copy was created based on the original object. If it is false a cached version is used and you must not apply the subdivision again.

          The Python Generator is only executed on every mouse move if you disable "Optimize Cache".

          Best wishes,
          Sebastian

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

            On 27/07/2015 at 13:51, xxxxxxxx wrote:

            I use a python generator however I don't get why it keeps getting the already subdivided model
            The line always takes the "child" object

            polyobj = op.GetAndCheckHierarchyClone(hh,child,c4d.HIERARCHYCLONEFLAGS_ASPOLY,False)["clone"]

            When I change the "False" to "True" it does not work at all. (printing polyobj returns base object instead of a polygonal object)

            I forgot to mention that the child object is a box primitive, I want this to work with primitives as well, however I don't know if this is related to the repetitive continuous subdivision problem at all?

            Edit: To clarify the problem once again:
            Even though I get the model once and apply the subdivision once (per execution) the script keeps applying the subdivision over the already subdivided model over and over. This is the behavior I want to fix.

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

              On 28/07/2015 at 02:35, xxxxxxxx wrote:

              Hello,

              as I said, GetAndCheckHierarchyClone() does not always create a new polygon copy of the given object but will return a cached polygon object if the original object did not change. Since you apply the subdivision to that polygon object, you will apply the subdivision not only once but again and again to it if it is returned again by GetAndCheckHierarchyClone().

              So you don't have to change "False" to "True" but you have to check that value and react accordingly. Something like this:

                
              result = op.GetAndCheckHierarchyClone(hh,child,c4d.HIERARCHYCLONEFLAGS_ASPOLY,False)  
                
              polyobj = result["clone"]  
                
              if result["dirty"] is True:  
                   c4d.utils.SendModelingCommand(c4d.MCOMMAND_SUBDIVIDE,[polyobj],c4d.MODIFY_ALL,settings)  
              

              best wishes,
              Sebastian

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

                On 28/07/2015 at 03:08, xxxxxxxx wrote:

                Oh, amazing!
                When "False" is changed to "True" it does not give me a polygonal object (but the base object is returned), is this how it's supposed to work?

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

                  On 28/07/2015 at 09:08, xxxxxxxx wrote:

                  Hello,

                  is your latest question actually related to the topic of your other thread: "GetAndCheckHierarchyClone & subdivision surfaces ?"?

                  best wishes,
                  Sebastian

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

                    On 28/07/2015 at 11:17, xxxxxxxx wrote:

                    Yes and no,
                    I'm just experimenting with python, both questions are related to the same experimentation however problems are different (maybe related), just opened different topics for different problems/questions to make it as clear as possible for the future newcomers like myself.

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