|
21 | 21 | import mmSolver.logger |
22 | 22 | import mmSolver.utils.constant as const_utils |
23 | 23 | import mmSolver.utils.time as time_utils |
| 24 | +import mmSolver.utils.node as node_utils |
24 | 25 | import mmSolver.utils.tools as tools_utils |
25 | 26 | import mmSolver.tools.createcontroller2.lib as lib |
26 | 27 |
|
27 | 28 | LOG = mmSolver.logger.get_logger() |
28 | 29 |
|
29 | 30 |
|
30 | 31 | def main(): |
31 | | - selection = maya.cmds.ls(selection=True) |
32 | | - if not len(selection) == 1: |
33 | | - LOG.warn("Please select only one controller.") |
| 32 | + nodes = maya.cmds.ls( |
| 33 | + selection=True, |
| 34 | + long=True, |
| 35 | + type='transform') or [] |
| 36 | + if len(nodes) == 0: |
| 37 | + LOG.warn("Please select at least 1 transform.") |
34 | 38 | return |
35 | 39 | start_frame, end_frame = time_utils.get_maya_timeline_range_inner() |
| 40 | + |
| 41 | + # Sort nodes by depth, deeper nodes first, so we do do not remove |
| 42 | + # parents before children. |
| 43 | + nodes = node_utils.sort_nodes_by_depth(nodes, reverse=True) |
| 44 | + |
| 45 | + # Channels to bake. |
| 46 | + attrs = lib._get_selected_channel_box_attrs() |
| 47 | + if len(attrs) == 0: |
| 48 | + attrs = lib.TRANSFORM_ATTRS |
| 49 | + |
| 50 | + baked_nodes = [] |
36 | 51 | ctx = tools_utils.tool_context( |
37 | 52 | use_undo_chunk=True, |
38 | 53 | restore_current_frame=True, |
39 | 54 | use_dg_evaluation_mode=True, |
40 | 55 | disable_viewport=True, |
41 | 56 | disable_viewport_mode=const_utils.DISABLE_VIEWPORT_MODE_VP1_VALUE) |
42 | 57 | with ctx: |
43 | | - lib.remove_controller(selection[0], start_frame, end_frame) |
| 58 | + for node in nodes: |
| 59 | + if maya.cmds.objExists(node) is False: |
| 60 | + continue |
| 61 | + baked_nodes += lib.remove_controller( |
| 62 | + node, start_frame, end_frame, attrs=attrs) |
| 63 | + maya.cmds.select(baked_nodes, replace=True) |
44 | 64 | return |
45 | | - |
|
0 commit comments