def find_results_roots(): for i in range(len(result_list)): if mxs.isValidNode(result_list[i].parent) == False or mxs.isValidNode(result_list[i].parent) and \ result_list[i].parent not in result_list: # print(f"#{i} - Search root", result_list[i].name) results_roots.append(result_list[i])
def convertList_Name2Node(self, nameList): nodeList = [] for nm in nameList: nd = rt.getNodeByName(nm) if rt.isValidNode(nd): nodeList.append(nd) return nodeList
def find_node_in_chain(): for i in range(len(out_of_groups)): if mxs.isValidNode( out_of_groups[i].parent ) == True or out_of_groups[i].children.count != 0: nodes_in_chain.append(out_of_groups[i]) result_list.append(out_of_groups[i])
def find_independent_nodes(): for i in range(len(out_of_groups)): if mxs.isValidNode( out_of_groups[i].parent ) == False and out_of_groups[i].children.count == 0: independent_nodes.append(nodes[i]) result_list.append(nodes[i])
def find_head_roots(): for i in range(len(group_heads)): if mxs.isValidNode(group_heads[i].parent ) == False or mxs.isGroupMember( group_heads[i]) == False: head_root.append(group_heads[i]) result_list.append(group_heads[i])
def node_exists(node): """ Returns whether given object exists or not :return: bool """ node = node_utils.get_pymxs_node(node) return rt.isValidNode(node)
def old_recreate(self): with pymxs.undo(True): if len(self.result) > 0: self.newNodes = [] self.dict = {} temp = mxs.Array() lastNode = None index = 0 rootNode = mxs.point() rootNode.size = 2 rootNode.showlinks = True rootNode.Box = True rootNode.cross = False rootNode.axistripod = False rootNode.centermarker = False mxs.join(temp, rootNode) def create_constraints(node, nNode): # Position sub = mxs.getSubAnim(nNode, 3) secsub = mxs.getSubAnim(sub, 1) secsub.controller = mxs.Position_List() posCtrl = mxs.Position_Constraint() thirdsub = mxs.getSubAnim(secsub, 2) thirdsub.controller = posCtrl posConstraintInterface = posCtrl.constraints posConstraintInterface.appendTarget(node, 100) # Rotation sub = mxs.getSubAnim(nNode, 3) secsub = mxs.getSubAnim(sub, 2) secsub.controller = mxs.rotation_list() posCtrl = mxs.Orientation_Constraint() thirdsub = mxs.getSubAnim(secsub, 2) thirdsub.controller = posCtrl posConstraintInterface = posCtrl.constraints posConstraintInterface.appendTarget(node, 100) for i in self.result: # Create new nodes and add them to list and dict nNode = mxs.point() nNode.showlinks = True nNode.size = 2 nNode.transform = i.transform nNode.name = i.name nNode.wireColor = i.wireColor self.dict[i] = nNode self.newNodes.append(i) # Create parent connections if mxs.isValidNode(i.parent): nNode.parent = self.dict[i.parent] else: nNode.parent = rootNode # Create Constraints create_constraints(i, nNode) # final part mxs.join(temp, nNode) lastNode = nNode index += 1 mxs.select(temp) mxs.redrawViews()
def recreate(self): defaultSize = 2 bones = mxs.Array() if len(self.result) > 0: self.newNodes = [] self.dict = {} temp = mxs.Array() lastNode = None index = 0 rootNode = mxs.BoneSys.createBone(mxs.point3(0, 0, 0), mxs.point3(0, 1, 0), mxs.point3(0, 1, 0)) rootNode.transform = mxs.Matrix3(1) rootNode.size = 2 rootNode.name = "rootBone" mxs.join(temp, rootNode) def new_create_constraints(node, nNode): posList = mxs.position_list() # Create Pos_List const = mxs.Position_Constraint() # Create Pos_Constraint const.appendTarget(nNode, 100) # Add target to Constraint secsub = mxs.setPropertyController(node.controller, "Position", posList) # Add PosList to node mxs.setPropertyController(secsub, 'Available', const) posList = mxs.rotation_list() # Create Pos_List const = mxs.Orientation_Constraint() # Create Pos_Constraint const.appendTarget(nNode, 100) # Add target to Constraint secsub = mxs.setPropertyController(node.controller, "Rotation", posList) # Add PosList to node mxs.setPropertyController(secsub, 'Available', const) def create_constraints(nNode, node): # Position posList = mxs.position_list() # Create Pos_List const = mxs.Position_Constraint() # Create Pos_Constraint const.appendTarget(nNode, 100) # Add target to Constraint secsub = mxs.setPropertyController(node.controller, "Position", posList) # Add PosList to node mxs.setPropertyController(secsub, 'Available', const) # Rotation posList = mxs.rotation_list() # Create Pos_List const = mxs.Orientation_Constraint() # Create Pos_Constraint const.appendTarget(nNode, 100) # Add target to Constraint secsub = mxs.setPropertyController(node.controller, "Rotation", posList) # Add PosList to node mxs.setPropertyController(secsub, 'Available', const) for obj in self.result: endPos = mxs.point3(0, 0, 0) if obj.children.count > 0: endPos = obj.children[0].transform.pos else: endPos = (mxs.transmatrix(mxs.point3(defaultSize, 0, 0)) * obj.transform).pos zPos = (mxs.transmatrix(mxs.point3(0, 0, 1)) * obj.transform).pos d = mxs.BoneSys.createBone(obj.transform.pos, endPos, zPos) d.transform = obj.transform d.name = obj.name d.wirecolor = obj.wirecolor mxs.join(bones, d) self.dict[obj] = d self.newNodes.append(obj) # Create parent connections if mxs.isValidNode(obj.parent): d.parent = self.dict[obj.parent] else: d.parent = rootNode create_constraints(obj, d) mxs.select(bones) mxs.selectmore(rootNode) mxs.redrawViews()