--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/2269441f-f499-4a9a-9e08-8226214db73a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
If the leading 'v' is the relevant thing, would '_[Vv][0-9]+' do?
(Its just hunting for an underscore, lowercase OR uppercase v, then a string of numbers)
The re module also has a case insensitive flag:
re.search(r'_v\d+', 'hello_v001', re.I)
You can also limit it to a 3 padded version scheme if you want to go that far:
re.search(r'_v\d{3}', 'hello_v001', re.I)
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/201405041107.s44B7L7K011303%40atl4mhob05.myregisteredsite.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3Z7NVysf56bmqWX8dzjJ9i6bNhnJdy%3DoxBG4qK8D4jug%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CACt6GrmdFrv2E0U1qxoCFMmPi-3xwavk4JNMiWjXfsJ5mY-MwQ%40mail.gmail.com.
import re
name = 'hello_v001.ma'
regex = '^(?P<name>.*)_[vV](?P<version>[0-9]{3})\.(?P<extension>.*)$'
# notice the ?P<version> inside of the () groups
match = re.match(regex, name)
match.groupdict()
# Result: {'version': '001', 'name': 'hello', 'extension': 'ma'} #
Although the expression gets a little bit more obscure
Cheers!
Eduardo
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAkKjQE5%3DO3o%2B3FMa3bVotg33FJmnUqfjrrfbX6gW2yOQ%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/2ffb5a33-efa0-4365-b2a0-f8003019255a%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ba398c57-19f8-4096-8524-07f609f1496c%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD-0rkPSh1QZrzntoLmk7Fawst3%3DGHWmT5w0Fo0yEgn5Q%40mail.gmail.com.
You could do something like this:
>>> version = re.search(r'v\d+.nk', 'my_nukeFile_v12.nk').group()
>>> version
'v12.nk'
At this point, you are guaranteed to always have a ‘v’ infront, and that it will always end with ‘.nk’. At which point you could
>>> version = int(version[1:-3])
12
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAKW24e29hZ%3DgrJndzhGxpw1j%2BEgVPc6Oi%2Bdcop5d_DMTwxtxCg%40mail.gmail.com.
Sorry, I completely missed the part of your questions containing the example. :)
# 1. Get all string in a dict together with their version number
pattern = re.compile(r'\d+')
versions = {}
for test in v:
version = pattern.search(test).group()
version = int(version)
versions[version] = test
# 2. Sort version numbers and fill up a new list of strings
sorted_versions = []
for version in sorted(versions):
sorted_versions.append(versions[version])
print sorted_versions
['test_v1.ma', 'test_v2.ma' ...]
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOB1gRWVdmQW%3DpN83Th9tRfcgpquF135%2BnZw5uHf%3DFSN1g%40mail.gmail.com.
re.compile(r'\d+')
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOB1gRWVdmQW%3DpN83Th9tRfcgpquF135%2BnZw5uHf%3DFSN1g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAKW24e3iNZDGBFTweCyBR%3DfYTFugtM%2BPYf9ZidDuHDDWM4Q-dQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0h9_C7qLE6iy%3DLXtm9U%2BjCRpFEzupFn2zPEG-8FxjO3w%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAKW24e2TOXcVLf38S8ShKUGsZhZkrE0EWhqyewvLDUjoCKyJ_A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD%3Dnvg0WiedApoPYVUoNoc7s6H3sVRn0wSw33_QPA%3DHVg%40mail.gmail.com.
That’s a good point; paths could potentially be filled with rules that need to be broken down, re-defined often and remain well understood.
I would however argue whether or not it is a good idea to rely this heavily on paths in the first place, as it seems better suited for a schema.
About object composition and schemas, this is what I’m picturing as an alternative to (my understanding of) pyparsing:
>>> project.shot(1000).used_assets()
['myasset1', 'myasset2']
As opposed to
>>> path = '/projects/hulk/1000/used_assets/myasset1'
>>> project, shot, assets = parse(path)
As an alternative, a schema might be defined as:
['root', 'project', 'shot' ,'used_asset]
Which would map each level of a hierarchy to the respective index.
# For example
$ /myprojects/hulk/1000/myasset1
$ 0 1 2 3
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2o4Zos4gsmmFWKZkNWs9N9OEAGNuZEh6e3OTMjH6HJ5w%40mail.gmail.com.
Marcus that is exactly what you do with pyparsing.
If it helps to call it a schema then let's call it that. The list you made with the 4 string elements is that same as if you defined 4 word rules in pyparsing and the list itself is the same as the mechanism they give you to combine them into a grammar. This grammar can then be used to parse the path string. The only difference I see between what you are showing and what pyparsing seems to offer is that pyparsing would be more robust in defining the rules. For instance, you have just assigned indexes to a paths split components. But what if index 4 is different depending on what 3 evaluates to. What if 4 can be broken up into two individual components like res_colorspace? That is the stuff you could define as part of the grammar.
Also there isn't anything saying you couldn't wrap the parsing into something that gives you object oriented access like a Project object. But at some point, you will have a path and you will need to parse it to be able to generate the instances of your objects. Starting with the name of a project would be straightforward if you then wanted to access a shot off it by name.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOB6emfzNK%2BmJoLBG0JF79QdtUhgnk301vgf2LZGVMCTaA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3oUqQj%2B8NyUNHEvzdoEO%3DOJ%3DUKKDYkGFUQj3GQN2Zb2w%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAWLQD4WVrrTP%2BGQ7%2BOC4JoaHxbbVdES6zarNb3L7Ys_w%40mail.gmail.com.
Thank you for sharing the definition of a database schema with me. I would not have know this otherwise.I'm not going to further the debate since I think it's not going anywhere productive.
On Thu, May 8, 2014 at 7:59 AM, Marcus Ottosson <konstr...@gmail.com> wrote:
To be clear, schemas and parsing are not one and the same.It really isn't a matter of splitting hairs.This is an example of schemas in action.And the re module, and possibly pyparsing, is an example of parsing.On 7 May 2014 20:38, Justin Israel <justin...@gmail.com> wrote:
Marcus that is exactly what you do with pyparsing.
If it helps to call it a schema then let's call it that. The list you made with the 4 string elements is that same as if you defined 4 word rules in pyparsing and the list itself is the same as the mechanism they give you to combine them into a grammar. This grammar can then be used to parse the path string. The only difference I see between what you are showing and what pyparsing seems to offer is that pyparsing would be more robust in defining the rules. For instance, you have just assigned indexes to a paths split components. But what if index 4 is different depending on what 3 evaluates to. What if 4 can be broken up into two individual components like res_colorspace? That is the stuff you could define as part of the grammar.
Also there isn't anything saying you couldn't wrap the parsing into something that gives you object oriented access like a Project object. But at some point, you will have a path and you will need to parse it to be able to generate the instances of your objects. Starting with the name of a project would be straightforward if you then wanted to access a shot off it by name.
On May 8, 2014 12:05 AM, "Marcus Ottosson" <konstr...@gmail.com> wrote:That’s a good point; paths could potentially be filled with rules that need to be broken down, re-defined often and remain well understood.
I would however argue whether or not it is a good idea to rely this heavily on paths in the first place, as it seems better suited for a schema.
About object composition and schemas, this is what I’m picturing as an alternative to (my understanding of) pyparsing:
Objects
>>> project.shot(1000).used_assets() ['myasset1', 'myasset2']As opposed to
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAWLQD4WVrrTP%2BGQ7%2BOC4JoaHxbbVdES6zarNb3L7Ys_w%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0tuGQPb1gexKupGDgf74dp_6sB%2Br7oGqn4X7P%3DNqNjEw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAKW24e2TOXcVLf38S8ShKUGsZhZkrE0EWhqyewvLDUjoCKyJ_A%40mail.gmail.com.
Nice link.
Since its on topic in case anyone is interested, my coworker wrote a library for parsing sequences and managing complex ranges, called fileseq
https://github.com/sqlboy/fileseq
Pretty useful stuff that is common at studios
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CA%2B5uDBb4JYMR082LGeyTsjfPkE8p71ouvyB-8Aqa06RnuC-1Rg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA221ivebO62rR273hVtunU%3DvdX6dj%2BdRW8EyrOFvKRQNw%40mail.gmail.com.
Also this. :)
https://github.com/rsgalloway/pyseq
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CA%2B5uDBZwXBji5MkkW%3DPkeoBy4WoyVE%2BpzEvGBR9V6yukVSxHmQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAGCWdhnjQzcL2k6TBgHEdYkZUgh__Bv5b--L3SmqQEzirpK6FA%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWOhkeQWWX_42Tfs8Fx7as10n_QWR_S4T5k86WpDdKHLsA%40mail.gmail.com.
About regex, this book has helped me both initially and on numerous occasions and also gave me some perspective on some of the potential of regular expressions.
On 8 May 2014 09:05, Fredrik Averpil <fredrik...@gmail.com> wrote:
Regarding regex and such ... as long as you use scripts with predefine naming conventions, you can rely on the same regex always working. That's what we do here. In short, artists never get to name their files.This causes file structures to get basically unreadable as every scene or script file is generated by a script, but this is remedied by a project manager inside of Nuke/Maya (PySide) which translates these file's names into something more useful (based on a JSON containing a nicer and more descriptive name). This also makes it possible to rename files and folders whenever you like. It could cause some headache when rerouting Maya references, but apart from that - not so much issues.We don't use this for all software, though. Only for software which supports python and pyside. Works better than you'd think.Regards,Fredrik
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWOhkeQWWX_42Tfs8Fx7as10n_QWR_S4T5k86WpDdKHLsA%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/6367fc36-8880-4951-8e0e-6cab1dbcaa47%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Depends on your usage profile but I find I tend to grab chapters here and there - my sub lets me do that more effectively than when I was buying books.
If you're not wedded to having hardcopies, perhaps consider a safari subscription?
Depends on your usage profile but I find I tend to grab chapters here and there - my sub lets me do that more effectively than when I was buying books.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/201405161523.s4GFNL8O031581%40atl4mhob08.myregisteredsite.com.
For more options, visit https://groups.google.com/d/optout.
I think so, but its been a while since I had a physical copy to compare against.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBMK7KLsYJckjwrq3NNLDq5vJkdd%3Dyy1UGvnOHDihRdQg%40mail.gmail.com.
I think so, but its been a while since I had a physical copy to compare against.
Cool, thanks for letting me know, I’ll check it out.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/3a52b309-f103-48a1-998c-ae4f3cb3297a%40googlegroups.com.