4
$\begingroup$

A lot operators use StringPropertys to reference objects by name. This works well for ID datablocks - no duplicate names allowed (although there can be issues with linked datablocks).

But not all objects are of type ID datablock, and unique names may not be enforced. Related operators may take a string for indentification however. Thus you may not act upon the right object.

If names aren't unique, one could use an integer to reference by index. But I wonder if there are any operators, which actually take a pointer to the right object (in C)? Like:

ot->prop = RNA_def_pointer(...);

Is it even possible to use pointers as operator properties? It would mean that python couldn't make any use of it, if I'm not mistaken (or could one pass a python object, and have C code figure out the pointer?).

$\endgroup$
4
+50
$\begingroup$

Operators should never have pointer properties and as far as I know there aren't any that do.

Such pointers would not be valid after deleting objects or after undo/redo steps, which would give problems in the operator history stack when repeating operators for example.

Operators that take datablock names should usually be avoided for python scripting. It's better to edit the data directly than going through operators when possible, there's probably only a handful of cases where you need to do this.

$\endgroup$
1
  • $\begingroup$ Thanks brecht, makes sense. I encountered transform orientations not needing a unique name, and currently delete based on index number in my mockup code. It is necessary to use an operator 'cause there is no RNA method to create/delete them. It doesn't even take a name for deletion, it is based on context instead. I wondered if there's a better way, at least in C. $\endgroup$
    – CodeManX
    Feb 26 '14 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.