That means your regular expression isn’t matching whatever you’re feeding it,
and you can’t necessarily expect it to; you need to be able to handle non-match
cases.
Depending on how rigid your naming convention is, you can probably get away
with something more on the lenient side. The simplest case would be something
like:
[string range [file rootname [value root.name]] end-2 end]
A more exact case:
[if {[regexp {\D(\d+)$} [file rootname [value root.name]] null digits]} then
{return $digits} else ""]
Also, as a side note (not applicable above), when dealing with Python
expressions via TCL, you can put your Python code in braces to prevent the TCL
interpreter from trying to evaluate it. This will let you avoid escaping things
like brackets.
Hope this helps some.
-Nathan
From: Marc Gutowski
Sent: Wednesday, July 04, 2012 8:36 AM
To: [email protected]
Subject: [Nuke-python] [expression] for filename version extraction
doesn'twork..
Hey Guys,
my comp is named:
Code:
'E89________P_D_S__v004.nk'
when rendering a still, i want to include the
last digits(version number) '004' of the comp script in the filename.
in script editor i correctly can get the version number '004' via
Code:
re.match(r'(.*)(?<=\D)(\d+)', nuke.root().name().rpartition("/")[-1]
).groups()[-1]
in the filename knob, i added this string with escaped square brackets
Code:
[python re.match(r'(.*)(?<=\D)(\d+)',
nuke.root().name().rpartition("/")\[-1\]).groups()\[-1\] ]
but nuke gives a " 'NoneType' object has no attribute 'groups' " error message.
has anyone a hint for me, how to fix it
or an alternative way ?
--------------------------------------------------------------------------------
_______________________________________________
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