nxt.nxt_layer module
Ways to operate on and ask questions of nxt layers.
- class SAVE_KEY[source]
Bases:
object- VERSION = 'version'
- ALIAS = 'alias'
- MUTE = 'mute'
- SOLO = 'solo'
- REFERENCES = 'references'
- COMP_ORVERRIDES = 'comp_overrides'
- COLOR = 'color'
- META_DATA = 'meta_data'
- NODES = 'nodes'
- CWD = 'cwd'
- FILEPATH = 'filepath'
- REAL_PATH = 'real_path'
- ATTRS = 'attrs'
- NAME = 'name'
- LOCK = 'lock'
- class META_DATA_KEY[source]
Bases:
object- POSITIONS = 'positions'
- COLLAPSE = 'collapse'
- COLORS = 'colors'
- ALIASES = 'aliases'
- LOCKS = 'locks'
- class AUTHORING[source]
Bases:
object- CREATE = 'create'
- REFERENCE = 'reference'
- ABOVE = 0
- BELOW = 1
- class LayerReturnTypes[source]
Bases:
object- Node = 'Node'
- Path = 'Path'
- NodeTable = 'NodeTable'
- NameDict = 'NameDict'
- PathDict = 'PathDict'
- Boolean = 'Boolean'
- class SpecLayer(layer_data=None)[source]
Bases:
objectLayer object representing layer data from disk.
- RETURNS
alias of
nxt.nxt_layer.LayerReturnTypes
- classmethod load_from_filepath(filepath)[source]
Given a filepath, return a SpecLayer loaded from that path.
- Parameters
filepath (str) – path to file to load
- Returns
Loaded SpecLayer
- Return type
- reload_from_data(layer_data)[source]
Replace everything this layer holds with what the data says.
The layer object is kept. A stage holds its layers by object and so does everything looking at one – the target layer, the display layer, the layer tree, the source layer recorded on every node – so building a new layer and swapping it in would leave all of those pointing at a layer that is not in the graph.
What is not in the data is what does not belong to it: where the layer sits in the stack, which layer references it, which file it came from, and whether it is locked, which is a local opinion nobody writes to a file. Those are carried over.
What a layer references does come from the data, because that is what the file says this layer is built on, and the layers already loaded behind the references that survive are kept. Putting the stage’s stack back in step with the new list – loading what arrived, letting go of what went, and stacking them in the order the file gives – is Stage.settle_references, because the stack is the stage’s to hold, not one layer’s.
- Parameters
layer_data (dict) – clean dict of an nxt save file
- get_cached_child_paths(parent_path)[source]
Get the cached child paths for the given parent path. If no cache exists, None is returned.
- Parameters
parent_path (str) – Path to node that has children
- Returns
List of node paths or None
- Return type
list | None
- add_reference(layer_path=None, layer=None, insert_idx=None)[source]
Given a layer path, a layer object, or both, add a reference to specified layer on this layer, optionally at a specified insert index.
- Parameters
layer_path (str, optional) – Path to use as reference path, defaults to None, if None is given, defaults to given layer.real_path
layer (SpecLayer) – layer to add as reference layer in this layer
insert_idx (int, optional) – index to insert given layer at, defaults to None, if None is given, defaults to lowest reference layer.
- Returns
index given layer was inserted at.
- Return type
int
- Raises
ValueError – If not provided with a layer path or layer.
- rebased_references(old_dir, new_dir)[source]
How this layer’s relative references read from another folder.
A reference relative to this layer’s folder means a different file once the layer is somewhere else, so a copy saved elsewhere would have lost them. Each one that found its file beside the old folder is written again from the new one: relative if the file is beside the new folder too, whole if not. References that are absolute, use a variable or a token, are found through NXT_FILE_ROOTS, or find nothing at all are left as written, since none of those depend on this layer’s folder.
- Parameters
old_dir – the folder the layer was saved in
new_dir – the folder it is being saved to
- Returns
{reference as written now: reference to write instead}
- Return type
dict
- rebase_references(renamed)[source]
Write references, and the comp overrides that belong to them, under new names. See rebased_references.
- Parameters
renamed (dict) – {reference as written now: reference to write instead}
- get_alias(local=False, fallback_to_local=True)[source]
Get the layer’s alias (nice name). By default the local alias is returned, if local is False the parent layer’s opinion of the alias is returned. :param local: If True the local opinion is returned, if False the strongest override opinion is returned. :type local: bool :param fallback_to_local: if True and local is False and there is no override opinion the local alias is returned. If false and no override opinion is found None is returned. :return: string of layer alias or None
- set_alias_over(alias)[source]
Set a alias override on the root parent of a layer. :param alias: new alias string
- get_color(local=True, fallback_to_local=True)[source]
Get the layer’s color. By default the local color is retuned, if local is False the parent layer’s opinion of the alias is returned. :param local: bool :param fallback_to_local: if True and local is False and there is no override opinion the local color is returned. If false and no override opinion is found None is returned. :return: string of layer alias
- set_color_over(color)[source]
Set a color override on the root parent of a layer. :param color: hex color
- get_locked(local=False, fallback_to_local=True)[source]
Get the locked state of the layer. By default the local opinion is returned, if local is False the parent layer’s opinion of the alias is returned. :param local: If True the local opinion is returned, if False the strongest override opinion is returned. :type local: bool :param fallback_to_local: if True and local is False and there is no override opinion the local alias is returned. If false and no override opinion is found None is returned. :return: bool of layer’s lock state
- save(filepath=None, as_copy=False)[source]
Save this layer, optionally to new, given filepath.
Saved to another folder, relative references are written so they still find the same files from there. See rebased_references.
- Parameters
filepath (str, optional) – file path to save to, defaults to None
as_copy (bool) – write a copy and leave this layer as it is, where it is, rather than moving it to the new file
- class CompLayer[source]
Bases:
nxt.nxt_layer.SpecLayer
- class CacheLayer[source]
Bases:
nxt.nxt_layer.SpecLayer- was_during_node_exec(time_float)[source]
Checks if given time float is within any executed node’s exec timeframe. :param time_float: float of time :return: bool
- save(filepath)[source]
Save this layer, optionally to new, given filepath.
Saved to another folder, relative references are written so they still find the same files from there. See rebased_references.
- Parameters
filepath (str, optional) – file path to save to, defaults to None
as_copy (bool) – write a copy and leave this layer as it is, where it is, rather than moving it to the new file
- get_active_layers(layers)[source]
Given a list of layers, return those that should contribute to comp.
If there are soloed layers, only the soloed layers that are not muted will be returned. If there are not soloed layers, only the non-muted layers will be returned.
- Parameters
layers (list) – list of layers to filter
- Returns
list of layers that should contribute to a comp.
- Return type
list
- get_soloed_layers(layers)[source]
Given a list of layers, return only those that are soloed
- Parameters
layers (list) – list of layers to filter
- Returns
list of layers that are soloed.
- Return type
list
- get_muted_layers(layers)[source]
Given a list of layers, return only those that are muted
- Parameters
layers (list) – list of layers to filter
- Returns
list of layers that are muted.
- Return type
list
- get_node_local_attr_names(node_path, layers)[source]
Get all attribute names that are local to the given node path within the given layers.
NOTE that layers are filtered to active layers.
- Parameters
node_path (str) – node path to find local attributes of
layers (list) – list of layers to look for attributes of given node within
- Returns
list of local attributes found in given layers
- Return type
list
- order_nodes_dict(node_dict)[source]
Given a dictionary mapping node paths to node data, return an ordered dict where the keys are sorted.
- Parameters
node_dict (dict) – dictionary mapping node paths to node data
- Returns
ordered dctionary with keys sosrted
- Return type
OrderedDict
- class RankedList(items)[source]
Bases:
objectList that answers “where is this item” and “put this item at index i” in log time rather than by scanning.
Stage.sort_instances moves most of its items exactly once, and both list.index and list.remove scan from the front, which made the sort quadratic in node count. Items here sit in per position buckets with a Fenwick tree over the bucket sizes turning a bucket into a global index.
Items are matched by identity. The list scans this replaces matched by equality, but the items are (trace, node) pairs holding distinct node classes, so no two of them ever compare equal.
- sort_multidimensional_list(multi_list, sort_by_idx)[source]
Takes a multi-dimensional list and sorts it by the length of a sub-list item. The item who’s length we sort by is determined by the idx parameter. If your input is: ``` sort_multidimensional_list( [
[[1,2,3], [‘a’, ‘b’]], [[4,5,6], [‘a’]]
], idx = 1)
` Your output will be: `[[[1,2,3], [‘a’]], [[4,5,6], [‘a’, ‘b’]]
- Parameters
multi_list – multi-dimensional list
sort_by_idx – Index of sub list item to sort by
- Returns
list