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

    Python Generator - Spline Outline

    Scheduled Pinned Locked Moved PYTHON Development
    2 Posts 0 Posters 349 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 07/09/2014 at 17:10, xxxxxxxx wrote:

      Hi guys,

      I'm new to Python Generators and need some help please.

      I am using this code snippet (from this forum) to dynamically create a spline Outline of the supplied child object...

      from c4d import utils as u
       
      def main() :
          nada = c4d.BaseObject(c4d.Ospline)
          
          outline = op[c4d.ID_USERDATA,1] # Userdata "meter" 
          obj     = op.GetDown()
        
          if not obj: return nada
          source = obj.GetClone()
        
          if source.CheckType(c4d.Ospline) is False: #Parametric object
              pobj   = u.SendModelingCommand(
                  command = c4d.MCOMMAND_CURRENTSTATETOOBJECT,
                  list    = [source],    
                  mode    = c4d.MODELINGCOMMANDMODE_ALL, 
                  doc     = obj.GetMain())
              source = pobj[0]
        
          bc = c4d.BaseContainer()
          bc.SetData(c4d.MDATA_SPLINE_OUTLINE, outline)
          offspline = u.SendModelingCommand(
              c4d.MCOMMAND_SPLINE_CREATEOUTLINE,
              [source],
              c4d.MODELINGCOMMANDMODE_ALL,
              bc)
        
          return source.GetClone()
      

      This all works great.

      I am wanting to make a very slight modification, so that I can opt to ONLY keep the newly created offset segment and remove the original spline from the generator output. The Python SDK suggests there is already this functionality, just like it exists with the the destructive version of this modelling tool.

      ie. MCOMMAND_SPLINE_CREATEOUTLINE by adding True flag to MDATA_SPLINE_OUTLINESEPARATE.

      However I am not sure how to implement this properly, and i suspect because it creates a new separate object beneath the generator op, i don't know how to return it properly. I've tried some silly things and nothing really works.

      Help a noob?

      Thanks guys.

      Parallel thread at CGSociety here...

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

        On 16/09/2014 at 14:46, xxxxxxxx wrote:

        Hi,

        as your source object is not a part of the generator output ,but the basic requirement for the generator itself.
        I only see this workaround to get close to what you may need.
        Build a separate object and replace it every time, like:

          
        import c4d  
        from c4d import utils as u  
           
        def main() :  
          
          if op.GetDown()==None:return  
            
          outline = op[c4d.ID_USERDATA,1] # Userdata "meter"   
          
          obj     = op.GetDown()  
          
          source = obj.GetClone()  
          
          if source.CheckType(c4d.Ospline) is False: #Parametric object  
              pobj   = u.SendModelingCommand(  
                  command = c4d.MCOMMAND_CURRENTSTATETOOBJECT,  
                  list    = [source],      
                  mode    = c4d.MODELINGCOMMANDMODE_ALL,   
                  doc     = obj.GetMain())  
              source = pobj[0]  
          
          bc = c4d.BaseContainer()  
          bc.SetData(c4d.MDATA_SPLINE_OUTLINE, outline)  
          bc.SetData(c4d.MDATA_SPLINE_OUTLINESEPARATE, True)  
          
          offspline = u.SendModelingCommand(  
              command    = c4d.MCOMMAND_SPLINE_CREATEOUTLINE,  
              list       = [source],  
              mode       = c4d.MODELINGCOMMANDMODE_ALL,   
              bc         = bc,  
              doc        = obj.GetMain())  
          
          #instead of let the generator creating an object directly  
          #do this set and replace code  
          offspline[0].SetName("Offset")  
          #insert a new offset spline under the source object  
          if obj.GetDown()==None:  
              doc.InsertObject(offspline[0],obj)  
          #if there is already a offsetspline replace it with the new settings  
          else:  
              spline=obj.GetDown()  
              spline.Remove()  
              doc.InsertObject(offspline[0],obj)  
          
          return   
        

        hope that helps
        martin

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