Object Axis modification in python



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 09/11/2012 at 13:06, xxxxxxxx wrote:

    It sounds like something simple, but I'm not able to do it in Python.

    I have e.g. a plane I want to rotate, not from the center, but from a specific side.
    So, I need to change the object axis.

    But how?



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 10/11/2012 at 14:30, xxxxxxxx wrote:

    I think you can do it by change the position of the object and all his points to keep their global position.

    Here is a little code that I did one day for it :

      
        
        
        import c4d
        from c4d import Vector, Matrix
        
        def axe(objet, matrice, relatif = True) :
            if relatif : m_obj = objet.GetMl()
            else : m_obj = objet.GetMg()
            
            m = ~matrice * m_obj
            nbpts = objet.GetPointCount()
            points = objet.GetAllPoints()
            
            for i in xrange(nbpts) :
                points[i] = m.Mul(points[i])
        	
            objet.SetAllPoints(points)
            
            if relatif : objet.SetMl(matrice)
            else : objet.SetMg(matrice)
        
        def main() :
            if not op : return
            if op.GetType() != c4d.Opolygon : return
            
            doc.StartUndo()
            doc.AddUndo(c4d.UNDOTYPE_CHANGE, op)
            
            v_1    = Vector(0, 1, 0)
            v_2    = Vector(0, 0, 1)
            v_3    = Vector(1, 0, 0)
            dep    = Vector(0, 50, 0)
            mat    = Matrix(dep, v_1, v_2, v_3) # Nouvelle matrice
            
            axe(op, mat)
            
            op.Message(c4d.MSG_UPDATE)
            doc.EndUndo()
            c4d.EventAdd()
        
        if __name__=='__main__':
            main()
    
    The variable mat is the new matrix who affect op.  
    


  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/11/2012 at 04:33, xxxxxxxx wrote:

    Amazing, wonderful clever solution!
    Thanks very much.


Log in to reply