Thanks @ferdinand , I misinterpreted the GetRange argument. That clears it up, and thanks for the example as well, it's very useful!
Posts made by orestiskon
How to get all elements from BaseSelect
I'm trying to get the selected points from an object. GetPointS gives a baseselect so I'm trying to retrieve the selected points' indices from the baseselect.
In the attached example, I selected a few of the points of the cube. I iterate through all the baseselect ranges but only half of them give points. The other half result "None". Any idea why it isn't working and/or how to fetch the point selection without iterating through all the points of the object?
# Main function def main(): objectSelection = doc.GetActiveObject() pointSelection = objectSelection.GetPointS() selectedCount = pointSelection.GetCount() for segment in range(pointSelection.GetSegments()): print(pointSelection.GetRange(segment, selectedCount))
RE: How to refresh a deleted object link in Python?
@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:
RE: How to refresh a deleted object link in Python?
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.
How to refresh a deleted object link in Python?
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?
RE: Python: Global Variable vs Plugin ID
Thank you for the reply.
The idea is to save a value beyond the limits of the main function of a python generator, and Global Variable seems to achieve it.
Saving the value when saving the scene isn't important in this case, as the purpose is performance. On load it would re-evaluate the generator anyway.
So I'm trying to understand when global variables fail, and we need to use a plugin id instead. Is the only benefit of the plugin id that it can save the data with the file?
Python: Global Variable vs Plugin ID
I'm trying to understand some basic concepts on good programming practices in c4d.
When we want to save a persistent data I was advised to use a plugin id that is attached to my python object.
What is the drawback of using global variables instead?
In my tests global variables seem to work, so what is the plugin id offering that the global variables don't?
My example case is manually storing a matrix array in a variable so I can compare it and see if it changes, since the GetDirty fucntions seem to be problematic for that particular object.
RE: Getting cache of a Python Generator under a Python Generator
def main(): obj = op.GetDown().GetCache().GetClone() print obj return obj
getting the cache before cloning does seem to work, I couldn't see the object as it was off screen before.
Still it opens some questions such as why the clone didn't initially work; I assume I needed to insert it into the doc, which I had tried without much success (crashed cinema when I tried to evaluate the doc).
In any case, the problem seems solved for now.
Getting cache of a Python Generator under a Python Generator
using a python generator as a source for another python generator can be helpful for prototyping. But I'm having trouble getting the cache of the child generator.
GetCache always returns me "None", and using current state to object also returns "None".
This is a code sample:
def main(): obj = op.GetDown().GetClone() print obj.GetCache() return obj
I tried to see if it has children or siblings with GetDown or GetNext but I get:
"AttributeError: 'NoneType' object has no attribute 'GetDown'"
Code with current state to object:
def currentState(obj) : return c4d.utils.SendModelingCommand(c4d.MCOMMAND_CURRENTSTATETOOBJECT,[obj],c4d.MODELINGCOMMANDMODE_ALL,c4d.BaseContainer(),doc) def main(): obj = op.GetDown().GetClone() collapsed = currentState(obj) print collapsed.GetChildren() //returns  return collapsed
In the docs there is a recursion function for the cache but I'm not sure how to use it.
I'm trying to understand what I'm doing wrong, are there suggestions on how to achieve this?
Here is a sample file:
RE: Python Generator: Getting polygon data from new generators
Wow much obliged for all the replies everyone, it is really helpful!
I think evaluating in a tempdocument is what I was looking for. I have another question about best practices:
In zipit's example the original cube is removed from the temp document after use. Is there a reason to do that? Does it help with performance and/or memory management?