Advertisement
nux95

Untitled

Sep 5th, 2011
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. import c4d
  2. from c4d.gui import MessageDialog
  3.  
  4. def main():
  5.     if not op:
  6.         # op is None, no selected object or multiple ones
  7.         MessageDialog("You must select exactly one object.")
  8.         return
  9.     if not isinstance(op, c4d.PointObject):
  10.         # selected object is not a PointObject, we cannot center the axis
  11.         MessageDialog("You must select either a spline or polygon object")
  12.         return
  13.  
  14.     points = op.GetAllPoints()
  15.  
  16.     min = c4d.Vector()
  17.     max = c4d.Vector()
  18.  
  19.     op_position = op.GetAbsPos()
  20.     for p in points:
  21.         p = p + op_position
  22.         if p.x < min.x:
  23.             min.x = p.x
  24.         if p.x > max.x:
  25.             max.x = p.x
  26.  
  27.         if p.y < min.y:
  28.             min.y = p.y
  29.         if p.y > max.y:
  30.             max.y = p.y
  31.  
  32.         if p.z < min.z:
  33.             min.z = p.z
  34.         if p.z > max.z:
  35.             max.z = p.z
  36.  
  37.     center = (min + max) / 2.
  38.     print min, max, center
  39.     # ...
  40.  
  41.     for index, p in enumerate(points):
  42.         p = p - center
  43.         points[index] = p
  44.     op.SetAllPoints(points)
  45.     """
  46.    op.SetAbsPos(op_position - center)"""
  47.  
  48.     op.Message(c4d.MSG_UPDATE)
  49.     c4d.EventAdd()
  50.  
  51. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement