How to refresh a deleted object link in Python?
orestiskon last edited by m_adam
I noticed when I use link fields or in/exclude lists, and I delete an object from the Object Manager, the link field or in/exclude list fails to refresh.
Please take a look at the attached example. I have a python node in xpresso which drives the cube along the spline. If you hit play, you will see the cube moving across the spline.
Now stop the playback, select the spline and delete it, and hit play again.
The cube will keep moving along the path as if nothing changed.
How can I refresh the link's information, so it will output "None" instead of a non-existent object?
m_adam last edited by
Hi @orestiskon this shouldn't happens, looks like an issue within Xpresso which seems to do a copy of the spline, so two solutions:
1- Check the document of the spline like so
import c4d def main(): global spline global obj global time if spline.GetDocument() is not None: SplineHelp = c4d.utils.SplineHelp() SplineHelp.InitSpline(spline) offset = SplineHelp.GetOffsetFromReal(time, 0) pos = SplineHelp.GetPos(offset) obj.SetAbsPos(pos)
And the other solution is to use python to retrieve the link and not anymore xpresso
import c4d def main(): global obj global time spline = op.GetNodeMaster().GetOwner()[c4d.ID_USERDATA,1] if spline is not None: SplineHelp = c4d.utils.SplineHelp() SplineHelp.InitSpline(spline) offset = SplineHelp.GetOffsetFromReal(time, 0) pos = SplineHelp.GetPos(offset) obj.SetAbsPos(pos)
orestiskon last edited by
Thanks Maxime, that's helpful.
I already went with the second solution as a workaround, since I noticed it happened when exporting the link with xpresso as well. I wanted to avoid unnecessary python nodes so I was hoping there was a function to force-refresh the object to update its lists and links, but it's good there are workarounds for it.
nophoto last edited by nophoto
In XPresso you should pay attention to the order of the nodes in the X-Manager. The nodes should be arranged in the order in which they where calcultated.
In your scene it looks looks like this:
If the python nodes is moved to the end of the list...
...everything works as expected.
orestiskon last edited by orestiskon
@nophoto Hi Peter.
I usually do put the nodes in order, especially when there are dependencies that matter.
However I can't reproduce here that putting them in order fixes the issue. Deleting the spline still doesn't prevent the python node from reading the previous object instead of None, and the Cube still glides on the ghost spline.
You can check the video for a demonstration:
x_nerve last edited by x_nerve
It feels like a good question, otherwise I wouldn't have known that XPresso had this problem.I think your problem is that XPresso Tag adds links to user data.If you add user data links to Python nodes, you will have no problem putting splines in the links.Or drag the spline directly to XPresso manager, output the object, there will be no problem.
import c4d #Welcome to the world of Python def main(): #global spline global obj global time spline = op[c4d.ID_USERDATA,1] if spline != None: SplineHelp = c4d.utils.SplineHelp() SplineHelp.InitSpline(spline) offset = SplineHelp.GetOffsetFromReal(time, 0) pos = SplineHelp.GetPos(offset) #print(pos) obj.SetAbsPos(pos)