def __setup(self): if not self._parentType: #--- None if self._controlChain: for i, ctl in enumerate(self.controls): j = i + 1 if not j == len(self.controls): attribute.lock_all(self.controls[j].group, True) cmds.parent(self.controls[j].group, ctl.transform) attribute.lock_all(self.controls[j].group) if self._parentType == 'parent': #--- parent for i, ctl in enumerate(self.controls): if self._controlChain: j = i + 1 if not i: attribute.lock_all(self.controls[i].group, True) cmds.parent(self.controls[i].group, self.main_control.gimbal) attribute.lock_all(self.controls[i].group) if not j == len(self.controls): attribute.lock_all(self.controls[j].group, True) cmds.parent(self.controls[j].group, ctl.transform) attribute.lock_all(self.controls[j].group) else: attribute.lock_all(ctl.group, True) cmds.parent(ctl.group, self.main_control.gimbal) attribute.lock_all(ctl.group) elif self._parentType == 'constraint': #--- constraint for i, ctl in enumerate(self.controls): if self._controlChain: j = i + 1 if not i: attribute.lock_all(self.controls[i].group, True) node.parentConstraint(self.main_control.gimbal, self.controls[i].group) for axis in 'xyz': cmds.connectAttr( self.main_control.transform + '.globalScale', self.controls[i].group + '.s' + axis) attribute.lock_all(self.controls[i].group) if not j == len(self.controls): attribute.lock_all(self.controls[i].group, True) cmds.parent(self.controls[j].group, ctl.transform) attribute.lock_all(self.controls[i].group) else: node.parentConstraint(self.main_control.gimbal, ctl.group) for axis in 'xyz': cmds.setAttr(ctl.group + '.s' + axis, lock=False) cmds.connectAttr( self.main_control.transform + '.globalScale', ctl.group + '.s' + axis) cmds.setAttr(ctl.group + '.s' + axis, lock=True)
def __setup(self): if not self._parentType: #--- None if self._controlChain: for i, ctl in enumerate(self.controls): j = i + 1 if not j == len(self.controls): attribute.lock_all(self.controls[j].group, True) cmds.parent(self.controls[j].group, ctl.transform) attribute.lock_all(self.controls[j].group) if self._parentType == 'parent': #--- parent for i, ctl in enumerate(self.controls): if self._controlChain: j = i + 1 if not i: attribute.lock_all(self.controls[i].group, True) cmds.parent(self.controls[i].group, self.main_control.gimbal) attribute.lock_all(self.controls[i].group) if not j == len(self.controls): attribute.lock_all(self.controls[j].group, True) cmds.parent(self.controls[j].group, ctl.transform) attribute.lock_all(self.controls[j].group) else: attribute.lock_all(ctl.group, True) cmds.parent(ctl.group, self.main_control.gimbal) attribute.lock_all(ctl.group) elif self._parentType == 'constraint': #--- constraint for i, ctl in enumerate(self.controls): if self._controlChain: j = i + 1 if not i: attribute.lock_all(self.controls[i].group, True) node.parentConstraint(self.main_control.gimbal, self.controls[i].group) for axis in 'xyz': cmds.connectAttr(self.main_control.transform + '.globalScale', self.controls[i].group + '.s' + axis) attribute.lock_all(self.controls[i].group) if not j == len(self.controls): attribute.lock_all(self.controls[i].group, True) cmds.parent(self.controls[j].group, ctl.transform) attribute.lock_all(self.controls[i].group) else: node.parentConstraint(self.main_control.gimbal, ctl.group) for axis in 'xyz': cmds.setAttr(ctl.group + '.s' + axis, lock=False) cmds.connectAttr(self.main_control.transform + '.globalScale', ctl.group + '.s' + axis) cmds.setAttr(ctl.group + '.s' + axis, lock=True)
def __setup(self): if not self._parentType: return if self._parentType == 'parent': #--- parent for ctl in self.controls: attribute.lock_n_hide(ctl.group, ['t', 'r', 's'], True) cmds.parent(ctl.group, self.main_control.gimbal) attribute.lock_n_hide(ctl.group, ['t', 'r', 's']) elif self._parentType == 'constraint': #--- constraint for ctl in self.controls: node.parentConstraint(self.main_control.gimbal, ctl.group) for axis in 'xyz': cmds.setAttr(ctl.group + '.s' + axis, lock=False) cmds.connectAttr( self.main_control.transform + '.globalScale', ctl.group + '.s' + axis) cmds.setAttr(ctl.group + '.s' + axis, lock=True)
def __create_constraints(self, mesh, ctl): """ @type mesh: string @param mesh: specify the mesh @type ctl: string @param ctl: specify the control """ attribute.lock_all(mesh, True) pac = node.parentConstraint(ctl, mesh) scn = node.scaleConstraint(ctl, mesh) self.lock.append(pac) self.lock.append(scn) if self._addScaleToControl: for c in self._addScaleToControl: if c == ctl: scn = node.scaleConstraint(ctl, mesh) self.lock.append(scn) attribute.lock_all(mesh)
def constraint(controlToTransform={}, constraint=None, maintainOffset=True): """ @type controlToTransform: dict @param controlToTransform: specify a key(control) and value(transform), ie. controlToTransform={'controlA:meshB} controlToTransform={'controlA:[meshB, meshC,..]} @type constraint: string @param constraint: valid are parent-, point-, orient-, scaleConstraint if None (as default) is set, a parent and scaleConstraint will be created automatically @type maintainOffset: boolean @param maintainOffset: Set to True or False """ msg = "controlToTransform: Please specify a valid key and a valid value" assert controlToTransform, msg for obj in controlToTransform.items(): key = obj[0] value = obj[1] msg = "constraint: Key object does not exist: " + str(key) assert cmds.objExists(key), msg if isinstance(value, list): #--- value is a list for v in value: if constraint == 'parentConstraint': node.parentConstraint(objA=key, objB=v, maintainOffset=maintainOffset) elif constraint == 'pointConstraint': node.pointConstraint(objA=key, objB=v, maintainOffset=maintainOffset) elif constraint == 'orientConstraint': node.orientConstraint(objA=key, objB=v, maintainOffset=maintainOffset) elif constraint == 'scaleConstraint': node.scaleConstraint(objA=key, objB=v, maintainOffset=maintainOffset) else: node.parentConstraint(objA=key, objB=v, maintainOffset=maintainOffset) node.scaleConstraint(objA=key, objB=v, maintainOffset=maintainOffset) else: #--- value is a string if constraint == 'parentConstraint': node.parentConstraint(objA=key, objB=value, maintainOffset=maintainOffset) elif constraint == 'pointConstraint': node.pointConstraint(objA=key, objB=value, maintainOffset=maintainOffset) elif constraint == 'orientConstraint': node.orientConstraint(objA=key, objB=value, maintainOffset=maintainOffset) elif constraint == 'scaleConstraint': node.scaleConstraint(objA=key, objB=value, maintainOffset=maintainOffset) else: node.parentConstraint(objA=key, objB=value, maintainOffset=maintainOffset) node.scaleConstraint(objA=key, objB=value, maintainOffset=maintainOffset)
def __constraint_flexiplane(self): """ Constraint the main control by specified nodes """ #--- check given flags if not self._constraintTo == [None, None]: msg = 'Specified node: ' + self._constraintTo[0] + 'does not exist!' assert cmds.objExists(self._constraintTo[0]), msg assert cmds.objExists(self._constraintTo[1]), msg #--- constraint the controls to proper positions pac = node.parentConstraint(objA=self._constraintTo, objB=self.control_main.transform, maintainOffset=False) pcn_down = node.pointConstraint(objA=self._constraintTo[0], objB=self.control_down.transform, maintainOffset=False) pcn_up = node.pointConstraint(objA=self._constraintTo[1], objB=self.control_up.transform, maintainOffset=False) cmds.delete(pac, pcn_down, pcn_up) #--- constraint the controls by given flag constraintType #--- parent = parentConstraint if self._constraintType == 'parent': node.parentConstraint(objA=self._constraintTo[0], objB=self.control_down.transform, suffix='PAC', maintainOffset=False) node.parentConstraint(objA=self._constraintTo[1], objB=self.control_up.transform, suffix='PAC', maintainOffset=False) #--- lock constraint attributes attribute.lock_attributes( [self.control_down.transform, self.control_up.transform], ['t', 'r']) #--- point = pointConstraint elif self._constraintType == 'point': node.pointConstraint(objA=self._constraintTo[0], objB=self.control_down.transform, suffix='PCN', maintainOffset=False) node.pointConstraint(objA=self._constraintTo[1], objB=self.control_up.transform, suffix='PCN', maintainOffset=False) #--- lock constraint attributes attribute.lock_attributes( [self.control_down.transform, self.control_up.transform], ['t']) #--- orient = orientConstraint elif self._constraintType == 'orient': node.orientConstraint(objA=self._constraintTo[0], objB=self.control_down.transform, suffix='OCN', maintainOffset=False) node.orientConstraint(objA=self._constraintTo[1], objB=self.control_up.transform, suffix='OCN', maintainOffset=False) #--- lock constraint attributes attribute.lock_attributes( [self.control_down.transform, self.control_up.transform], ['r'])