Setting an object to the target section of a Transform Constraint Tag
-
Hi everyone!
I'm trying to set up the constraint tag, so this will pick the movement from another object. I need to do it strictly with Transform Constraint Tag.
I was playing around with code and different parameters, but one is driving me crazy, I just can't figure out how to set an object as a target. Likewise, I used SearchObject, I got GUID nothing is going to help.
I digged through the forums and found out that the UI ID of the target matters (10001), but I find no samples how to use the ID properly in Python scripts. Appreciate any help!
I work on Windows 11
Cinema 4D 2023.2.2import c4d from c4d import gui doc = c4d.documents.GetActiveDocument() target_obj = doc.SearchObject("Test") def addConstraint(): objects = doc.GetActiveObjects(1) print(objects) my_obj = doc.SearchObject("Test") for obj in objects: tag = obj.MakeTag(c4d.Tcaconstraint) print(f"Your tag: {tag}") my_obj = doc.SearchObject("Test") tag()[c4d.ID_CA_CONSTRAINT_TAG_PSR] = True tag()[c4d.ID_CA_CONSTRAINT_TAG_PSR_LINK] = my_obj tag()[c4d.ID_CA_CONSTRAINT_TAG_PSR_P_OFFSET] = c4d.Vector(5,0,0) tag()[c4d.ID_CA_CONSTRAINT_TAG_PSR_MAINTAIN] = True tag.SetName("Boo") c4d.EventAdd() addConstraint()
-
Hello @EugeneNUA,
Welcome to the Plugin Café forum and the Cinema 4D development community, it is great to have you with us!
Getting Started
Before creating your next postings, we would recommend making yourself accustomed with our Forum and Support Guidelines, as they line out details about the Maxon SDK Group support procedures. Of special importance are:
- Support Procedures: Scope of Support: Lines out the things we will do and what we will not do.
- Support Procedures: Confidential Data: Most questions should be accompanied by code but code cannot always be shared publicly. This section explains how to share code confidentially with Maxon.
- Forum Structure and Features: Lines out how the forum works.
- Structure of a Question: Lines out how to ask a good technical question. It is not mandatory to follow this exactly, but you should follow the idea of keeping things short and mentioning your primary question in a clear manner.
About your First Question
You mostly got it right, your major oversight was that you assumed the link field to be a static parameter (which it is not). Find out more on how to discover parameter IDs in Python Console Manual: Drag and Drop. Find my example attached below.
Cheers,
FerdinandResult:
Code:
"""Adds a constraint tag with a PSR transform targeting an object named 'link' to the currently selected object. Must be run as a Script Manager script. """ import c4d doc: c4d.documents.BaseDocument # The active document op: c4d.BaseObject # The selected object in #doc, can be #None. def main() -> None: """ """ # Search for the object to link in the constraint. link: c4d.BaseObject = doc.SearchObject("link") if not op or not link: print ("Please select an object and provide an object named 'link'.") return tag: c4d.BaseTag = op.MakeTag(c4d.Tcaconstraint) if not tag: raise MemoryError("Could not allocate tag.") tag[c4d.ID_CA_CONSTRAINT_TAG_PSR] = True # ID_CA_CONSTRAINT_TAG_PSR_LINK is just a stride, i.e., offset, not an actual ID as a constraint # can have multiple links and the IDs must be therefore dynamic. If you only want one link # (or even multiple) I would just hardcode the dynamic ID (10001 will be present on the freshly # initialized tag). See # https://developers.maxon.net/docs/py/2024_0_0/manuals/manual_py_console.html#drag-and-drop # for how I found out that 10001 is the relevant ID here. tag[10001] = link tag[c4d.ID_CA_CONSTRAINT_TAG_PSR_P_OFFSET] = c4d.Vector(5,0,0) tag[c4d.ID_CA_CONSTRAINT_TAG_PSR_MAINTAIN] = True c4d.EventAdd() if __name__ == "__main__": main()
-
Hello! @ferdinand
Proud to be a part of the community.
Wow, how close the solution to the problem was, but I couldn't find any mention of it anywhere.
Thank you so much for the ready-made solution and quick help!
-
@ferdinand Just ran into the same problem. Thank you for the solution!