4040
4141def _transform_has_constraints (tfm_node ):
4242 constraints = cmds .listRelatives (
43- tfm_node , children = True , type = " pointConstraint" ) or []
43+ tfm_node , children = True , type = ' pointConstraint' ) or []
4444 constraints += cmds .listRelatives (
45- tfm_node , children = True , type = " parentConstraint" ) or []
45+ tfm_node , children = True , type = ' parentConstraint' ) or []
4646 has_constraints = len (constraints ) > 0
4747 return has_constraints
4848
@@ -69,37 +69,34 @@ def _is_world_space_node(node, start_frame, end_frame):
6969 return False
7070
7171 # Create node network to check if object is in world space.
72- cmds .loadPlugin (" matrixNodes" , quiet = True )
72+ cmds .loadPlugin (' matrixNodes' , quiet = True )
7373 worldspace_check_matrix_node = None
7474 result_decomp_node = None
75- # try:
7675 worldspace_check_matrix_node = cmds .createNode (
77- "multMatrix" ,
78- # name="mmSolver_cc_worldspace_check_node",
76+ 'multMatrix' ,
7977 skipSelect = True )
8078 result_decomp_node = cmds .createNode (
81- "decomposeMatrix" ,
82- # name="mmSolver_cc_worldspace_result_node",
79+ 'decomposeMatrix' ,
8380 skipSelect = True )
8481 cmds .connectAttr (
85- node + " .parentMatrix[0]" ,
86- worldspace_check_matrix_node + " .matrixIn[1]" ,
82+ node + ' .parentMatrix[0]' ,
83+ worldspace_check_matrix_node + ' .matrixIn[1]' ,
8784 force = True )
8885 cmds .connectAttr (
89- node + " .xformMatrix" ,
90- worldspace_check_matrix_node + " .matrixIn[2]" ,
86+ node + ' .xformMatrix' ,
87+ worldspace_check_matrix_node + ' .matrixIn[2]' ,
9188 force = True )
9289 cmds .connectAttr (
93- worldspace_check_matrix_node + " .matrixSum" ,
94- result_decomp_node + " .inputMatrix" ,
90+ worldspace_check_matrix_node + ' .matrixSum' ,
91+ result_decomp_node + ' .inputMatrix' ,
9592 force = True )
9693
9794 # Get single frame pos and rotation sum
9895 pos = cmds .getAttr (
99- result_decomp_node + " .outputTranslate" ,
96+ result_decomp_node + ' .outputTranslate' ,
10097 time = int (start_frame ))[0 ]
10198 rot = cmds .getAttr (
102- result_decomp_node + " .outputRotate" ,
99+ result_decomp_node + ' .outputRotate' ,
103100 time = int (end_frame ))[0 ]
104101 stored_sum = sum (pos ) + sum (rot )
105102
@@ -110,16 +107,15 @@ def _is_world_space_node(node, start_frame, end_frame):
110107 world_space_state = True
111108 for frame in range (start_frame , end_frame + 1 ):
112109 pos = cmds .getAttr (
113- result_decomp_node + " .outputTranslate" ,
110+ result_decomp_node + ' .outputTranslate' ,
114111 time = frame )[0 ]
115112 rot = cmds .getAttr (
116- result_decomp_node + " .outputRotate" ,
113+ result_decomp_node + ' .outputRotate' ,
117114 time = frame )[0 ]
118115 pos_rot_sum = sum (pos ) + sum (rot )
119116 if not pos_rot_sum == stored_sum :
120117 world_space_state = False
121118 break
122- # finally:
123119 if worldspace_check_matrix_node and cmds .objExists (worldspace_check_matrix_node ):
124120 cmds .delete (worldspace_check_matrix_node )
125121 if result_decomp_node and cmds .objExists (result_decomp_node ):
@@ -156,22 +152,21 @@ def __init__(self, parent=None, *args, **kwargs):
156152 self .full_bake_rdo_btn .clicked .connect (self .fullbake_space_radio_button_clicked )
157153 self .current_frame_rdo_btn .clicked .connect (self .fullbake_space_radio_button_clicked )
158154
159- self .loc_grp_node = None
160155 self .reset_options ()
161156
162157 def get_pivot_object (self ):
163158 """Set the pivot object widget as current selection."""
164159 selection = cmds .ls (selection = True , long = True ) or []
165160 if not len (selection ) == 1 :
166- LOG .warn (" Please select exactly one object." )
161+ LOG .warn (' Please select exactly one object.' )
167162 return
168163 self .pivot_object_text .setText (str (selection [0 ]))
169164
170165 def get_main_object (self ):
171166 """Set the main object widget as current selected transform."""
172167 selection = cmds .ls (selection = True , long = True , transforms = True ) or []
173168 if not len (selection ) == 1 :
174- LOG .warn (" Please select exactly one transform object." )
169+ LOG .warn (' Please select exactly one transform object.' )
175170 return
176171 self .main_object_text .setText (str (selection [0 ]))
177172 self .full_bake_rdo_btn .setChecked (True )
@@ -188,30 +183,30 @@ def fullbake_space_radio_button_clicked(self):
188183 def create_locator_group (self ):
189184 pivot_text = self .pivot_object_text .text ()
190185 main_text = self .main_object_text .text ()
191- if pivot_text == "" or main_text == "" :
192- LOG .warn (" Please get both pivot and main objects." )
186+ if pivot_text == '' or main_text == '' :
187+ LOG .warn (' Please get both pivot and main objects.' )
193188 return
194189 if not cmds .objExists (pivot_text ):
195- LOG .warn (" Could not find pivot object: %r" , pivot_text )
190+ LOG .warn (' Could not find pivot object: %r' , pivot_text )
196191 return
197192 if not cmds .objExists (main_text ):
198- LOG .warn (" Could not find main object: %r" , main_text )
193+ LOG .warn (' Could not find main object: %r' , main_text )
199194 return
200195
196+ loc_grp_node = None
201197 loc_grp_name = str (self .locator_group_text .text ())
202198 if not loc_grp_name :
203- LOG .warn (" Please type controller name." )
199+ LOG .warn (' Please type controller name.' )
204200 return
205201 if self .group_rdo_btn .isChecked ():
206- self . loc_grp_node = cmds .group (empty = True , name = loc_grp_name )
202+ loc_grp_node = cmds .group (empty = True , name = loc_grp_name )
207203 else :
208- self . loc_grp_node = cmds .spaceLocator (name = loc_grp_name )
204+ loc_grp_node = cmds .spaceLocator (name = loc_grp_name )
209205
210- # TODO: Should we de-select?
211- cmds .select (clear = True )
206+ return loc_grp_node
212207
213208 def create_controller_button_clicked (self ):
214- self .create_locator_group ()
209+ loc_grp_node = self .create_locator_group ()
215210
216211 # Set time
217212 start_frame , end_frame = time_utils .get_maya_timeline_range_inner ()
@@ -223,7 +218,6 @@ def create_controller_button_clicked(self):
223218 controller_name = self .locator_group_text .text ()
224219 pivot_node = self .pivot_object_text .text ()
225220 main_node = self .main_object_text .text ()
226- loc_grp_node = self .loc_grp_node
227221 camera = _get_viewport_camera ()
228222 space = None
229223 if self .world_space_rdo_btn .isChecked ():
@@ -233,7 +227,7 @@ def create_controller_button_clicked(self):
233227 elif self .screen_space_rdo_btn .isChecked ():
234228 space = const .CONTROLLER_TYPE_SCREEN_SPACE
235229 else :
236- LOG .error (" Invalid space." )
230+ LOG .error (' Invalid space.' )
237231 return
238232 smart_bake = self .smart_bake_rdo_btn .isChecked ()
239233 if not controller_name or not pivot_node or not main_node :
@@ -242,16 +236,16 @@ def create_controller_button_clicked(self):
242236 loc_grp_node = [loc_grp_node ]
243237 if self .screen_space_rdo_btn .isChecked ():
244238 if not camera :
245- LOG .warn (" Please select camera viewport." )
239+ LOG .warn (' Please select camera viewport.' )
246240 if cmds .objExists (loc_grp_node [0 ]):
247241 cmds .delete (loc_grp_node [0 ])
248242 return
249243
250244 # Check if main node has constraints already
251245 has_constraints = _transform_has_constraints (main_node )
252246 if has_constraints is True :
253- LOG .warn (" Main object has constraints already." )
254- cmds .delete (self . loc_grp_node )
247+ LOG .warn (' Main object has constraints already.' )
248+ cmds .delete (loc_grp_node )
255249 return
256250
257251 controller_nodes = lib .create_controller (
@@ -264,7 +258,7 @@ def create_controller_button_clicked(self):
264258 space ,
265259 smart_bake ,
266260 camera )
267- LOG .warn (" Success: Create Controller." )
261+ LOG .warn (' Success: Create Controller.' )
268262
269263 def reset_options (self ):
270264 # reset widgets to default
0 commit comments