THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 27/06/2011 at 13:37, xxxxxxxx wrote:
So this is likely some noob mistake, some fundamental that I am missing. I can get CallCommand to work great from the console but I can't for the life of me make it work in a script. I'm not sure what I'm doing wrong. The relevant part of the code is towards the bottom. Thanks for your time!
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() :
# function creates a linear spline
spline = add_spline(10, 500)
# create tags
constraint_tag = 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 = c4d.BaseObject(c4d.Onull)
# insert null into anchor field for constraint tag
constraint_tag[c4d.HAIR_CONSTRAINTS_TAG_ANCHOR_LINK] = null
# add constraint tag to spline
spline.InsertTag(constraint_tag)
# select point 0 on spline (at position 0, 0, 0)
all_points = spline.GetPointS()
all_points.Select(0)
# set the spline to be the active object
doc.SetActiveObject(spline, 1)
# get all tags attached to spline
tags = spline.GetTags()
# push the button HAIR_CONSTRAINTS_TAG_SET_ANCHOR
c4d.CallButton(tags[0], 5000) # 5000 //HAIR_CONSTRAINTS_TAG_SET_ANCHOR
# Add the spline and null to the scene
doc.InsertObject(spline)
doc.InsertObject(null)
c4d.EventAdd()
if __name__ == '__main__':
main()