def create_circle_control(name, init_pos=None, radius=10, color=None, axis='z'): """ Creates a circle control :param name: str :param init_pos: list(float, float, float) or None :param radius: float :param color: list(float, float, float) or rt.Point3 :param axis: str """ pos = init_pos or [0, 0, 0] if rt.classOf(pos) != rt.Point3: pos = rt.Point3(*pos) if color and rt.classOf(color) != rt.color: color = rt.color(*color) if not color: color = rt.yellow rt.setCommandPanelTaskMode(rt.Name('modify')) ctrl_name = rt.uniquename(name) base_circle = rt.circle(name=ctrl_name, radius=radius, steps=6, pos=pos) if str(axis).lower() == 'x': xform_mod = rt.xform() rt.addModifier(base_circle, xform_mod) rt.setProperty(xform_mod.gizmo, 'rotation', rt.eulerAngles(0, 90, 0)) elif str(axis).lower() == 'y': xform_mod = rt.xform() rt.addModifier(base_circle, xform_mod) rt.setProperty(xform_mod.gizmo, 'rotation', rt.eulerAngles(90, 0, 0)) base_circle.wirecolor = color rt.convertTo(base_circle, rt.SplineShape) return base_circle
def find_unique_name(obj_names=None, include_last_number=True, do_rename=False): def _find_unique_name(obj_name): node = node_utils.get_pymxs_node(obj_name) if not node: return obj_name unique = FindUniqueName(obj_name) unique.get_last_number(include_last_number) unique_name = unique.get() unique_name = rt.uniquename(unique_name) if do_rename: node.name = unique_name return node.name else: return unique_name if not obj_names: obj_names = [obj.name for obj in list(rt.selection)] if isinstance(obj_names, (tuple, list)): unique_names = list() for obj in enumerate(obj_names): unique_names.append(_find_unique_name(obj)) return python.remove_dupes(unique_names) else: return rt.uniquename(obj_names)
def _find_unique_name(obj_name): node = node_utils.get_pymxs_node(obj_name) if not node: return obj_name unique = FindUniqueName(obj_name) unique.get_last_number(include_last_number) unique_name = unique.get() unique_name = rt.uniquename(unique_name) if do_rename: node.name = unique_name return node.name else: return unique_name
def create_box_control(name, init_pos=None, length=10, width=10, height=10, color=None): """ Creates a box control :param name: str :param init_pos: :param length: :param width: :param height: :param color: :return: """ pos = init_pos or [0, 0, 0] if rt.classOf(pos) != rt.Point3: pos = rt.Point3(*pos) if color and rt.classOf(color) != rt.color: color = rt.color(*color) if not color: color = rt.yellow rt.setCommandPanelTaskMode(rt.Name('modify')) base_box = rt.Box( lengthsegs=1, widthsegs=1, heightsegs=1, length=length, width=width, height=height, mapcoords=True, pos=pos, isSelected=True) rt.select(base_box) rt.convertTo(base_box, rt.PolyMeshObject) rt.subobjectLevel = 2 edge_bitarray = rt.BitArray() edge_indices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] edge_bitarray.count = len(edge_indices) for i, index in enumerate(edge_indices): edge_bitarray[i] = index base_box.EditablePoly.SetSelection(rt.Name('Edge'), edge_bitarray) ctrl_name = rt.uniquename(name) base_box.EditablePoly.createShape(ctrl_name, False, base_box) rt.subobjectLevel = 0 rt.delete(base_box) box_ctrl = rt.getNodeByName(ctrl_name) rt.convertTo(box_ctrl, rt.SplineShape) box_ctrl.wirecolor = color rt.CenterPivot(box_ctrl) transform.reset_xform_and_collapse(box_ctrl, freeze=True) return box_ctrl
def create_rectangle_control(name, init_pos=None, length=10.0, width=10.0, corner_radius=0.0, color=None, axis='z'): """ Creates a rectangle control :param name: str :param init_pos: :param length: :param width: :param corner_radius: :param color: :param axis: :return: """ pos = init_pos or [0, 0, 0] if rt.classOf(pos) != rt.Point3: pos = rt.Point3(*pos) if color and rt.classOf(color) != rt.color: color = rt.color(*color) if not color: color = rt.yellow rt.setCommandPanelTaskMode(rt.Name('modify')) ctrl_name = rt.uniquename(name) base_rectangle = rt.rectangle(name=ctrl_name, length=length, width=width, cornerRadius=corner_radius, pos=pos) base_rectangle.wirecolor = color if str(axis).lower() == 'x': xform_mod = rt.xform() rt.addModifier(base_rectangle, xform_mod) rt.setProperty(xform_mod.gizmo, 'rotation', rt.eulerAngles(0, 90, 0)) elif str(axis).lower() == 'y': xform_mod = rt.xform() rt.addModifier(base_rectangle, xform_mod) rt.setProperty(xform_mod.gizmo, 'rotation', rt.eulerAngles(90, 0, 0)) rt.convertTo(base_rectangle, rt.SplineShape) return base_rectangle
def renameselected(text): '''Rename all elements in selection''' if text != "": for i in rt.selection: i.name = rt.uniquename(text)
def create_end_bone(parent_bone, name='newBone', snap_to=None, match_to=None, parent=None, **kwargs): """ Creates and end bone :param parent_bone: :param snap_to: :param match_to: :param name: :param parent: :return: """ length = kwargs.pop('length', 10) width = kwargs.pop('width', 10) height = kwargs.pop('height', 5) color = kwargs.pop('color', [7, 7, 11]) main_axis = kwargs.pop('main_axis', 'z') extrude = kwargs.pop('extrude', True) freeze = kwargs.pop('freeze', False) parent_bone = node_utils.get_pymxs_node(parent_bone) snap_to = node_utils.get_pymxs_node(snap_to) match_to = node_utils.get_pymxs_node(match_to) parent = node_utils.get_pymxs_node(parent) if not parent_bone or not node_utils.node_exists(parent_bone.name): logger.error('Bone could not be created!') return False if color and rt.classOf(color) != rt.color: color = rt.color(*color) if not color: color = rt.color(7, 7, 11) bone_name = rt.uniquename(name) bone_box = rt.box(name=bone_name, lengthsegs=1, widthsegs=1, heightsegs=1, length=length, width=width, height=height, mapcoords=True, isSelected=True) bone_box.wirecolor = color bone_box.boneEnable = True bone_box.boneAxis = rt.Name(main_axis.lower()) xform_utils.match_transforms(bone_box, parent_bone) rt.SetCommandPanelTaskMode(rt.Name('modify')) rt.convertTo(bone_box, rt.PolyMeshObject) rt.subobjectLevel = 1 vertex_bitarray = rt.BitArray() vertex_indices = [1, 2, 3, 4] vertex_bitarray.count = len(vertex_indices) for i, index in enumerate(vertex_indices): vertex_bitarray[i] = index bone_box.EditablePoly.SetSelection(rt.Name('Vertex'), vertex_bitarray) bone_box.EditablePoly.collapse(rt.Name('Vertex')) bone_box.EditablePoly.SetSelection(rt.Name('Vertex'), rt.BitArray()) if extrude: rt.subobjectLevel = 4 vertex_bitarray = rt.BitArray() vertex_indices = [1] vertex_bitarray.count = len(vertex_indices) for i, index in enumerate(vertex_indices): vertex_bitarray[i] = index bone_box.EditablePoly.SetSelection(rt.Name('Face'), vertex_bitarray) bone_box.EditablePoly.extrudeFaces(height) bone_box.EditablePoly.SetSelection(rt.Name('Vertex'), rt.BitArray()) rt.subobjectLevel = 0 if snap_to: xform_utils.match_position(bone_box, snap_to) if match_to: xform_utils.match_transforms(bone_box, match_to) if parent: bone_box.parent = parent if freeze: xform_utils.freeze_transform(bone_box) return bone_box
def create_bone(root_node, name='new_bone', target_node=None, parent=None, **kwargs): length = kwargs.pop('length', 10) width = kwargs.pop('width', 10) height = kwargs.pop('height', 10) color = kwargs.pop('color', [7, 7, 11]) main_axis = kwargs.pop('main_axis', 'z') flip_main_axis = kwargs.pop('flip_main_axis', False) main_rot_axis = kwargs.pop('main_rot_axis', 'y') flip_main_rot_axis = kwargs.pop('flip_main_rot_axis', False) freeze = kwargs.pop('freeze', False) root_node = node_utils.get_pymxs_node(root_node) target_node = node_utils.get_pymxs_node(target_node) parent = node_utils.get_pymxs_node(parent) if not root_node or not node_utils.node_exists(root_node.name): logger.error('Bone could not be created!') return False if color and rt.classOf(color) != rt.color: color = rt.color(*color) if not color: color = rt.color(7, 7, 11) bone_name = rt.uniquename(name) bone_box = rt.box(name=bone_name, lengthsegs=1, widthsegs=1, heightsegs=1, length=length, width=width, height=height, mapcoords=True, isSelected=True) bone_box.wirecolor = color bone_box.boneEnable = True bone_box.boneAxis = rt.Name(main_axis.lower()) main_axis_index = 0 main_rot_index = 0 if main_axis.lower() == 'y': main_axis_index = 1 elif main_axis.lower() == 'z': main_axis_index = 2 if main_rot_axis.lower() == 'y': main_rot_index = 1 elif main_rot_axis.lower() == 'z': main_rot_index = 2 xform_utils.match_transforms(bone_box, root_node) if target_node and node_utils.node_exists(target_node.name): temp_helper = rt.Point(pos=rt.Point3(0, 0, 0)) xform_utils.match_position(temp_helper, bone_box) look_at_controller = rt.LookAt_Constraint() rt.setPropertyController(temp_helper.controller, 'Rotation', look_at_controller) look_at_controller.appendTarget(target_node, 1) look_at_controller.target_axis = main_axis_index look_at_controller.upnode_axis = 1 look_at_controller.StoUP_axis = main_rot_index look_at_controller.target_axisFlip = flip_main_axis look_at_controller.StoUP_axisFlip = flip_main_rot_axis xform_utils.match_transforms(bone_box, temp_helper) rt.delete(temp_helper) bone_box.height = rt.distance(root_node, target_node) if parent: bone_box.parent = parent if freeze: xform_utils.freeze_transform(bone_box) return bone_box