mgear.flex.query module
flex.query
flex.query module contains a collection of functions useful for the analyze and update functions of Flex
- module:
flex.query
- mgear.flex.query.get_clean_matching_shapes(source, target)
Returns the prefix-less found shapes under the given groups
- Parameters:
source (string) – source group containing shapes in Maya
target (string) – target group containing shapes in Maya
- Returns:
The matching target shapes names without prefix
- Return type:
dict, dict
- mgear.flex.query.get_deformers(shape)
Returns a dict with each deformer found on the given shape
- Parameters:
shape (str) – the shape node name
- Returns:
the deformers found on shape sorted by type
- Return type:
dict
- mgear.flex.query.get_dependency_node(element)
Returns a Maya MFnDependencyNode from the given element
- Parameters:
element (string) – Maya node to return a dependency node class object
- Returns:
the element in a Maya MFnDependencyNode object
- Return type:
MFnDependencyNode
- mgear.flex.query.get_matching_shapes(source_shapes, target_shapes)
Returns the matching shapes
This Function will return a dict that contains the target matching shape name from the source.
- Parameters:
source_shapes (dict) – sources dictionary containing prefix-less shapes
target (dict) – targets dictionary containing prefix-less shapes
- Returns:
The matching target shapes names
- Return type:
dict
Note
This function is the core idea of how Flex finds matching shapes from a source group to the target. Because Flex is not part of a specific studio pipeline this matching is shapes name based. Because some studios might bring the source scene into the rig scene as a reference or as an import we cover those two cases.
Using this dict is the fastest way (so far found) to deal with a huge amount of names. Finding the matching names on a scene with more than 2000 shapes takes 0.0009… seconds.
- mgear.flex.query.get_matching_shapes_from_group(source, target)
Returns the matching shapes on the given groups
- Parameters:
source (string) – source group containing shapes in Maya
target (string) – target group containing shapes in Maya
- Returns:
The matching target shapes names
- Return type:
dict
- mgear.flex.query.get_missing_shapes(source_shapes, target_shapes)
Returns the missing shapes
This Function will return a dict that contains the missing shape found on the target.
- Parameters:
source_shapes (dict) – sources dictionary containing prefix-less shapes
target (dict) – targets dictionary containing prefix-less shapes
- Returns:
The missing target shapes names
- Return type:
dict
- mgear.flex.query.get_missing_shapes_from_group(source, target)
Returns the missing shapes from the given source and target group
- Parameters:
source (string) – source group containing shapes in Maya
target (string) – source group containing shapes in Maya
- Returns:
The missing target shapes names
- Return type:
dict
- mgear.flex.query.get_parent(element)
Returns the first parent found for the given element
- Parameters:
element (string) – A Maya dag node
- mgear.flex.query.get_prefix_less_dict(elements)
Returns a dict containing each element with a stripped prefix
This Function will return a dict that contains each element resulting on the element without the found prefix
- Parameters:
elements (list) – List of all your shapes
- Returns:
The matching prefix-less elements
- Return type:
dict
Note
Because Flex is not part of a specific studio pipeline we cover two different ways to bring the source shapes inside your rig. You can either import the source group with the meshes or use a Maya reference. This function will strip the prefix whether your object is part of a namespace or a double name getting a full path naming.
- mgear.flex.query.get_prefix_less_name(element)
Returns a prefix-less name
- Parameters:
elements (str) – element top use on the search
- Returns:
The prefix-less name
- Return type:
str
- mgear.flex.query.get_resources_path()
Gets the directory path to the resources files
- mgear.flex.query.get_shape_orig(shape)
Finds the orig (intermediate shape) on the given shape
- Parameters:
shape (str) – maya shape node
- Returns:
the found orig shape
- Return type:
str
Note
There are several ways of searching for the orig shape in Maya. Here we query it by first getting the given shape history on the component type attribute (inMesh, create..) then filtering on the result the same shape type. There might be more optimised and stable ways of doing this.
- mgear.flex.query.get_shape_type_attributes(shape)
Returns a dict with the attributes names depending on the shape type
This function returns the points, output, input and axes attributes for the corresponding shape type. Mesh type of nodes will be set as default but nurbs surfaces and nurbs curves are supported too.
- on mesh nodes: points = pnts
output = outMesh input = inMesh p_axes = (pntx, pnty, pntz)
- on nurbs nodes: points = controlPoints
output = local input = create p_axes = (xValue, yValue, zValue)
- Parameters:
shape (str) – maya shape node
- Returns:
corresponding attributes names
- Return type:
dict
- mgear.flex.query.get_shapes_from_group(group)
Gets all object shapes existing inside the given group
- Parameters:
group (str) – maya transform node
- Returns:
list of shapes objects
- Return type:
list str
- mgear.flex.query.get_temp_folder()
Returns the user temporary folder in a Maya friendly matter
- Returns:
temp folder path
- Return type:
str
- mgear.flex.query.get_transform_selection()
Gets the current dag object selection
Returns the first selected dag object on a current selection that is a transform node
- Returns:
the first element of the current maya selection
- Return type:
str
- mgear.flex.query.get_vertice_count(shape)
Returns the number of vertices for the given shape
- Parameters:
shape (string) – The maya shape node
- Returns:
The number of vertices found on shape
- Return type:
int
- mgear.flex.query.is_lock_attribute(element, attribute)
Returns if the given attribute on the element is locked
- Parameters:
element (string) – Maya node name
attribute (string) – Maya attribute name. Must exist
- Returns:
if attribute is locked
- Return type:
bool
- mgear.flex.query.is_matching_bouding_box(source, target, tolerance=0.05)
Checks if the source and target shape have the same bounding box
- Parameters:
source (string) – source shape node
target (string) – target shape node
tolerance (float) – difference tolerance allowed. Default 0.001
- Returns:
If source and target matches their bounding box
- Return type:
bool
- mgear.flex.query.is_matching_count(source, target)
Checks if the source and target shape have the same amount of vertices
- Parameters:
source (string) – source shape node
target (string) – target shape node
- Returns:
If source and target matches vertices count or not
- Return type:
bool
- mgear.flex.query.is_matching_type(source, target)
Checks if the source and target shape type matches
- Parameters:
source (string) – source shape node
target (string) – target shape node
- Returns:
If source and target matches or not
- Return type:
bool
- mgear.flex.query.is_maya_batch()
Returns if the current session is a Maya batch session or not
- Returns:
if Maya is on batch mode or not
- Return type:
bool
- mgear.flex.query.is_valid_group(group)
Checks if group is valid
Simply checks if the given group exists in the current Maya session and if it is a valid transform group.
- Parameters:
group (str) – a maya transform node
- Returns:
If the group is valid
- Return type:
bool
- mgear.flex.query.lock_unlock_attribute(element, attribute, state)
Unlocks the given attribute on the given element
- Parameters:
element (string) – Maya node name
attribute (string) – Maya attribute name. Must exist
state (bool) – If we should lock or unlock
- Returns:
If the setting was successful or not
- Return type:
bool