On 01/09/2017 at 08:14, xxxxxxxx wrote:
I'm trying to change User Data of another object via Python tag.
If I want to get User Data from current object I can use this:
But what if I'm going to change User Data from different object?
I was searching for an answer in documentation and not sure whether it's right and how to use it.
I will be appreciative for an answer or some example.
Also what is "op"?
On 02/09/2017 at 00:07, xxxxxxxx wrote:
Seems like I can do it like that
But still not sure what is "op", "doc" and where I can read it.
On 04/09/2017 at 08:16, xxxxxxxx wrote:
welcome to the Plugin Café forums
SearchObject() is one of the options you have. Depending on a user's naming scheme not always the best one, as it returns only one object with the specified name.If the user has several objects with identical names, you probably won't get the desired result.
For example it's often simpler or more effective to iterate through the scene (tree of objects). Maybe you don't even want to search objects by name, but rather by type...
In these cases you can either start with the first object (GetFirstObject()) or with the currently active/selected object (GetActiveObject()). And then you have GetPred(), GetNext(), GetUp() and GetDown() to walk through the tree of objects.
See also our C++ manual on navigation in lists and trees, no worries it should be easy to understand for Python developers as well.
Regarding your question on doc and op. These are predefined variables in most places where you can use Python inside Cinema (plugins excluded). doc is always pointing to the active document. In case of a Python tag op is the tag itself, in general op points to the entity the Python code is running in. So in a Python Generator it's the generator object. In a Xpresso Python node it's the node. In Script Manager and Console it is the currently active object (if any).
On 05/09/2017 at 01:36, xxxxxxxx wrote:
just one little addendum to the point iterating though the tree of objects. There are some useful lines out there I alway copy+paste recursive hierarchy iteration. In line 4 of the recurse_hierarchy function you just have to add brackets behind 'op.GetDown' and it´ll work well. Don´t be confused - op isn´t predefined in custom functions.
But if it makes sense, e.g. the object you´d like to get is permanently the same and the code you want the object in is in a tag or a pygenerator, I prefer filling userData of type link with the searched object.`