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

    If clone is inside falloff - freeze position. PyMo

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 512 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 09/09/2015 at 05:39, xxxxxxxx wrote:

      Hello!

      Can anybody point me in the right direction to what I'm doing wrong here?

      I can see how many clones are inside the falloff and access their index, but can't set/fix their position
      whilst they are inside the falloff region 😞

      Here is my code so far:

      __________________________
      import c4d
      from c4d.modules import mograph as mo

      def main() :

      md = mo.GeGetMoData(op)
          if md==None: return False
          
          cnt = md.GetCount()
          marr = md.GetArray(c4d.MODATA_MATRIX)
          fall = md.GetFalloffs()
          carr = md.GetArray(c4d.MODATA_COLOR)
          MoColAr = md.GetArray(c4d.MODATA_COLOR)
         
          
          l = [] # Empty list to store falloff clones
          
          for i in xrange(0, cnt) :
              if fall == 1:
      _            l2 = i_
      _            l.append(l2)_
      _    _
      _    print "Number of clones inside fall off ", len(l)_
      _    #print "Falloff cloner index values: ", l   _
      _    _
      _    _
      _    for i in xrange (len(l)) :_
      _        print marr ___
      _ _        marr = marr _____
      _ _ _        #MoColAr = c4d.Vector(0)
      __
      _ _ _    ___
      _ _ _    md.SetArray(c4d.MODATA_Matrix, marr, True)___
      _ _ _    #md.SetArray(c4d.MODATA_COLOR, MoColAr, True)___
      _ _ _    ___
      _ _ _    #b = "Number of clones inside falloff = " + str(len(l))___
      _ _ _    #c4d.StatusSetText(b)___
      _ _ _   ___
      _ _ _    ___
      _ _ _    return True___
      _ _ __________________________________


      _ _ Any help on this would be much appreciated! -  Thank you in advance!__



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

        On 09/09/2015 at 06:29, xxxxxxxx wrote:

        Hi
        Some mods and fix typos mad and seems, all work - video demo

        i use

        marr _.off = c4d.Vector(0)_
        

        _to freeze position

        import c4d  
        from c4d.modules import mograph as mo  
          
        def main() :  
          md = mo.GeGetMoData(op)  
          if md==None: return False  
            
          cnt = md.GetCount()  
          marr = md.GetArray(c4d.MODATA_MATRIX)  
          fall = md.GetFalloffs()  
          carr = md.GetArray(c4d.MODATA_COLOR)  
          MoColAr = md.GetArray(c4d.MODATA_COLOR)  
          
            
          l = [] # Empty list to store falloff clones  
          for i in xrange(0, cnt) :  
              if fall[i] > 0:  
                  l2 = i  
                  l.append(l2)  
            
          print "Number of clones inside fall off ", len(l)  
          #print "Falloff cloner index values: ", l     
            
            
          for i in xrange (len(l)) :  
              print marr  
              marr[i].off = c4d.Vector(0)  
              md.SetArray(c4d.MODATA_MATRIX, marr, True)  
              #MoColAr = c4d.Vector(0)  
            
          md.SetArray(c4d.MODATA_MATRIX, marr, True)  
          #md.SetArray(c4d.MODATA_COLOR, MoColAr, True)  
            
          #b = "Number of clones inside falloff = " + str(len(l))  
          #c4d.StatusSetText(b)  
          return True
        

        _

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

          On 09/09/2015 at 12:50, xxxxxxxx wrote:

          Thanks for your help Ilya, really appreciate it!

          The issue I'm having is that i want to freeze the clones in its current position.... It seems trickier than it sounds! 😢

          Appending marr.off and passing back doesn't work as the marr.off value is constantly calculated.
           I'm trying tuples without any luck!

          Thanks again! If you have any ideas let me know!

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

            On 15/09/2015 at 07:07, xxxxxxxx wrote:

            Hi,

            I played around with this. Here's what I came up with:

            import c4d
            from c4d.modules import mograph as mo
              
            # two global arrays
            fixed = [] # stores for each clone, if it is currently fixed
            pos = []   # stores fixed position for each clone
              
            def main() :
                md = mo.GeGetMoData(op)
                if md==None: return False
              
                cnt = md.GetCount()
                marr = md.GetArray(c4d.MODATA_MATRIX)
                fall = md.GetFalloffs()
              
                # extend and initialize list to match number of clones, if needed
                if len(fixed) < cnt:
                    for i in xrange(len(fixed), cnt) :
                        fixed.extend([False])
                        pos.extend([c4d.Vector(0.0, 0.0, 0.0)])
                
                # walk all clones
                for i in xrange(0, cnt) :
                    if fall[(cnt - 1) - i] > 0.0: # NOTE: content of the falloffs array is reverse
                        # Clone is inside falloff
                        if fixed[i] == False: # if not yet fixed, we store the position and mark it fixed
                            pos[i] = marr[i].off
                            fixed[i] = True
                        marr[i].off = pos[i]
                    else:
                        # Clone is outside falloff, so we release it (do not touch marr[i].off)
                        fixed[i] = False
                
                # finally don't forget to update the MoData with our changed matrices
                md.SetArray(c4d.MODATA_MATRIX, marr, True)
                return True
            

            Note 1: GetFalloffs() returns the results in the inverse order compared with the other MoData arrays. I'm still investigating, what's the reason for this behavior (maybe to have same behavior as good old COFFEE...). As soon as I have found out, I'll add a note to the docs.

            Note 2: For simplicity I used global arrays in my example. Of course you may also store the values in the object's or effectors BaseContainer (using a valid PluginID) or you could add User Data to store the values.

            Hope this helps.

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

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

              Thank you Andreas, great work! I didn't think to include the lists outside of the main function, and haven't used .extend before. I'm going to make sure I fully understand this - but it's working great!

              Thank you once again,

              Simon

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