General Utilities¶
artv2.utilities.general_utilities
| author: | Jeremy Ernst |
|---|---|
| description: | This module provides utilities usually for retrieving information, handling paths, building strings, saving and loading data, etc. |
-
convert_to_pynodes(nodes)[source]¶ Converts the incoming nodes to PyNodes and returns them.
Parameters: nodes – String list of nodes to convert. Returns: List of PyNodes
-
create_asset(asset_name)[source]¶ Create a container asset with the given asset name and return the created container. :param asset_name: Name for container. :return: pyNode of created asset.
-
create_clipboard(name, data)[source]¶ Creates a clipboard with the given name writing the given data to the clipboard.
Parameters: - name – The name of the file. It will be added to the temp dir.
- data – The data to write to the file
Returns: The clipboard file
-
create_trailing_number(value)[source]¶ Creates a trailing number string with a padded 0 if the number is less than or equal to 9. Example 08 or 18.
Parameters: value – The value to crates a trailing number in string format for Returns: string
-
delete_node(node)[source]¶ Deletes node, but first makes sure the node is not locked. :param node: DAG node to delete :type node: PyNode
-
filter_directory_contents(path, filters, ext_filters)[source]¶ Filter the contents from the incoming path using the provided filters and extension filters. This is only checking for files.
Parameters: - path – The path to list contents and the filter the contents.
- filters – The filters to look for before the file extension for exclusion.
- ext_filters – The file extensions to look for for exclusion.
Returns: List of filtered contents.
-
filter_nodes(nodes, filter_by='transform')[source]¶ Filters the given nodes by the given type and returns the filtered nodes as a list. :param nodes: List of nodes to filter. :param str filter_by: Types of nodes to return. :return: List of filtered nodes.
-
generate_prefix_suffix(string)[source]¶ Tries to generate a mirrored prefix or suffix given the input string.
Parameters: string – input string to try and create a mirrored version. Returns: Returns a string with the prefix or suffix. If a match in the dict was found, it will return a mirrored version. Otherwise, it simply returns the input string. For example, given a component name of clavicle_joint_l, where the prefix is clavicle and the suffix is l, passing clavicle into this function simply retruns clavicle. Passing l into the function will return r. So, if a component passes its prefix and suffix to this function to try and generate a mirrored version, you would get clavicle and r.
-
generate_unique_suffix(existing, inst)[source]¶ Generates a unique suffix to avoid naming conflicts when duplicating components.
Parameters: - existing – Dict of existing components in the scene.
- inst – instance of component that is being duplicated.
Returns: Returns a string with the unique suffix.
-
get_class_properties(cls)[source]¶ Given a class, retrieve the properties of the class (as indicated by the @property decorator)
Parameters: cls – class instance Returns: dict of property names and values
-
get_control_shapes()[source]¶ Looks in the resources directory to find the control shapes and returns the name of the files without the extension.
Returns: Returns a list of the names of the files without the extension.
-
get_control_shapes_as_enum(shapes_list)[source]¶ Takes in a list of control shapes (usually generated from get_control_shapes()), and builds an enum string.
Parameters: shapes_list – A list of strings. Returns: A string that is build to be used as an enum for a Maya enum attribute (ex: circle:square:cube)
-
get_joints_in_hierarchy(root=None, as_pynode=False)[source]¶ Gets the joints in a hierarchy and returns them. If a root joint is given, it will search from there. If not, it will select everything in the scene and find the joints that way instead. :param root: (Optional) Name of joint at the top of the hierarchy you wish to search. :param as_pynode: Bool as whether to return the list as PyNodes or strings. :return: Returns either a list of PyNodes or strings of the joints in the hierarchy.
-
get_root_joint_of_component(joints)[source]¶ Finds and returns the top-most joint of a component.
Parameters: joints – List of Pynodes of joints from the component. Returns: Pynode of top-most joint.
-
import_file(path, return_nodes=False)[source]¶ Imports the given file into Maya. :param path: Path of file to import :param return_nodes: Whether or not to return created nodes. :return: list of imported nodes
-
launch_web_docs(page)[source]¶ Launches the given html file in a web browser.
Parameters: page – string file path of html file.
-
load_from_file(path)[source]¶ Loads data (using JSON) for the given file and returns the data loaded.
Parameters: path – The file path to load data from. Returns: Data from the file.
-
parent_object(child, parent)[source]¶ Parents the child to the parent object.
Parameters: - child (str) – Name of node to be parented.
- parent (str) – Name of node that will be the parent.
-
path_join(path_base, path_tail)[source]¶ Take the incoming path and file and use os.path.join to create a new file path. Then replace all back slashes with forward slashes.
Parameters: - path_base (str) – First part of path to join.
- path_tail (str) – Second part of path to join.
Returns: Joined path with proper separators.
Return type: str
-
path_unify(path)[source]¶ Take the incoming path and replace back slashes with forward slashes.
Parameters: path (str) – Incoming path to manipulate. Returns: Corrected path with correct separators. Return type: str
-
read_clipboard(clipboard)[source]¶ Given a clipboard file, read and return the data.
Parameters: clipboard – File path of the clipboard file. Returns: Data from file.
-
rename_object(pynode, new_name)[source]¶ Renames the incoming PyNode with the given new name.
Parameters: - pynode (pymel.core.PyNode) – PyNode that represents the object to rename.
- new_name (str) – The new name for the node.
-
retrieve_clipboard(name)[source]¶ Return the file path to the clipboard with the given name
Parameters: name – the name of the clipboard file Returns: The full file path to the clipboard
-
return_settings()[source]¶ Returns ARTv2 settings for the paths to various needed directories.
Returns: Array of path names to directories needed by the tools. Return type: str, []
-
save_to_file(path, data)[source]¶ Dumps the given data (using JSON) to the given path.
Parameters: - path – Path to write data to on disk.
- data – Data to dump to file.
-
set_attribute(node, attr, value, attr_type=None)[source]¶ Sets an attribute on the given node to the given value. Ensures node and attribute is unlocked before doing so, and re-locks them after.
Parameters: - node (pm.PyNode) – Node to set attribute on.
- attr (str) – Attribute on node to set.
- value (float, int, bool, string) – Value to set attribute to.
- attr_type (str) – Whether or not a special type needs to be defined (string, bool, etc)
-
strip_name(name_to_strip, prefix, base_name, suffix)[source]¶ Strip a name down to whatever is left after removing the prefix, base name, and suffix.
Parameters: - name_to_strip (str) – The name to tokenize.
- prefix (str) – The prefix to remove from the name.
- base_name (str, None) – The base name of the component to remove from the name.
- suffix (str) – The suffix to remove from the name.
Returns: The name with the prefix, suffix, and base name removed.
Return type: str
-
validate_integer(value, int_min, int_max)[source]¶ Given a value, validate that it is a whole number that is greater than or equal to the minimum and less than or equal to the maximum given values.
Parameters: - value – The value to check
- int_min – The minimum the value can be
- int_max – The maximum the value can be
Returns: (bool) True if value is meets conditions. False otherwise.