PDA

View Full Version : Creating node with phyton


anna1
09-25-2012, 08:57 AM
Hey,

I am currently trying to put a Xpresso tag on an object and then creating a node of the object with x,y and z position output. I figured out how to create the tag, put it on my controller and create the node. But I am not really getting how to add the port. I looked it up in the SDK and I also found some examples, but it is not really working. The port ist simply not appearing.

This is my code:

xp_tag = c4d.BaseTag(c4d.Texpresso)
nodemaster = xp_tag.CreateNodeMaster()
node1 = nodemaster.CreateNode(nodemaster.GetRoot(), c4d.ID_OPERATOR_OBJECT, None,100,100)

until here everything is working fine. Then I read, that I have to use the DescID to get my position x:

pos_x = c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_ABS_POSITION), c4d.DescLevel(c4d.VECTOR_X)

and then adding the port:

node1.AddPort(c4d.GV_PORT_OUTPUT, pos_x)

I am not getting any error message but the port does not appear either. Do I maybe have to add a flag? I tried it, but could not make it work. So if anyone of you could help me, it would be great and thank you so much

Anna

Scott Ayers
09-28-2012, 05:07 PM
Give this a try: import c4d
def main():
cube = c4d.BaseObject(c4d.Ocube) #Create a cube in memory only
doc.InsertObject(cube) #Add it to the OM from memory
xtag = c4d.BaseTag(c4d.Texpresso) #Create an xpresso tag in memory only
cube.InsertTag(xtag) #Add it to the cube from memory

xtag.SetBit(c4d.BIT_ACTIVE) #Make the xpresso tag active

#Create a nodemaster object
nm = doc.GetActiveTag().GetNodeMaster()

#Create the object's position node
objnode = nm.CreateNode(nm.GetRoot(), c4d.ID_OPERATOR_OBJECT,insert=None, x=200, y=200)
outport = objnode.AddPort(c4d.GV_PORT_OUTPUT, (c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_X))

#Create a result node and then get it's first input port
resultnode = nm.CreateNode(nm.GetRoot(), c4d.ID_OPERATOR_RESULT,insert=None, x=300, y=200)
inport = resultnode.GetInPort(0)


#Connect the objnode's output port to the resultnode's input port
outport.Connect(inport)

c4d.EventAdd()

if __name__=='__main__':
main()

-ScottA

anna1
09-29-2012, 02:01 PM
thank you so much for your help. It helpd me a lot and I am understanding it now so much better and could do a lot more coding :-)

I am still having a last question, is there some way to freeze the transformation of the position?

Anna

Scott Ayers
09-29-2012, 03:52 PM
c4d.CallCommand(1023335) #Freeze all transforms

If you want to execute the individual buttons in the freeze pallet.
This is an example of how to execute those buttons: import c4d
def main():

obj = doc.GetActiveObject()
obj.SetFrozenPos(c4d.Vector(0,0,0)) #Sets the freeze value fields if desired

c4d.CallButton(obj,c4d.ID_BASEOBJECT_FREEZE) #Executes the Freeze All button
c4d.CallButton(obj,c4d.ID_BASEOBJECT_FREEZE_P) #Executes the Freeze P button
c4d.CallButton(obj,c4d.ID_BASEOBJECT_FREEZE_S) #Executes the Freeze S button
c4d.CallButton(obj,c4d.ID_BASEOBJECT_FREEZE_R) #Executes the Freeze R button

c4d.CallButton(obj,c4d.ID_BASEOBJECT_FROZEN_RESET) #Executes the Unfreeze All Button

obj.Message(c4d.MSG_UPDATE)
c4d.EventAdd()

if __name__=='__main__':
main()

-ScottA

anna1
10-01-2012, 03:20 PM
thanks a lot, it is now working completely :bounce:

CGTalk Moderation
10-01-2012, 03:20 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.