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() :   
    doc.StartUndo()   
       
    # Create Cubes for Start / End   
    a = c4d.BaseObject(c4d.Ocube)   
    a.SetName("A")   
    doc.InsertObject(a)   
    a_pos = c4d.Vector()   
    doc.AddUndo(c4d.UNDOTYPE_NEW, a)   
       
    b = c4d.BaseObject(c4d.Ocube)   
    b.SetName("B")   
    doc.InsertObject(b, pred=a)   
    b_pos = c4d.Vector(1000.0, 0, 0)   
    b.SetRelPos(b_pos)   
    doc.AddUndo(c4d.UNDOTYPE_NEW, b)   
       
    # Draw a Spline linking them   
    spline = c4d.BaseObject(c4d.Ospline)   
    spline.SetName("A to B")   
    spline.ResizeObject(2)   
    spline.SetPoint(0, a_pos)   
    spline.SetPoint(1, b_pos)   
    doc.InsertObject(spline, pred=a)   
    doc.SetActiveObject(spline)   
    doc.AddUndo(c4d.UNDOTYPE_NEW, spline)   
       
    # Add a Spline Dynamics tag   
    spline_dynamics_tag = c4d.BaseTag(1018068)   
    spline.InsertTag(spline_dynamics_tag)   
    doc.AddUndo(c4d.UNDOTYPE_NEW, spline_dynamics_tag)   
       
    # Constrain to A   
    constraint = c4d.BaseTag(1018074)   
    constraint[c4d.HAIR_CONSTRAINTS_TAG_ANCHOR_LINK] = a   
    spline.InsertTag(constraint)   
       
  
    # Initialize the Constraint Tag   
    # THIS IS THE PART THAT IS BEHAVING STRANGELY   
    spline.GetPointS().Select(0) # Select the first point   
    doc.SetActiveTag(constraint)   
    c4d.CallButton(constraint, c4d.HAIR_CONSTRAINTS_TAG_SET_ANCHOR)   
  
    doc.AddUndo(c4d.UNDOTYPE_NEW, constraint)   
       
    doc.EndUndo()   
    c4d.EventAdd()   
       
if \__name\_\_=='\__main\_\_':   
    main()   

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

Hello,

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,
Sebastian