PYTHON GENERATOR ISSUES



  • I want to use python generator to return cloner object. and clone object "A" on the object "B" surface, but it's return odd result, I don't know what step is wrong.

    And this is my python code here:

    import c4d
    #Welcome to the world of Python
    
    def main():
        cloner = c4d.BaseObject(1018544)
        sphere = c4d.BaseObject(c4d.Osphere).GetClone(0)
        
        plane = c4d.BaseObject(c4d.Oplane).GetClone(0)
        
        bc = c4d.BaseContainer()
        bc.SetLong(c4d.ID_MG_MOTIONGENERATOR_MODE,0)
        bc.SetLink(c4d.MG_OBJECT_LINK,plane)
        
        cloner.SetData(bc)
        sphere.InsertUnder(cloner)
        
        return cloner
    
    


  • I don't know what "odd result" means, but just from looking at the code: the plane is local to main() and you don't insert it anywhere in your cloner hierarchy, so the link that points to it becomes invalid when you leave the function.

    Also, you overwrite your cloner's complete base container? Not sure whether that works this way. Try setting only the relevant data.

    Also, cloning brand new objects seems unnecessary to me.

    import c4d
    #Welcome to the world of Python
    
    def main():
        cloner = c4d.BaseObject(1018544)
        sphere = c4d.BaseObject(c4d.Osphere)
        null = c4d.BaseObject(c4d.Onull)
        plane = c4d.BaseObject(c4d.Oplane)
        
        cloner[c4d.ID_MG_MOTIONGENERATOR_MODE] = 0
        cloner[c4d.MG_OBJECT_LINK] = plane
        
        cloner.InsertUnder(null)
        plane.InsertUnder(null)
        sphere.InsertUnder(cloner)
    
        return null
    

    Also, the default count for the cloner is 20, so there will only be 20 spheres appear on the plane.
    Also, the spheres are very big in comparison with the plane.



  • @Cairyn
    Thank you for your reply.
    The "odd result" it's means the scene is empty , no objects were generated.
    According to your explanation, I have solved the problem.
    And it's just an exercise code.
    Thank you again !


Log in to reply