Messages between objects [SOLVED]



  • On 13/04/2015 at 09:09, xxxxxxxx wrote:

    Now it is solved,

    the polygonal representation from the parametric object should be taken from current state to object.
    (like Yannick suggested)
    but the dirty state needs to be read from the cache.

    Yannick, thanks!
    Could you please explain why the cache hasn´t been updated ?
    Best wishes
    Martin

      
      
    import c4d  
    from c4d import utils, gui  
      
    global dirtyCount  
    dirtyCount = 0  
      
    def GetLink(op) :  
      udOK = False  
      for udID, udBC in op.GetUserDataContainer() :  
          if udID[1].id==1 and udID[1].dtype==c4d.DTYPE_BASELISTLINK:  
              udOK = True  
              break  
      if not udOK:  
          dialog = gui.MessageDialog("No appropriate UserData available! \n"  
                                     "Please insert a linkfield \n"  
                                     "and activate the generator again.",c4d.GEMB_OK)  
          op[c4d.ID_BASEOBJECT_GENERATOR_FLAG] = False  
          return None  
        
      link = op[c4d.ID_USERDATA,1]  
      if not link:return None  
      
      if link.GetClassification()!=c4d.Obase:  
          dialog = gui.MessageDialog("Please insert a valid object in the user data link!",c4d.GEMB_OK)  
          op[c4d.ID_BASEOBJECT_GENERATOR_FLAG] = False  
          return None  
        
      return link  
        
      
    def GetGeom(op) :  
      geom = op  
      dirty = op.GetDirty(c4d.DIRTYFLAGS_DATA|c4d.DIRTYFLAGS_MATRIX)  
      if not op.IsInstanceOf(c4d.Opolygon) :  
          settings = c4d.BaseContainer()  
          settings[c4d.MDATA_CURRENTSTATETOOBJECT_NOGENERATE] = False  
          settings[c4d.MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION] = True  
          settings[c4d.MDATA_CURRENTSTATETOOBJECT_INHERITANCE] = False  
            
          polylist = utils.SendModelingCommand(command= c4d.MCOMMAND_CURRENTSTATETOOBJECT, list= [op.GetClone()], mode =c4d.MODELINGCOMMANDMODE_ALL, bc = settings,  doc= doc)  
          if not polylist : return None  
          geom = polylist[0]  
           
          if op.GetCache().GetDeformCache() :          
              deform = op.GetCache().GetDeformCache()  
              dirty = dirty + deform.GetDirty(c4d.DIRTYFLAGS_DATA|c4d.DIRTYFLAGS_MATRIX)  
              print dirty, "parametric deform"  
      
            
      if op.GetDeformCache() :          
          deform = geom.GetDeformCache()  
          print dirty,"polygonal deform "     
          dirty = dirty + deform.GetDirty(c4d.DIRTYFLAGS_DATA|c4d.DIRTYFLAGS_MATRIX)  
          geom = deform  
      return geom,dirty  
      
      
    def main() :  
      global dirtyCount  
        
      if op[c4d.OPYTHON_OPTIMIZE] == True:  
          dialog=gui.MessageDialog("Please uncheck Optimize Cache! \n"  
                                   "and activate the generator again.",c4d.GEMB_OK)  
          op[c4d.ID_BASEOBJECT_GENERATOR_FLAG] = False   
          return c4d.BaseObject(c4d.Onull)  
        
      link = GetLink(op)  
      if not link: return c4d.BaseObject(c4d.Onull)  
        
      geom,dirty = GetGeom(link)  
      if not geom: return c4d.BaseObject(c4d.Onull)  
        
        
      #custom dirty test with linked object  
      
      if dirty != dirtyCount:          
          dirtyCount = dirty  
          op.SetDirty(c4d.DIRTYFLAGS_DATA|c4d.DIRTYFLAGS_MATRIX)  
            
        
      if not op.IsDirty(c4d.DIRTYFLAGS_DATA|c4d.DIRTYFLAGS_MATRIX) : return op.GetCache()  
      
      #parent virtual object  
      null = c4d.BaseObject(c4d.Onull)  
      child = geom.GetClone()  
      child.InsertUnder(null)  
        
      return null  
    


  • On 13/04/2015 at 09:32, xxxxxxxx wrote:

    The initial question for this topic has been solved: messaging between the generator and its linked object, more precisely getting the dirty state from the linked object (the original title of the topic isn't event not meaningful).
    Please create a new thread for new questions.



  • On 13/04/2015 at 09:54, xxxxxxxx wrote:

    Feel free to rename this thread to suit the topic, Yannick, no problem.
    That´s all not that meaningful...enjoy your finishing time
    martin



  • On 14/04/2015 at 06:19, xxxxxxxx wrote:

    Hi Martin,

    I'd really like to help you but we need to have an organized forum.

    You can create a new topic with the current script for the Python generator, the issues with it and I'll be happy to help you 🙂.


Log in to reply