PDA

View Full Version : Python - How to add new link fields to Tags ?


Decade
12-06-2010, 10:44 PM
I'm trying to setup an aim constraint with python.

I know how to create the tag with :

Tcaconstraint = 1019364
constr = c4d.BaseTag(Tcaconstraint)

and check the 'aim' box with :

constr[c4d.ID_CA_CONSTRAINT_TAG_AIM] = 1

I've worked out how to add link fields with :

constr[c4d.ID_CA_CONSTRAINT_TAG_AIM_TARGET_COUNT] = 1

But I'm stuck at accessing the properties of the links.
When I try to use :

constr[c4d.ID_CA_CONSTRAINT_TAG_AIM_AXIS] = 2

to set the axis to Z+, nothing happens. I guess I need to access it by index, because there can be any number of links, but I don't know the syntax.
The .H file, which I've used to get this far, mentions containers, so I guess maybe I have to change the properties in a variable and load it in but again, I don't know the syntax.

If anyone could help me with an example of how to add a link, it would be greatly appreciated.

Scott Ayers
12-07-2010, 01:11 AM
You are technically already accessing the container when you type out the various attributes using those [] brackets. It's the shortcut version of editing an object's container

You could create a brand new container and then fill it with attributes that you want to edit.
The Send Modeling code is an example of that kind of thing. Where you fill in your new container with MDATA options then edit them. But since you're just trying to "Set" the attributes that already exist inside the object's container. You shouldn't need to create a brand new one for what you're doing.

Here's the code with the Axis attribute set to Z+: import c4d
from c4d import gui

def main():
op = doc.GetActiveObject()
const = c4d.BaseTag(1019364) #create a constraint tag
const[c4d.ID_CA_CONSTRAINT_TAG_AIM] = 1 #Enable the aim option
const[c4d.ID_CA_CONSTRAINT_TAG_AIM_TARGET_COUNT] = 1 #Add a target
const[20004]=2 #Sets the axis option to Z+
op.InsertTag(const) #Insert the tag on the cube
c4d.EventAdd()

if __name__=='__main__':
main()


-ScottA

Decade
12-07-2010, 10:48 PM
Many thanks Scott, that was just what I needed and I understand why it works too.
Thanks again.

CGTalk Moderation
12-07-2010, 10:48 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.