def RemoveAffectedObject(self, ControlObject, removeObjectList, VisibilitySwitch='visibility', visibilityType="visibility"): ControlObject = RMRigTools.validate_pymel_nodes(ControlObject) removeObjectList = RMRigTools.validate_pymel_nodes(removeObjectList) '''visibilityType valid values are overrideVisibility, lodVisibility or visibility''' AffectedObjectList = self.GetAfectedObjectsList( ControlObject, VisibilitySwitch=VisibilitySwitch) for eachObject in removeObjectList: if eachObject in AffectedObjectList: pm.disconnectAttr( ("%s.%s" % (ControlObject, VisibilitySwitch)), ("%s.%s" % (eachObject, visibilityType)))
def RMCircularControl(Obj, radius=1, NameConv=None, axis="X", name=""): Obj = RMRigTools.validate_pymel_nodes(Obj) if not NameConv: NameConv = nameConvention.NameConvention() if name == '': defaultName = "circularControl" else: defaultName = name if axis in "yY": Ctrl, Shape = pm.circle(normal=[0, 1, 0], radius=radius, name=defaultName) elif axis in "zZ": Ctrl, Shape = pm.circle(normal=[0, 0, 1], radius=radius, name=defaultName) elif axis in "xX": Ctrl, Shape = pm.circle(normal=[1, 0, 0], radius=radius, name=defaultName) if name == '' and NameConv.is_name_in_format(Obj): NameConv.rename_based_on_base_name(Obj, Ctrl) else: NameConv.rename_based_on_base_name(Obj, Ctrl, name=Ctrl) NameConv.rename_set_from_name(Ctrl, "control", "objectType") RMRigTools.RMAlign(Obj, Ctrl, 3) ResetGroup = RMRigTools.RMCreateGroupOnObj(Ctrl) return ResetGroup, Ctrl
def RMCircularControl(self, Obj, radius=1, axis="X", name=""): Obj = RMRigTools.validate_pymel_nodes(Obj) if name == '': defaultName = "circularControl" else: defaultName = name if axis in "yY": Ctrl, Shape = pm.circle(normal=[0, 1, 0], radius=radius, name=defaultName) elif axis in "zZ": Ctrl, Shape = pm.circle(normal=[0, 0, 1], radius=radius, name=defaultName) elif axis in "xX": Ctrl, Shape = pm.circle(normal=[1, 0, 0], radius=radius, name=defaultName) if name == 'circularControl': if self.NameConv.is_name_in_format(Obj): self.NameConv.rename_based_on_base_name(Obj, Ctrl) else: self.NameConv.rename_name_in_format(Ctrl, name=name, objectType='control') else: self.NameConv.rename_name_in_format(Ctrl, name=name, objectType='control') RMRigTools.RMAlign(Obj, Ctrl, 3) ResetGroup = self.rigTools.RMCreateGroupOnObj(Ctrl) return ResetGroup, Ctrl
def get_oposite(scene_object): if scene_object.__class__ is list: return_list = True else: return_list = False scene_object = [scene_object] result_list = [] for each_object in scene_object: each_object = RMRigTools.validate_pymel_nodes(each_object) namespace_tokens = each_object.split(':') if len(namespace_tokens) > 1: namespace = '%s:' % namespace_tokens[0] splitName = namespace_tokens[1] else: namespace = '' splitName = str(each_object) token_list = splitName.split('_') if token_list[1] in ['FR', 'MR', 'BR', 'FL','ML', 'BL', 'C', 'R','L']: if 'L' in token_list[1]: token_list[1] = token_list[1].replace('L', 'R') else: if 'R' in token_list[1]: token_list[1] = token_list[1].replace('R', 'L') if pm.objExists('%s%s' % (namespace, '_'.join(token_list))): result_list.append(RMRigTools.validate_pymel_nodes('%s%s' % (namespace, '_'.join(token_list)))) else: print 'no oposite found for object %s' % each_object else: if token_list[0] in ['FR', 'MR', 'BR', 'FL', 'ML', 'BL', 'C', 'R', 'L']: if 'L' in token_list[0]: token_list[0] = token_list[0].replace('L', 'R') else: if 'R' in token_list[0]: token_list[0] = token_list[0].replace('R', 'L') if pm.objExists('%s%s' % (namespace, '_'.join(token_list))): result_list.append(RMRigTools.validate_pymel_nodes('%s%s' % (namespace, '_'.join(token_list)))) else: print 'no oposite found for object %s' % each_object if return_list: return result_list else: if len(result_list) == 1: return result_list[0] else: return None
def ConstraintVisibility(self, Objects, ControlObject, VisibilitySwitch='visibility', visibilityType="visibility"): Objects = RMRigTools.validate_pymel_nodes(Objects) ControlObject = RMRigTools.validate_pymel_nodes(ControlObject) '''visibilityType valid values are overrideVisibility, lodVisibility or visibility''' if (self.AddEnumParameters(ControlObject, VisibilitySwitch=VisibilitySwitch)): for eachObject in Objects: RMRigTools.RMLockAndHideAttributes(eachObject, "xxxxxxxxxL") RMRigTools.RMLockAndHideAttributes(eachObject, "xxxxxxxxxh") # print ("connecting Visibility %s.%s to %s.%s"%(ControlObject,VisibilitySwitch,eachObject,visibilityType) ) pm.connectAttr("%s.%s" % (ControlObject, VisibilitySwitch), "%s.%s" % (eachObject, visibilityType)) else: print "Not Valid Object"
def AddAffectedObject(self, ControlObject, addObjectList, VisibilitySwitch='visibility', visibilityType="visibility"): ControlObject = RMRigTools.validate_pymel_nodes(ControlObject) addObjectList = RMRigTools.validate_pymel_nodes(addObjectList) '''visibilityType valid values are overrideVisibility, lodVisibility or visibility''' for eachObject in addObjectList: inputConnections = pm.listConnections("%s.%s" % (eachObject, visibilityType), plugs=True, destination=True) if inputConnections: if len(inputConnections) > 0: pm.disconnectAttr(inputConnections[0], "%s.%s" % (eachObject, visibilityType)) pm.connectAttr("%s.%s" % (ControlObject, VisibilitySwitch), "%s.%s" % (eachObject, visibilityType), force=True)
def RMCreateBoxCtrl(self, Obj, Xratio=1, Yratio=1, Zratio=1, ParentBaseSize=False, customSize=0, name="", centered=False): Obj = RMRigTools.validate_pymel_nodes(Obj) if name == "": defaultName = "BoxControl" else: defaultName = name Parents = pm.listRelatives(Obj, parent=True) if Parents and len(Parents) != 0 and ParentBaseSize == True: JntLength = RMRigTools.RMLenghtOfBone(Parents[0]) Ctrl = RMCreateCubeLine(JntLength * Xratio, JntLength * Yratio, JntLength * Zratio, name=defaultName, centered=centered) else: if customSize != 0: JntLength = customSize elif pm.objectType(Obj) == "joint": JntLength = RMRigTools.RMLenghtOfBone(Obj) else: JntLength = 1 Ctrl = RMCreateCubeLine(JntLength * Xratio, JntLength * Yratio, JntLength * Zratio, name=defaultName, centered=centered) if name == '' and self.NameConv.is_name_in_format(Obj): self.NameConv.rename_based_on_base_name(Obj, Ctrl) else: self.NameConv.rename_based_on_base_name(Obj, Ctrl, name=Ctrl) self.NameConv.rename_set_from_name(Ctrl, "control", "objectType") RMRigTools.RMAlign(Obj, Ctrl, 3) ResetGroup = self.rigTools.RMCreateGroupOnObj(Ctrl) return ResetGroup, Ctrl
def getControlEnums(self, Node, attribute='Visibility'): ''' returns all the enums in an object attribute ''' Node = RMRigTools.validate_pymel_nodes(Node) AttributeList = pm.listAttr(Node) if attribute in AttributeList: if pm.getAttr(Node + "." + attribute, type=True) == 'enum': ValidValues = pm.addAttr(Node + "." + attribute, q=True, enumName=True) ValidValuesList = ValidValues.split(":") return ValidValuesList else: return []
def AddEnumParameters(self, Object, VisibilitySwitch='visibility'): Object = RMRigTools.validate_pymel_nodes(Object) Enum = ["Off", "On"] AttributeList = pm.listAttr(Object) if VisibilitySwitch in AttributeList: if pm.getAttr(Object + "." + VisibilitySwitch, type=True) == 'enum': return True else: pm.addAttr(Object, at="enum", ln=VisibilitySwitch, k=1, en=":".join(Enum)) return True return None
def GetEnumVisibilityList(self, ControlObject): ''' returns all the attributes in the control object that are presumably visibility switches, it checks two things, been an enum Attribute and have On Off Values. ''' ControlObject = RMRigTools.validate_pymel_nodes(ControlObject) VisibilityEnumList = [] AttributeList = None AttributeList = pm.listAttr(ControlObject, visible=True, keyable=True) if AttributeList != None: for eachEnum in AttributeList: if pm.getAttr(ControlObject + "." + eachEnum, type=True) == 'enum': EnumValues = self.getControlEnums(ControlObject, attribute=eachEnum) if (EnumValues[0] == "Off" and EnumValues[1] == "On"): VisibilityEnumList.append(eachEnum) return VisibilityEnumList
def surface_base(self, nurbs_surface, **kwargs): self.setup_name_convention_node_base(nurbs_surface) nurbs_surface = RMRigTools.validate_pymel_nodes(nurbs_surface) self.surface = nurbs_surface.getShapes()[0] u_value = kwargs.pop('u_value', .5) v_value = kwargs.pop('v_value', .5) self.build() self._node.startDirection.set(1) self._node.parameterU.set(u_value) self._node.parameterV.set(v_value) self.connect_input_surface(self.surface) follicle_transform = self._node.getParent() self.connect_output_transform(follicle_transform) # self._node.outTranslate >> self.transform.translate # self._node.outRotate >> self.transform.rotate return self._node
def changeNameConv(correct_object): correct_object = RMRigTools.validate_pymel_nodes(correct_object) for each in correct_object: name = original_name_conv.get_from_name(each, 'name') side = original_name_conv.get_from_name(each, 'side') side = get_key(side, original_name_conv.translator['side']) system = original_name_conv.get_from_name(each, 'system') objectType = original_name_conv.get_from_name(each, 'objectType') print each print 'name=%s' % name name_conv.rename_name_in_format(each, name=name, side=side, objectType=objectType, useName=False) for each_children in each.getChildren(): if pm.objectType(each_children) == 'transform': changeNameConv([each_children])
def GetAfectedObjectsList(self, ControlObject, VisibilitySwitch='visibility'): ControlObject = RMRigTools.validate_pymel_nodes(ControlObject) ''' ''' inputConnections = pm.listConnections( "%s.%s" % (ControlObject, VisibilitySwitch), p=True) Afected = [] if inputConnections: for eachConnection in inputConnections: Values = eachConnection.split(".") if Values[1] == "visibility" or Values[ 1] == "lodVisibility" or Values[ 1] == "overrideVisibility": Afected.append(Values[0]) self.AfectedObjectList = Afected return self.AfectedObjectList
def RMImportMoveControl(Obj, scale=1, NameConv=None, name='', Type="move"): Obj = RMRigTools.validate_pymel_nodes(Obj) MoversTypeDic = { "move": { "filename": "ControlMover.mb", "object": "MoverControl" }, "v": { "filename": "ControlV.mb", "object": "VControl" }, "head": { "filename": "ControlHead.mb", "object": "HeadControl" }, "circleDeform": { "filename": "ControlCircularDeform.mb", "object": "CircularDeform" } } if not NameConv: NameConv = nameConvention.NameConvention() path = os.path.dirname(RMRigTools.__file__) RMPYPATH = os.path.split(path) FinalPath = os.path.join(RMPYPATH[0], "RMPY\AutoRig\RigShapes", MoversTypeDic[Type]["filename"]) if os.path.isfile(FinalPath): print 'ready to import' pm.importFile(FinalPath, i=True, type="mayaBinary", ignoreVersion=True, mergeNamespacesOnClash=False, rpr="ControlMover", pr=False) print 'imported !!' else: print "archivo no encontrado %s , %s, %s " % (path, RMPYPATH, FinalPath) return None Ctrl = pm.ls(MoversTypeDic[Type]["object"])[0] if pm.objExists(Ctrl): if name != '': Ctrl = pm.rename(Ctrl, name) pm.setAttr(Ctrl + ".scale", scale, scale, scale) pm.makeIdentity(Ctrl, apply=True, t=1, r=1, s=1) if name != '' and NameConv.is_name_in_format(Obj): NameConv.rename_based_on_base_name(Obj, Ctrl) else: NameConv.rename_based_on_base_name(Obj, Ctrl, name=Ctrl) NameConv.rename_set_from_name(Ctrl, "control", "objectType") RMRigTools.RMAlign(Obj, Ctrl, 3) ParentGroup = RMRigTools.RMCreateGroupOnObj(Ctrl) return ParentGroup, Ctrl else: print "Error importing Shape File" return None