Alright, here’s a quick and slightly dirty take on using regexps that works for 
pasted text data. I didn’t take the time to implement proper value rescaling 
and translation into Nuke image coordinates; all keys are just set straight 
from the raw values from AE.

Again, I would still advocate for a regexp-free approach to this, but hope it 
helps somehow.

-Nathan



From: Nathan Rusch 
Sent: Monday, June 25, 2012 11:27 AM
To: Nuke Python discussion 
Subject: Re: [Nuke-python] AE Transform to Nuke

Without having taken a really close look at the structure of your function yet, 
here are a couple immediate things to try:

1) Split your data into lines before you process it.
2) Recompiling your regex objects inside a loop is pretty inefficient. The 
point of compiling regexps is so they can be reused multiple times, and you 
typically just want to compile them all one time each at highest level that 
makes sense, which in this case would probably be the module level.
3) Rather than explicitly matching tab characters, just use the \s token, which 
will match any kind of whitespace. This goes hand in hand with initially 
splitting your data into lines, since it will prevent your regexps from 
accidentally matching across multiple lines.

I’ll take a closer look after work.

-Nathan



From: Ron Ganbar 
Sent: Monday, June 25, 2012 11:15 AM
To: Nuke Python discussion 
Subject: Re: [Nuke-python] AE Transform to Nuke

Hi Wouter, 
I tried this kinda thing for the regex strings:
regex = 
re.compile('\\t+([-+]?\d+\.?\d*)\\t+([-+]?\d+\.?\d*)\\t+([-+]?\d+\.?\d*)\\t+([-+]?\d+\.?\d*)\\t+')

Didn't help (though testing the string in pythonregex.com does show results).

If I did it wrong I'd love to know. Any other ideas welcome too.


Thanks!
Ron Ganbar
email: [email protected]
tel: +44 (0)7968 007 309 [UK]
     +972 (0)54 255 9765 [Israel]
url: http://ronganbar.wordpress.com/




On 25 June 2012 21:05, Ron Ganbar <[email protected]> wrote:

  Hi Wouter, 
  thanks. That's something I haven't tried.
  I'll have a look. 



  Ron Ganbar
  email: [email protected]
  tel: +44 (0)7968 007 309 [UK]
       +972 (0)54 255 9765 [Israel]
  url: http://ronganbar.wordpress.com/




  On 25 June 2012 20:15, Wouter Klouwen <[email protected]> wrote:

    On 19/06/2012 08:28, Ron Ganbar wrote:

      The weird thing is that the code I have works perfectly when reading the
      text from a text file, just not when reading from paste. Really annoying
      to start and write it again from scratch. Plus, I would love to have
      learned from this script something useful about re.
      Any chance you can have another look?



    Your regexps look very strict. I would suggest to be more permissive in the 
amount and kind of whitespacing you allow between numbers.
    I would suggest:

    [:blank:]+  instead of \t

    Or if the Python regexps don't support he POSIX character classes, just [ 
\t]+.

    It's entirely possible that you're getting spaces in the pasted data 
instead of the tabs read from file.

    HTH,
       Wouter

    -- 
    Wouter Klouwen, Software Engineer
    The Foundry, 6th Floor, Comms Building, 48 Leicester Sq, London WC2H LT
    Tel: +442079686828 • Fax: +4420 79308906 • thefoundry.co.uk
    The Foundry Visionmongers Ltd • Reg.d in England and Wales No: 4642027 

    _______________________________________________
    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
import re

import nuke


ATTR_RE = re.compile('(Position|Rotation|Scale)')
AE_TO_NUKE_ATTR = {'Position': ('translate', 2),
                   'Rotation': ('rotate', 1),
                   'Scale': ('scale', 2)}
KEY_RE = re.compile(r'\s([-+]?\d+\.?\d*)')


def aeTransform(rawText):
    lines = rawText.splitlines()
    keys = {}
    srcW = srcH = None
    for i, line in enumerate(iter(lines)):
        if line.startswith('Transform'):
            match = ATTR_RE.search(line)
            if not match:
                print 'Unrecognized Transform block:', line
                continue
            attrKeys = []
            subIndex = i + 2
            while True:
                keyLine = lines[subIndex]
                if not keyLine:
                    break
                attrKeys.append([float (k) for k in KEY_RE.findall(keyLine)])
                subIndex += 1
            keys[match.group(0)] = attrKeys
        elif srcW is None and 'Source Width' in line:
            srwW = float(line.split()[-1])
        elif srcH is None and 'Source Height' in line:
            srcH = float(line.split()[-1])

    if not keys:
        return

    xf = nuke.createNode('Transform', inpanel=False)
    for attrName, keyList in keys.iteritems():
        knobName, size = AE_TO_NUKE_ATTR[attrName]
        knob = xf[knobName]
        knob.setAnimated()
        for keyData in keyList:
            frame = keyData[0]
            values = keyData[1:]
            for i in range(size):
                knob.setValueAt(values[i], frame, i)

    nuke.show(xf)
    return True

def dropAEData(mimeType, text):
    if text.startswith('Adobe After Effects') and 'Transform' in text:
        return aeTransform(text)
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

Reply via email to