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

    Best way to hide a child and get best perfomance

    Scheduled Pinned Locked Moved Cinema 4D SDK
    2025pythonwindows
    1 Posts 1 Posters 4 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.
    • T Offline
      Tpaxep
      last edited by Tpaxep

      Hi, forum!
      I'm working on a tool the principle of operation of which is similar like a "Sweep". It wraps one "profile" spline around a "path" spline. I want any geometric change to these splines to trigger an update. I think I've figured it out using this code.

      def GetVirtualObjects(self, op, hh):
         
          doc = op.GetDocument()
          path = op.GetDown()
          if path is None:
              return None
      
          profile = path.GetNext()
          if profile is None:
              return None
      
          dirty = op.CheckCache(hh)\
                  or op.IsDirty(c4d.DIRTY_DATA)\
                  or path.IsDirty(c4d.DIRTY_DATA)\
                  or path.IsDirty(c4d.DIRTY_MATRIX)\
                  or profile.IsDirty(c4d.DIRTY_DATA)\
                  or profile.IsDirty(c4d.DIRTY_MATRIX)
          if not dirty: return op.GetCache(hh)
      
      
          path = c4d.utils.SendModelingCommand(
              c4d.MCOMMAND_CURRENTSTATETOOBJECT,
              [path],
              c4d.MODELINGCOMMANDMODE_ALL,
              c4d.BaseContainer(),
              doc
          )[0]
      
          profile = c4d.utils.SendModelingCommand(
              c4d.MCOMMAND_CURRENTSTATETOOBJECT,
              [profile],
              c4d.MODELINGCOMMANDMODE_ALL,
              c4d.BaseContainer(),
              doc
          )[0]
      

      However, I'd like to hide the child elements, but I can't figure out how I can do it more correctly

      I have try use c4d.BaseObject.Touch() and my child is hide, but I can't edit my path/profile dynamically. If I edit the path/profile, I need to refresh the viewport or op settings to see the changes.

      I tried this code. Perhaps I didn't fully understand something and missed something.

      path = op.GetDown()
      if path is None:
          return None
      
      profile = path.GetNext()
      if profile is None:
          return None
      
      path.Touch()
      profile.Touch()
      
      dirty = op.CheckCache(hh)\
          or op.IsDirty(c4d.DIRTY_DATA)\
          or path.IsDirty(c4d.DIRTY_DATA)\
          or path.IsDirty(c4d.DIRTY_MATRIX)\
          or profile.IsDirty(c4d.DIRTY_DATA)\
          or profile.IsDirty(c4d.DIRTY_MATRIX)
      if not dirty: return op.GetCache(hh)
      

      Besides this, I tried using op.GetAndCheckHierarchyClone like it was in this thread https://developers.maxon.net/forum/topic/10491/13941_hide-child-of-object-plugin/3

      path = op.GetDown()
      if path is None:
          return None
      
      profile = path.GetNext()
      if profile is None:
          return None
      
      ProfileClone = op.GetAndCheckHierarchyClone(hh, profile, c4d.HIERARCHYCLONEFLAGS_ASSPLINE, False)
      
      ProfileCloneDirty = ProfileClone["dirty"]
      ProfileCloneClone = ProfileClone["clone"]
      
      PathClone = op.GetAndCheckHierarchyClone(hh, path, c4d.HIERARCHYCLONEFLAGS_ASSPLINE, False)
      
      PathCloneDirty = PathClone["dirty"]
      PathCloneClone = PathClone["clone"]
      
      if not ProfileCloneDirty:
          return ProfileCloneClone
      
      if not PathCloneDirty:
          return PathCloneClone
      
      path_upd = c4d.utils.SendModelingCommand(
          c4d.MCOMMAND_CURRENTSTATETOOBJECT,
          [PathCloneClone],
          c4d.MODELINGCOMMANDMODE_ALL,
          c4d.BaseContainer(),
          doc
      )[0]
      
      profile_upd = c4d.utils.SendModelingCommand(
          c4d.MCOMMAND_CURRENTSTATETOOBJECT,
          [ProfileCloneClone],
          c4d.MODELINGCOMMANDMODE_ALL,
          c4d.BaseContainer(),
          doc
      )[0]
      

      However, this reduces performance compared to the code above. I would be very grateful if you could help me figure out how I can do this more correctly and optimized.

      P.s I think my question will seem primitive, but I'm just learning the API, so don't judge me too harshly 🙂

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