I made nice little script that uses temporary Target constraint to 'aim' an item at some other item and then 'bakes' the transforms and removes the target. Math in it works but the problem is that when I read the constraints list right after adding the temp Target, SOMETIMES the list is EMPTY :O
The problem happens here:
- Code: Select all
ix.cmds.AddValue(item.get_full_name()+".constraints", "ConstraintTarget") # add temp. target constraint
# as addvalue does not return the added value, we need to get the list...
constrs=item.attrs.constraints # get all constraints (there may be some added before this script)
if len(constrs)==0:
ix.log_warning("Constraints list is EMPTY! This should never happen!")
I have noticed that the problem is timing i.e. if Clarisse is rendering complex enough (hence the extra lights to slow down the render), the script tries to get the list 'too soon' after the added constraint. I added a loop that read the list until it was not empty (max. 1000 times) and check_for_events() was called on each round. It usually got it after 10-20 loops.
But of course that is not the correct way to do it so I need a way to wait until the constraints list is updated with the added constraint. That's why that loop trick is not in the code anymore.
I also tried ix.application.is_evaluating() but it gave wrong results (claimed not evaluating but still the list was empty).
And of course this is not needed just for constraints, this is generic thing needed for any attributes

The test project is here, full script is in Script Editor, please see the code comments for details

Note that there are some other minor questions in the comments, please check them too

Thank you!
Antti