Change Xpresso Object Node Ref with Python
-
On 18/02/2018 at 01:00, xxxxxxxx wrote:
Hi
i have a scene with a null, a cube and a sphere,
that null has a xpresso tag on it and a bunch of user data sliders
inside xpresso i made connections between null user data and an object node named "MyObject" referenced to the cube which controls cube's position;
is it possible to change that "MyObject" node reference from cube to sphere with a python script? -
On 19/02/2018 at 08:59, xxxxxxxx wrote:
Hi,
welcome to the Plugin Café forums !
Smile
[URL-REMOVED]Actually you don't need any scripting at all to achieve this.
Here's option one to solve it in Xpresso, just by assigning another object to an object node:
, which can be used to assign another object to an object node. The mode to use there is GV_OP_DROP_IN_BODY.
[URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.
-
On 19/02/2018 at 10:46, xxxxxxxx wrote:
Hi Andreas,
Thanks!
actually switch node is a perfect solution for this example
but my real situation is a bit more complicated and i think python is the only way!
that GvNode.OperatorSetData() helped me but now i don't know how to use it for that specific node named "MyObject" -
On 20/02/2018 at 02:31, xxxxxxxx wrote:
Hi,
so you basically need to get hold of the GvNode "MyObject".
There are different ways to achieve this, also depending on where you implement it (in a Python Scripting node or a Script Manager script or ...). The following function should help with this: XPressoTag.GetNodeMaster(), GvNodeMaster.GetRoot() (and from there with the usual GeListNode tools).And then it's just calling OperatorSetData(), roughly like so:
myObjNode.OperatorSetData(c4d.GV_ATOM, theOtherObject, c4d.GV_OP_DROP_IN_BODY)
-
On 20/02/2018 at 08:05, xxxxxxxx wrote:
Thanks Andreas
i finally got it workin'
that last step could also be achieved by setting GV_OBJECT_OBJECT_ID directly
this is the final code:import c4d
def main() :Cube = doc.SearchObject('Cube')
Remote = doc.SearchObject('Remote') #user data holder
RemoteXP = Remote.GetTag(c4d.Texpresso)
RemoteNodes = RemoteXP.GetNodeMaster()
Root = RemoteNodes.GetRoot()
MyNodes = Root.GetChildren()
for child in MyNodes:
if child[c4d.ID_BASELIST_NAME] == 'MyObject':
child[c4d.GV_OBJECT_OBJECT_ID] = Cube
#child.OperatorSetData(c4d.GV_ATOM, Cube, c4d.GV_OP_DROP_IN_BODY)doc.EndUndo()
c4d.EventAdd()if __name__=='__main__':
main()