Proxy to python object within pivy

17 views
Skip to first unread message

miguel tejada

unread,
Jul 18, 2018, 7:50:15 AM7/18/18
to coin3d-discuss
There are any way to make proxy to python object in pivy?

When I get a node from pivy space, i need to recover the python object that contains other properties not included in the node, but the node is not the reference to the object. 

from pivy import coin
root = coin.SoSeparator()
node = coin.SoSeparator()
node.prop = "hello" #add custom property to python SoSeparator object
root.addChild(node)

noderec = root[0] 
hasattr(nodrec,'prop') # return False
hasattr(node, 'prop') # return True


I found a partial solution, that is bassed on store the "id" of python object as name of the object, and after recover it:

objid = '_' + hex(id(node)) # I add '_' at name start to avoid invalid type issue
node.setName(objid)
#
#
noderec = root[0]
objid = noderec.getName().getString()[1:]   #remove '_' from name
pynode = ctypes.cast(objid, ctypes.py_object).value
hasattr(pynode,'prop') # return True


This solution goes well, but I think that there must be a more efficient method tahat does not use the name field. Please, help me!



Reply all
Reply to author
Forward
0 new messages