CallButton Won't Work on New Tags

On 28/07/2017 at 16:57, xxxxxxxx wrote:

I'm attempting to use c4d.CallButton() to initialize a Hair Constraint tag. I can get it to work if I am calling the command on a pre-existing tag, however, if I create the same tag with my script I can't call the tag. Any ideas why this might be the case?

"""Constrain Spline to Cubes   
Creates two cubes, and constrains a two-point spline to the first cube.   
import c4d   
from c4d import gui   
def main() :   
    # Create Cubes for Start / End   
    a = c4d.BaseObject(c4d.Ocube)   
    a_pos = c4d.Vector()   
    doc.AddUndo(c4d.UNDOTYPE_NEW, a)   
    b = c4d.BaseObject(c4d.Ocube)   
    doc.InsertObject(b, pred=a)   
    b_pos = c4d.Vector(1000.0, 0, 0)   
    doc.AddUndo(c4d.UNDOTYPE_NEW, b)   
    # Draw a Spline linking them   
    spline = c4d.BaseObject(c4d.Ospline)   
    spline.SetName("A to B")   
    spline.SetPoint(0, a_pos)   
    spline.SetPoint(1, b_pos)   
    doc.InsertObject(spline, pred=a)   
    doc.AddUndo(c4d.UNDOTYPE_NEW, spline)   
    # Add a Spline Dynamics tag   
    spline_dynamics_tag = c4d.BaseTag(1018068)   
    doc.AddUndo(c4d.UNDOTYPE_NEW, spline_dynamics_tag)   
    # Constrain to A   
    constraint = c4d.BaseTag(1018074)   
    constraint[c4d.HAIR_CONSTRAINTS_TAG_ANCHOR_LINK] = a   
    # Initialize the Constraint Tag   
    spline.GetPointS().Select(0) # Select the first point   
    c4d.CallButton(constraint, c4d.HAIR_CONSTRAINTS_TAG_SET_ANCHOR)   
    doc.AddUndo(c4d.UNDOTYPE_NEW, constraint)   
if \__name\_\_=='\__main\_\_':   

On 31/07/2017 at 02:01, xxxxxxxx wrote:


the Hair Constraint tag only works properly after initialization. The tag is initialized when its Execute() function is called. To do this you could call ExecutePasses() on the BaseDocument that includes the tag. Only then you can work with the tag (e.g. pressing buttons).

I'm not sure if this will get in the way of creating an undo step so please test this carefully.

best wishes,