Creating node with phyton

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  09 September 2012
Creating node with phyton


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_POS ITION), 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

  09 September 2012
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


if __name__=='__main__':

My Gallery
  09 September 2012
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?

  09 September 2012
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

if __name__=='__main__':

My Gallery

Last edited by Scott Ayers : 09 September 2012 at 05:02 PM.
  10 October 2012
thanks a lot, it is now working completely
  10 October 2012
Thread automatically closed

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.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 12:33 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.