How to set xpresso node references?

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 02/06/2011 at 12:14, xxxxxxxx wrote:

I'm going through the python SDK and trying out the various xpresso methods. But I'm stuck on how to deal with node references.
The SDK says to use CreateNode(nodemaster.GetRoot(). And I'm thinking that this is why my nodes are always created referenced to the object the xpresso tag is on. And that's bad.

I need to have control over what object gets referenced in the nodes I create. So I can create nodes for other objects in the OM. But I don't see how to do that.

Here's an example that creates two objects, two nodes, and connects their ports:

import c4d  
from c4d import *   
  
def main() :  
  cube = c4d.BaseObject(c4d.Ocube)      #Create a cube  
  doc.InsertObject(cube)  
  sphere = c4d.BaseObject(c4d.Osphere)  #Create a sphere  
  doc.InsertObject(sphere)  
     
  xtag = c4d.BaseTag(c4d.Texpresso)     #Create an xpresso tag  
  cube.InsertTag(xtag)                  #Put it on the cube    
  
  nodemaster = xtag.GetNodeMaster()     #Get the xpresso tag's master node  
  print nodemaster.GetOwner().GetName() #Prints the name of the tag(XPresso)  
  
  n1 = nodemaster.CreateNode(nodemaster.GetRoot(), c4d.ID_OPERATOR_OBJECT, None, 100, 100);  
  n1out = n1.AddPort(c4d.GV_PORT_OUTPUT, c4d.ID_BASEOBJECT_POSITION)  
  print n1.GetOperatorContainer()[c4d.GV_OBJECT_OBJECT_ID].GetName() #prints the name of the tag's owner("Cube")  
  
  n2 = nodemaster.CreateNode(nodemaster.GetRoot(), c4d.ID_OPERATOR_OBJECT, None, 200, 100);  
  n2in = n2.AddPort(c4d.GV_PORT_INPUT, c4d.ID_BASEOBJECT_POSITION)  
  
  n1out.Connect(n2in) #Connect the first node's output port to the second node's input port  
  
  c4d.EventAdd()  
  
if __name__=='__main__':  
  main()

Both nodes get created using the same object reference. And I need to know how to set them myself.
I'm thinking that the GetOperatorContainer() & SetOperatorContainer() methods are what I need to use. But I'm not sure. And I can't figure it out how to really take advantage of them from what's in the SDK.

-ScottA

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 02/06/2011 at 12:26, xxxxxxxx wrote:

    n2 = nodemaster.CreateNode(nodemaster.GetRoot(), c4d.ID_OPERATOR_OBJECT, None, 200, 100);  
  n2[c4d.GV_OBJECT_OBJECT_ID] = sphere  
  n2in = n2.AddPort(c4d.GV_PORT_INPUT, c4d.ID_BASEOBJECT_POSITION)

Not very obvious, hm? ;)

Cheers,
Niklas

PS: I'm very proud of your 4-space indentation. :)

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 02/06/2011 at 12:47, xxxxxxxx wrote:

Lol. Thanks.

I'd still like to know more about GetOperatorContainer() & SetOperatorContainer() though.

I think those methods are going to be very useful when trying to do more complicated things with the nodes.
I'd like to know how to use them to iterate through the node's ports and change the values in them.
But I've never seen any examples of that.

-ScottA