C4D Python Constraint tag target


#1

Hi,

I currently work on a script that would allow automatic retargeting of skeletal meshes.
I have two skeletons with the same naming convention, i match the position of the bones and then lock my rigged skeleton to the mocap skeleton via Constraint tag with PSR enabled.

The problem is: when in the PSR section of the constraint tag, i need to manually set the targets for each obejct.
I have started writing a script, but dont know how to set a target via code. Also could not find it in the MAXON Python SDK.

def GetNextObject(op):
    if op==None:
        return None
    if op.GetDown():
        return op.GetDown()
    while not op.GetNext() and op.GetUp():
        op = op.GetUp()
    return op.GetNext()
 
def IterateHierarchy(op):
    doc = c4d.documents.GetActiveDocument() # Get active Cinema 4D document
    if op is None:
        return
    while op:
        tags = op.GetTags() # Get tags of object
        for t in tags: # Loop Through tags
            if t.GetType() == 50045 and t = [c4d.ID_CA_CONSTRAINT_TAG_PSR] = True: # If tag is a constraint tag
                name = op.GetName()

This is how far i got with some script bashing - Im saving the name of the object with a given tag, and would like to later aplly an object with a different tag and same name as a target in my PSR constraint tag. Im new to python.

Would be great if somebody could help me:)
Thanks,
Pio


#2

Please use the code tag to format Python. Indents are crucial for Python coding, and losing all indents makes the code unreadable.


#3

Thanks, i have edited it. Didnt know about the significance of indentation in python


#4

First, on my system a constrain tag comes out as type==1019364. Sadly there doesn’t seem to be a formal constant Tconstraint at the moment.

Second, t = [c4d.ID_CA_CONSTRAINT_TAG_PSR] = True is not Python. I assume you mean something like if t[c4d.ID_CA_CONSTRAINT_TAG_PSR] :

Third, the constraint tag has a dynamic number of targets. You can drag the parameters to the console to see what their ID numbers are, but there are no constants. Seems the targets are numbered in steps of 10 beginning at 10000, with 1,2,5,6,7 being indices for the displayed GUI widgets.

Looking at the ID_CA_CONSTRAINT_TAG constants however, I can see ID_CA_CONSTRAINT_TAG_PSR_TARGET_COUNT and ID_CA_CONSTRAINT_TAG_PSR_TARGET_COUNT_END which may be needed to tell C4D how many targets there are.

To set the targets programmatically, you may need to investigate the BaseContainer of the constrain tag and find out what values this tag actually uses per target instance, and then you can manipulate the tag into acceptiong additional targets.