Isotropix Forums

Detecting when attribute is ready after e.g. addvalue?

Clarisse Scripting related topics

Detecting when attribute is ready after e.g. addvalue?

Unread postby atnreg » Tue Mar 12, 2019 1:59 pm

Hi!

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 :)
test.project
(59.63 KiB) Downloaded 33 times


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

Thank you!

Antti
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 4.0SP3,Blender2.80,Fusion360,ZBrush,Onyx,Houdini,SubstPnt...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 508
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland

Re: Detecting when attribute is ready after e.g. addvalue?

Unread postby bvaldes » Wed Mar 13, 2019 3:43 pm

Hi Antti,

I took a look to your project and I think that the issue comes on our side but it's hard to tell if it's a bug or a limitation. I have to talk about that with the engineers.

I didn't had the issue where Clarisse wasn't able to get the last constraint if the constraints list is not empty. So I can't help you on that. What you could try is to use get_attribute() and then get_object() with get_value_count() to know how many object are in the attribute.

About the is evaluating(), it's because when you call it, Clarisse didn't start it's evaluation so it's normal. I tried in a while loop and it's set to True once it start evaluating.

The while loop you used as work around is the only one that could work until we find a proper solution.

I will get back to you when I'll have more info from the engineers.

Regards
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 384
Joined: Mon Sep 26, 2016 10:44 am

Re: Detecting when attribute is ready after e.g. addvalue?

Unread postby atnreg » Wed Mar 13, 2019 4:00 pm

Hi!

bvaldes wrote:I took a look to your project and I think that the issue comes on our side but it's hard to tell if it's a bug or a limitation. I have to talk about that with the engineers.

OK, thank you :)

I didn't had the issue where Clarisse wasn't able to get the last constraint if the constraints list is not empty. So I can't help you on that.

The problem only occurs when the list is empty of course yes but the problem is that the list should never be empty at that point as a constraint was just added to the list :)

What you could try is to use get_attribute() and then get_object() with get_value_count() to know how many object are in the attribute.

OK, I'll try that, thanks!

About the is evaluating(), it's because when you call it, Clarisse didn't start it's evaluation so it's normal. I tried in a while loop and it's set to True once it start evaluating.

But then why it said False and still the list was empty? :?

The while loop you used as work around is the only one that could work until we find a proper solution.

Ok, I'll go with that then until better solution appears :mrgreen:

I will get back to you when I'll have more info from the engineers.

Thank you very much, this was very important because now I know I didn't do anything actually wrong, let's hope there is some simple solution to this as this occurs everywhere where the script adds to lists and then immediately needs to get the list :)

Antti
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 4.0SP3,Blender2.80,Fusion360,ZBrush,Onyx,Houdini,SubstPnt...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 508
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland

Re: Detecting when attribute is ready after e.g. addvalue?

Unread postby atnreg » Wed Mar 13, 2019 4:15 pm

What you could try is to use get_attribute() and then get_object() with get_value_count() to know how many object are in the attribute.


I tried this but same result, the list is randomly empty.
Code: Select all
item=ix.selection[0] # item to aim
target=ix.selection[1] # item to aim to
ix.cmds.AddValue(item.get_full_name()+".constraints", "ConstraintTarget") # add temp. target constraint
#constrs=item.attrs.constraints # get all constraints (there may be some added before this script)
attr=item.get_attribute("constraints")
cnt=attr.get_value_count()
if cnt==0:
    ix.log_warning("Constraints list is EMPTY! This should never happen!")
.
.
.


So I'll use the loop trick until you give perfect solution to this :mrgreen:

Antti
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 4.0SP3,Blender2.80,Fusion360,ZBrush,Onyx,Houdini,SubstPnt...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 508
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland

Re: Detecting when attribute is ready after e.g. addvalue?

Unread postby atnreg » Wed Mar 13, 2019 4:49 pm

Even using add_embedded_object() and add_object() does not change the problem so it is not in cmds :)

Antti
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 4.0SP3,Blender2.80,Fusion360,ZBrush,Onyx,Houdini,SubstPnt...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 508
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland

Re: Detecting when attribute is ready after e.g. addvalue?

Unread postby bvaldes » Thu Mar 14, 2019 9:27 am

:!: Hi,

I told you to use get_object() to avoid the fact that when the list is NOT empty, sometimes you didn't succeed to get the last element of the list (this is what you wrote in the comment of your script in the project) so I said that I didn't succeed to reproduce this issue and If this happen to you, you can try to use get_object() instead of item.attrs.constraint[-1]. This don't fix the main issue: the list is not refreshed before the next script action.

But then why it said False and still the list was empty? :?

Maybe I didn't explain it well: when you add the contraint and you call ix.application.is_evaluating(), Clarisse did't start the evaluation so it return false. If you try to put a while loop chat check 1000 times ix.application.is_evaluating() you will see that at the beginning False is printed then True then false again. So that shows that when you ask right after adding a constraint, Clarisse didn't start the evaluation so it's normal that False is printed.

Cheers
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 384
Joined: Mon Sep 26, 2016 10:44 am

Re: Detecting when attribute is ready after e.g. addvalue?

Unread postby atnreg » Thu Mar 14, 2019 1:22 pm

bvaldes wrote:I told you to use get_object() to avoid the fact that when the list is NOT empty, sometimes you didn't succeed to get the last element of the list (this is what you wrote in the comment of your script in the project) so I said that I didn't succeed to reproduce this issue and If this happen to you, you can try to use get_object() instead of item.attrs.constraint[-1]. This don't fix the main issue: the list is not refreshed before the next script action.

Ok I slightly misunderstood then but there is and ever was no problem getting the last constraint when the list is returned correctly so using get_object() makes no difference in this case :)

Maybe I didn't explain it well: when you add the contraint and you call ix.application.is_evaluating(), Clarisse did't start the evaluation so it return false. If you try to put a while loop chat check 1000 times ix.application.is_evaluating() you will see that at the beginning False is printed then True then false again. So that shows that when you ask right after adding a constraint, Clarisse didn't start the evaluation so it's normal that False is printed.

Ok now I understand that but it makes the is_evaluating() unsuitable for this kind of checking.
But I actually use check_for_events() in a loop and try to get the list on each round, until either the list is not empty or the max rounds is reached. That works for cases where the list must not be empty but as the list can be empty, there is no way to separate this error situation from normal generally. But anyway, that seems to work for this case, even though I don't think it is nice way to do it :)
But as said, that will do until there is better way :)

Antti
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 4.0SP3,Blender2.80,Fusion360,ZBrush,Onyx,Houdini,SubstPnt...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 508
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland


Return to Scripting
cron