Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import c4d
- from c4d import SplineObject
- from c4d import documents
- from c4d import BaseTag
- from c4d import BaseSelect
- doc = c4d.documents.GetActiveDocument()
- def add_spline(number_points, spline_length):
- '''Returns a linear spline of a specified length that starts at the origin and extends through the y-axis'''
- segment_length = spline_length / (number_points - 1)
- spline = c4d.SplineObject(int(number_points), c4d.SPLINETYPE_LINEAR)
- index = 0
- while index <= (int(number_points) - 1):
- if index == 0:
- spline.SetPoint(index, c4d.Vector())
- index += 1
- else:
- point_pos = c4d.Vector(0, 0, int((segment_length * index)))
- spline.SetPoint(index, point_pos)
- index += 1
- return spline
- def main():
- main_null = c4d.BaseObject(c4d.Onull)
- # function creates a linear spline
- spline = add_spline(50, 500)
- # create tags
- constraint_tag_start = c4d.BaseTag(1018074) # 1018074 //Constraint
- constraint_tag_end = c4d.BaseTag(1018074) # 1018074 //Constraint
- dynamics_tag = c4d.BaseTag(1018068) # 1018068 //Spline Dynamics
- # add dynamics tag to spline
- spline.InsertTag(dynamics_tag)
- # create null
- null_start = c4d.BaseObject(c4d.Onull)
- null_end = c4d.BaseObject(c4d.Onull)
- null_end.SetAbsPos(c4d.Vector(0,0,500))
- # insert null into anchor field for constraint tag
- constraint_tag_start[c4d.HAIR_CONSTRAINTS_TAG_ANCHOR_LINK] = null_start
- constraint_tag_end[c4d.HAIR_CONSTRAINTS_TAG_ANCHOR_LINK] = null_end
- # add constraint tag to spline
- spline.InsertTag(constraint_tag_end)
- spline.InsertTag(constraint_tag_start)
- # select point 0 on spline (at position 0, 0, 0)
- all_points = spline.GetPointS()
- all_points.Select(0)
- # Add the spline and null to the scene
- doc.InsertObject(spline)
- doc.InsertObject(null_start)
- doc.InsertObject(null_end)
- doc.InsertObject(main_null)
- spline.InsertUnder(main_null)
- null_start.InsertUnder(main_null)
- null_end.InsertUnder(main_null)
- # set the spline to be the active object
- doc.SetActiveObject(spline, 1)
- # get all tags attached to spline
- tags = spline.GetTags()
- #Before we attempt to execute any buttons. Let's first update C4D about all these changes we've made first
- c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW|c4d.DRAWFLAGS_NO_THREAD|c4d.DRAWFLAGS_NO_REDUCTION|c4d.DRAWFLAGS_STATICBREAK) #Update cinema 4d
- # push the button HAIR_CONSTRAINTS_TAG_SET_ANCHOR
- c4d.CallButton(tags[0], 5000) # 5000 //HAIR_CONSTRAINTS_TAG_SET_ANCHOR
- all_points.DeselectAll()
- all_points = spline.GetPointS()
- all_points.Select(49)
- #Before we attempt to execute any buttons. Let's first update C4D about all these changes we've made first
- c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW|c4d.DRAWFLAGS_NO_THREAD|c4d.DRAWFLAGS_NO_REDUCTION|c4d.DRAWFLAGS_STATICBREAK) #Update cinema 4d
- c4d.CallButton(tags[1], 5000) # 5000 //HAIR_CONSTRAINTS_TAG_SET_ANCHOR
- c4d.EventAdd()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement