I still steer clear from list comprehensions for the reasons Ivan mentions,
though something like that example is pretty clear.
However the speed increase is likely to be negligible for something like that
isn't it Ivan? or not?
Howard
>________________________________
> From: Ivan Busquets <[email protected]>
>To: Nuke Python discussion <[email protected]>
>Sent: Thursday, 19 April 2012, 6:54
>Subject: Re: [Nuke-python] Writing a Curve
>
>
>Yes, it's a list comprehension, which is just a quick way to create a list
>from a series of statements, in this case a for loop.
>
>
>But I see you already got that. The only reason I mentioned readability is
>that, when you start adding nested loops and conditions to the mix, then list
>comprehensions get increasingly hard to read. On the other hand, they are
>generally a little faster than the equivalent for loop(s).
>
>
>So, your choice :) I just meant that not for being shorter it was necessarily
>a better approach.
>
>
>Cheers,
>Ivan
>
>
>On Wed, Apr 18, 2012 at 10:27 PM, Ron Ganbar <[email protected]> wrote:
>
>Isn't what you have there simply a for loop, just written differently? It's
>very readable anyway.
>>Thanks again,
>>R
>>On Apr 19, 2012 8:24 AM, "Ivan Busquets" <[email protected]> wrote:
>>
>>Yes, because addKey() takes either an AnimationKey or a list of them, I just
>>built a list of them using a list comprehension structure, which is
>>essentially a loop.
>>>
>>>
>>>But if a for loop makes more sense, then by all means you should use that.
>>>Shorter is not always better, and the more readable you make it for
>>>yourself, the easier it will be to go back and make changes to it :)
>>>
>>>
>>>
>>>
>>>
>>>On Wed, Apr 18, 2012 at 10:07 PM, Ron Ganbar <[email protected]> wrote:
>>>
>>>Thanks Ivan,
>>>>I figured it probably just needs a loop, but yours is far shorter than mine.
>>>>
>>>>
>>>>I'll have a look at those tutorials.
>>>>
>>>>
>>>>
>>>>Ron Ganbar
>>>>email: [email protected]
>>>>tel: +44 (0)7968 007 309 [UK]
>>>> +972 (0)54 255 9765 [Israel]
>>>>url: http://ronganbar.wordpress.com/
>>>>
>>>>
>>>>
>>>>On 19 April 2012 03:44, Ivan Busquets <[email protected]> wrote:
>>>>
>>>>Hey Ron,
>>>>>
>>>>>I assume you just want the shortest possible version of setting the whole
>>>>>curve from values you already have, right?
>>>>>So, say you have an animated knob that you've created like this:
>>>>>
>>>>>
>>>>>node = nuke.createNode( 'Blur' )
>>>>>k = node['size']
>>>>>k.setAnimated()
>>>>>And then you have list of keys and values that you want to feed at once as
>>>>>an animation curve.
>>>>>One thing you can do is put them all in a list of (frame,value) tuples,
>>>>>like this:
>>>>>
>>>>>keys = [(0,20), (1,30), (5,70), (8,90)]
>>>>>
>>>>>And then get the AnimationCurve object for that knob, and add them all
>>>>>like this:
>>>>>
>>>>>anim = k.animation(0)
>>>>>anim.addKey([nuke.AnimationKey(frame, value) for (frame,value) in keys])
>>>>>
>>>>>Of course, that is just an example for doing it in just a couple of lines.
>>>>>Depending on how your initial data is formatted, you might want to take a
>>>>>different approach.
>>>>>If you want to dig any deeper into it, you can find more info and some
>>>>>examples in the Python Developers Guide, under "Animation".
>>>>>
>>>>>Also check these two great tutorials from Nathan:
>>>>>
>>>>>http://www.nukepedia.com/python/knob-animation-and-python-a-primer/
>>>>>http://www.nukepedia.com/python/animationcurve-and-animationkey-objects/
>>>>>
>>>>>Hope that helps.
>>>>>
>>>>>Cheers,
>>>>>Ivan
>>>>>
>>>>>
>>>>>
>>>>>On Wed, Apr 18, 2012 at 3:16 AM, Ron Ganbar <[email protected]> wrote:
>>>>>
>>>>>Hi guys,
>>>>>>quick question, back in Shake it was easy to type an animation curve, it
>>>>>>was simply hermite(0, 0@1, 15@10, 44@100).
>>>>>>Is there a way to easily create an animation curve like that in Nuke?
>>>>>>
>>>>>>I know about setValueAt(), but that's for each keyframe rather than a
>>>>>>whole curve.
>>>>>>
>>>>>>Thanks!
>>>>>>Ron Ganbar
>>>>>>email: [email protected]
>>>>>>tel: +44 (0)7968 007 309 [UK]
>>>>>> +972 (0)54 255 9765 [Israel]
>>>>>>url: http://ronganbar.wordpress.com/
>>>>>>
>>>>>>_______________________________________________
>>>>>>Nuke-python mailing list
>>>>>>[email protected], http://forums.thefoundry.co.uk/
>>>>>>http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>>>>>>
>>>>>>
>>>>>
>>>>>_______________________________________________
>>>>>Nuke-python mailing list
>>>>>[email protected], http://forums.thefoundry.co.uk/
>>>>>http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>>>>>
>>>>>
>>>>
>>>>_______________________________________________
>>>>Nuke-python mailing list
>>>>[email protected], http://forums.thefoundry.co.uk/
>>>>http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>>>>
>>>>
>>>
>>>_______________________________________________
>>>Nuke-python mailing list
>>>[email protected], http://forums.thefoundry.co.uk/
>>>http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>>>
>>>
>>_______________________________________________
>>Nuke-python mailing list
>>[email protected], http://forums.thefoundry.co.uk/
>>http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>>
>>
>
>_______________________________________________
>Nuke-python mailing list
>[email protected], http://forums.thefoundry.co.uk/
>http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>
>
>
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python