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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Object Axis modification in python

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 463 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

      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?

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

        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.  
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          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.

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