Playing with the init.py file


#1

I’m starting to play with the init.py file in order to customize nodes at the moment they are created.
First off, it seems that the exemple file available here is outdated :

http://natron.readthedocs.io/en/master/devel/startupscripts.html

In this exemple, setting the default value for a Blur size is achieved using the setDefaultValue() function.
It doesn’t work, the setValue() function has to be used instead.

Then, setColor() doesn’t seem to work neither.
It works when running it in the script editor doing : app.Blur1.setColor(1,0,0)
but not within the init.py file.

Another weird thing : at the time a Blur node is created, i ask Natron to print the node color in the script editor.
But the value returned is wrong. In this case it return (0,0,0) (black), although a Blur node is by default orange.

What am i doing wrong ?


#2

At some point setDefaultValue was changed to only modify the default value without actually reseting the current value to the default value.
Using setDefaultValue + restoreDefaultValue should work.
Regarding the color of the node, this might be because of a bug in the current version of Natron: it probably is because the color is not yet set internally (because the node UI is not created) when the callback is called.


#3

Thanks MrKepzie.
I was indeed expecting that setColor() wasn’t taken in account because the UI wasn’t initialized yet.
It was just to play around with Python anyway, not a big deal.
Thx again.