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

    Set Axis to Center via Python

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 414 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 22/06/2015 at 03:59, xxxxxxxx wrote:

      Hello, 
      I would like to set axis to center of an object. And as I will use it in xpresso-python node, it should only fire for once. Position will be 0,0,0. I tried script below, please help.

      import c4d
      from c4d import Vector as v

      def setAxis(obj) :

      size = obj.GetRad()
          position = obj.GetMp() + obj.GetAbsPos()
          if obj is None or not obj.CheckType(c4d.Opoint) : return False
          oldm   = obj.GetMg()
          points = obj.GetAllPoints()
          pcount = obj.GetPointCount()
          doc.StartUndo()
          doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj)
          obj.SetAbsRot(v(0))
          obj.SetAbsPos(v(0))
          obj.Message(c4d.MSG_UPDATE)
          
          newm    = obj.GetMg()
          newm.off = position-size/2
          newm.v1 = newm.v1.GetNormalized()
          newm.v2 = newm.v2.GetNormalized()
          newm.v3 = newm.v3.GetNormalized()
          
          for p in xrange(pcount) :
              obj.SetPoint(p,newm*oldm*points
      )
              c4d.EventAdd()
              
          obj.Message(c4d.MSG_UPDATE)
          c4d.EventAdd()
          doc.EndUndo()

      def main() :
          
          global Source
          
          if Source.CheckType(c4d.Opoint) :
              setAxis(Source)

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

        On 29/06/2015 at 02:38, xxxxxxxx wrote:

        Hello,

        is this thread on the same topic as in your other thread?

        • Center Axis with Python
          if so, please avoid double posts.

        If you want to execute a python script only once you can edit and execute a script from the Script Manager. This allows you to run scripts that can edit the scene and it's objects as desired.

        A Python Xpresso Node should only be used for logic operations etc. and not to edit the current scene since the node will be executed many times.

        Best wishes,
        Sebastian

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

          On 03/07/2015 at 09:40, xxxxxxxx wrote:

          Hello grasycho,

          was your question answered?

          Best wishes,
          Sebastian

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