Advertisement
Guest User

createSpline dynamic

a guest
Jan 29th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.18 KB | None | 0 0
  1. import c4d
  2. from c4d import SplineObject
  3. from c4d import documents
  4. from c4d import BaseTag
  5. from c4d import BaseSelect
  6.  
  7. doc = c4d.documents.GetActiveDocument()
  8.  
  9. def add_spline(number_points, spline_length):
  10.     '''Returns a linear spline of a specified length that starts at the origin and extends through the y-axis'''
  11.     segment_length = spline_length / (number_points - 1)
  12.     spline = c4d.SplineObject(int(number_points), c4d.SPLINETYPE_LINEAR)
  13.    
  14.     index = 0
  15.     while index <= (int(number_points) - 1):
  16.         if index == 0:
  17.             spline.SetPoint(index, c4d.Vector())
  18.             index += 1
  19.         else:
  20.             point_pos = c4d.Vector(0, 0, int((segment_length * index)))
  21.             spline.SetPoint(index, point_pos)
  22.             index += 1
  23.     return spline
  24.  
  25. def main():
  26.     main_null = c4d.BaseObject(c4d.Onull)
  27.     # function creates a linear spline
  28.     spline = add_spline(50, 500)
  29.    
  30.     # create tags
  31.     constraint_tag_start = c4d.BaseTag(1018074)   # 1018074 //Constraint
  32.     constraint_tag_end = c4d.BaseTag(1018074)   # 1018074 //Constraint
  33.     dynamics_tag = c4d.BaseTag(1018068)     # 1018068 //Spline Dynamics
  34.    
  35.     # add dynamics tag to spline
  36.     spline.InsertTag(dynamics_tag)
  37.    
  38.     # create null
  39.     null_start = c4d.BaseObject(c4d.Onull)
  40.     null_end = c4d.BaseObject(c4d.Onull)
  41.     null_end.SetAbsPos(c4d.Vector(0,0,500))
  42.    
  43.     # insert null into anchor field for constraint tag
  44.     constraint_tag_start[c4d.HAIR_CONSTRAINTS_TAG_ANCHOR_LINK] = null_start
  45.     constraint_tag_end[c4d.HAIR_CONSTRAINTS_TAG_ANCHOR_LINK] = null_end
  46.    
  47.     # add constraint tag to spline
  48.     spline.InsertTag(constraint_tag_end)
  49.     spline.InsertTag(constraint_tag_start)
  50.    
  51.    
  52.     # select point 0 on spline (at position 0, 0, 0)
  53.     all_points = spline.GetPointS()
  54.     all_points.Select(0)
  55.  
  56.     # Add the spline and null to the scene
  57.     doc.InsertObject(spline)
  58.     doc.InsertObject(null_start)
  59.     doc.InsertObject(null_end)
  60.     doc.InsertObject(main_null)
  61.    
  62.     spline.InsertUnder(main_null)
  63.     null_start.InsertUnder(main_null)
  64.     null_end.InsertUnder(main_null)
  65.    
  66.     # set the spline to be the active object
  67.     doc.SetActiveObject(spline, 1)
  68.    
  69.     # get all tags attached to spline
  70.     tags = spline.GetTags()
  71.  
  72.     #Before we attempt to execute any buttons. Let's first update C4D about all these changes we've made first
  73.     c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW|c4d.DRAWFLAGS_NO_THREAD|c4d.DRAWFLAGS_NO_REDUCTION|c4d.DRAWFLAGS_STATICBREAK) #Update cinema 4d
  74.    
  75.     # push the button HAIR_CONSTRAINTS_TAG_SET_ANCHOR
  76.     c4d.CallButton(tags[0], 5000)   # 5000 //HAIR_CONSTRAINTS_TAG_SET_ANCHOR
  77.    
  78.     all_points.DeselectAll()
  79.     all_points = spline.GetPointS()
  80.     all_points.Select(49)
  81.  
  82.     #Before we attempt to execute any buttons. Let's first update C4D about all these changes we've made first
  83.     c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW|c4d.DRAWFLAGS_NO_THREAD|c4d.DRAWFLAGS_NO_REDUCTION|c4d.DRAWFLAGS_STATICBREAK) #Update cinema 4d
  84.        
  85.     c4d.CallButton(tags[1], 5000)   # 5000 //HAIR_CONSTRAINTS_TAG_SET_ANCHOR
  86.    
  87.    
  88.     c4d.EventAdd()
  89.  
  90. if __name__ == '__main__':
  91.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement