common.sequence#

Common methods used to work with sequentially numbered file items.

A sequence item is a file that has a number component that can be incremented. See get_sequence(). E.g.:

1s = 'C:/test/my_image_sequence_0001.png'
2seq = common.get_sequence(s)

A collapsed item is a single item that refers to a series of sequence items and is marked by the SEQSTART, sequence range and SEQEND characters. See is_collapsed(). E.g.:

1s = 'C:/test/my_image_sequence_{1-200}.png'
2common.is_collapsed(s) # = True

Functions:

get_sequence(s)

Checks if the given text contains a sequence element.

get_sequence_end_path(path)

Checks if given string is collapsed, and if so, returns the path of the last item of the sequence.

get_sequence_paths(index)

Return a list of file paths of the individual files that make up the sequence.

get_sequence_start_path(path)

Checks if given string is collapsed, and if so, returns the path of the first item of the sequence.

is_collapsed(s)

Checks the presence SEQSTART and SEQEND markers.

proxy_path(v)

Substitutes range notations (e.g.

Data:

GetSequenceRegex

Regular expression used to get the path components of a collapsed sequence

IsSequenceRegex

Regular expression used to find sequence items

SEQEND

End character used to encapsulate the sequence range of collapsed items.

SEQPROXY

Placeholder sequence marker used to associate settings and database values with sequence items.

SEQSTART

Start character used to encapsulate the sequence range of collapsed items.

SequenceEndRegex

Regular expression used to get the last frame of a collapsed sequence

SequenceStartRegex

Regular expression used to get the first frame of a collapsed sequence

bookmarks.common.sequence.get_sequence(s)[source]#

Checks if the given text contains a sequence element.

Strictly speaking, a sequence is any file that has a valid number element. There can only be one incremental element - it will always be the number closest to the end.

The regex will understand sequences with the v prefix, eg v001, v002, but works without the prefix as well. E.g. 001, 002. In the case of a filename like job_sh010_animation_v002.c4d 002 will be the prevailing sequence number, ignoring the number in the extension.

Likewise, in job_sh010_animation_v002.0001.c4d the sequence number will be 0001, and not 010 or 002.

1s = 'job_sh010_animation_v002_username.c4d'
2m = get_sequence(s)
3if m:
4    prefix = match.group(1)
5    sequence_number = match.group(2)
6    suffix = match.group(3)
7    extension = match.group(4)
Parameters:

s (str) – A file path.

Returns:

All the characters before the sequence number. group 2 (SRE_Match): The sequence number, as a string. group 3 (SRE_Match):

All the characters after the sequence number up until the file extensions.

group 4 (SRE_Match): The file extension without the ‘.’ dot.

Return type:

group 1 (SRE_Match)

bookmarks.common.sequence.get_sequence_end_path(path)[source]#

Checks if given string is collapsed, and if so, returns the path of the last item of the sequence.

Parameters:

path (str) – A collapsed sequence name.

Returns:

The path to the last file of the sequence.

Return type:

str

bookmarks.common.sequence.get_sequence_paths(index)[source]#

Return a list of file paths of the individual files that make up the sequence.

Parameters:

index (QtCore.QModelIndex) – A list view index.

Returns:

A list of file paths.

Return type:

list

bookmarks.common.sequence.get_sequence_start_path(path)[source]#

Checks if given string is collapsed, and if so, returns the path of the first item of the sequence.

Parameters:

path (str) – A collapsed sequence name.

Returns:

The path to the first file of the sequence.

Return type:

str

bookmarks.common.sequence.is_collapsed(s)[source]#

Checks the presence SEQSTART and SEQEND markers.

When Bookmarks is displaying a sequence of files as a single item, the item is collapsed. Every collapsed item contains the SEQEND, sequence range and SEQSTART elements.

Example

1filename = 'job_sh010_animation_{001-299}_gw.png'
2m = is_collapsed(filename)
3prefix = match.group(1) # = 'job_sh010_animation_'
4sequence_string = match.group(2) # = '{001-299}'
5suffix = match.group(3) # = '_gw.png'
Parameters:

s (str) – A file path.

Returns:

  • group(1) - All the characters before the sequence marker.

  • group(2) - The sequence marker, e.g. {01-50}.

  • group(3) - All characters after the sequence marker.

Return type:

SRE_Match

bookmarks.common.sequence.proxy_path(v)[source]#

Substitutes range notations (e.g. {001-099}) with SEQPROXY.

Any non-collapsed items will use their actual file path. Collapsed sequence items however, need to be represented in a manner independent of their actual start, end and length to associate preferences with them consistently.

Parameters:

v (QModelIndex, weakref.ref, dict or str) – Data dict, index or filepath.

Returns:

The key used to store the item’s information in the local preferences and the bookmark item database.

Return type:

str

bookmarks.common.sequence.GetSequenceRegex = re.compile('^(.*?)([0-9]+)([0-9\\\\/]*|[^0-9\\\\/]*(?=.+?))\\.([^\\.]+)$', re.IGNORECASE)#

Regular expression used to get the path components of a collapsed sequence

bookmarks.common.sequence.IsSequenceRegex = re.compile('^(.+?)({.*})(.*)$', re.IGNORECASE)#

Regular expression used to find sequence items

bookmarks.common.sequence.SEQEND = '}'#

End character used to encapsulate the sequence range of collapsed items.

bookmarks.common.sequence.SEQPROXY = '{0}'#

Placeholder sequence marker used to associate settings and database values with sequence items.

bookmarks.common.sequence.SEQSTART = '{'#

Start character used to encapsulate the sequence range of collapsed items.

bookmarks.common.sequence.SequenceEndRegex = re.compile('^(.*){.*?([0-9]+)}(.*)$', re.IGNORECASE)#

Regular expression used to get the last frame of a collapsed sequence

bookmarks.common.sequence.SequenceStartRegex = re.compile('^(.*){([0-9]+).*}(.*)$', re.IGNORECASE)#

Regular expression used to get the first frame of a collapsed sequence