Python pymel.core.select() Examples

The following are 30 code examples of pymel.core.select(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pymel.core , or try the search function .
Example #1
Source File: publish.py    From anima with MIT License 6 votes vote down vote up
def check_sequence_name(progress_controller=None):
    """Sequence name is properly set

    checks if the sequence name attribute is properly set
    """
    if progress_controller is None:
        progress_controller = ProgressControllerBase()

    # do not consider referenced shot nodes
    shots = pm.ls(type='shot')
    progress_controller.maximum = len(shots)
    shot = None
    for s in shots:
        if s.referenceFile() is None:
            shot = s
            break
        progress_controller.increment()

    progress_controller.complete()
    sequencer = shot.outputs(type='sequencer')[0]
    sequence_name = sequencer.sequence_name.get()
    if sequence_name == '' or sequence_name is None:
        pm.select(sequencer)
        raise PublishError('Please enter a sequence name!!!') 
Example #2
Source File: sqSpaceSwitcher.py    From dpAutoRigSystem with GNU General Public License v2.0 6 votes vote down vote up
def _event_edtFrame_changed(self, iRow):
        """
        Manage a frame change in the frame info table
        """
        pCellQLine = self.ui.tblFrameInfo.cellWidget(iRow, self.ID_COL_FRAME)

        if pCellQLine.text() != "":
            pCellFrame = self.ui.tblFrameInfo.item(iRow, self.ID_COL_FRAME)
            iOldFrame = pCellFrame.data(QtCore.Qt.UserRole)
            # pCellParent = self.ui.tblFrameInfo.item(iRow, self.ID_COL_PARENT)
            # iParentIdx = pCellParent.data(QtCore.Qt.UserRole)
            iNewFrame = int(pCellQLine.text())
            # Prevent the user to move a key on a frame already constrained
            if not (iNewFrame in self.aConstrainedFrame):
                self.pSelSpSys.moveKey(iNewFrame, iOldFrame)
                self._update_tblFrameInfo(self.pSelSpSys)
            else:
                pCellQLine.setText(str(iOldFrame))

            pymel.select(self.nSelDriven) 
Example #3
Source File: render.py    From anima with MIT License 6 votes vote down vote up
def assign_random_material_color(cls):
        """assigns a lambert with a random color to the selected object
        """
        selected = pm.selected()

        # create the lambert material
        lambert = pm.shadingNode('lambert', asShader=1)

        # create the shading engine
        shading_engine = pm.nt.ShadingEngine()
        lambert.outColor >> shading_engine.surfaceShader

        # randomize the lambert color
        import random
        h = random.random()  # 0-1
        s = random.random() * 0.5 + 0.25  # 0.25-0.75
        v = random.random() * 0.5 + 0.5  # 0.5 - 1

        from anima.utils import hsv_to_rgb
        r, g, b = hsv_to_rgb(h, s, v)
        lambert.color.set(r, g, b)

        pm.sets(shading_engine, fe=selected)
        pm.select(selected) 
Example #4
Source File: applyop.py    From mgear_core with MIT License 6 votes vote down vote up
def gear_curvecns_op(crv, inputs=[]):
    """
    create mGear curvecns node.

    Arguments:
        crv (nurbsCurve): Nurbs curve.
        inputs (List of dagNodes): Input object to drive the curve. Should be
            same number as crv points.
            Also the order should be the same as the points

    Returns:
        pyNode: The curvecns node.
    """
    pm.select(crv)
    node = pm.deformer(type="mgear_curveCns")[0]

    for i, item in enumerate(inputs):
        pm.connectAttr(item + ".worldMatrix", node + ".inputs[%s]" % i)

    return node 
Example #5
Source File: pickWalk.py    From mgear_core with MIT License 6 votes vote down vote up
def controllerWalkUp(node, add=False):
    """Walk up in the hierachy using the controller tag

    Arguments:
        node (dagNode or list of dagNode): Node with controller tag
        add (bool, optional): If true add to selection

    """
    oParent = []
    if not isinstance(node, list):
        node = [node]
    for n in node:
        tag = getWalkTag(n)
        if tag:
            cnx = tag.parent.connections()
            if cnx:
                oParent.append(cnx[0])
        else:
            pm.displayWarning("The selected object: %s without Controller tag "
                              "will be skipped" % n.name())
    if oParent:
        pm.select(_getControllerWalkNodes(oParent), add=add)
    else:
        pm.displayWarning("No parent to walk Up.") 
Example #6
Source File: pickWalk.py    From mgear_core with MIT License 6 votes vote down vote up
def transformWalkUp(node, add=False):
    """Walks to the parent transform dagNode on the hierarcy

    Arguments:
        node (dagNode or list of dagNode): dagNode to walk
        add (bool, optional): if True, will add to the selection

    """
    oParent = []
    if not isinstance(node, list):
        node = [node]
    for n in node:
        p = n.listRelatives(p=True)
        if p:
            oParent.append(p)

    if oParent:
        pm.select(oParent, add=add)
    else:
        pm.displayWarning("No parent to walk Up.") 
Example #7
Source File: pickWalk.py    From mgear_core with MIT License 6 votes vote down vote up
def transformWalkDown(node, add=False, multi=False):
    """Walks to the child transform dagNode on the hierarcy

    Arguments:
        node (dagNode or list of dagNode): dagNode to walk
        add (bool, optional): if True, will add to the selection
        multi (bool, optional): if True will select all the childrens
    """
    oChild = []
    if not isinstance(node, list):
        node = [node]
    for n in node:
        relatives = n.listRelatives(typ='transform')
        if relatives:
            if multi:
                oChild = oChild + relatives
            else:
                oChild.append(relatives[0])
    if oChild:
        pm.select(oChild, add=add)
    else:
        pm.displayWarning("No child to walk Down.") 
Example #8
Source File: pickWalk.py    From mgear_core with MIT License 6 votes vote down vote up
def transformWalkRight(node, add=False, multi=False):
    """Pick walks to the right the next sibling transform on the hierarchy

    Arguments:
        node (dagNode or list of dagNode): dagNode transform to navegate
            the hierarchy
        add (bool, optional): If true add to selection
        multi (bool, optional): If true, selects all the siblings

    """
    sib = _getTransformWalkSiblings(node, "right", multi)
    pm.select(sib, add=add)


# =====================================================
# Walk mirror 
Example #9
Source File: anim_utils.py    From mgear_core with MIT License 6 votes vote down vote up
def select_all_child_controls(control, *args):  # @unusedVariable
    """ Selects all child controls from the given control

    This function uses Maya's controller nodes and commands to find relevant
    dependencies between controls

    Args:
        control (str): parent animation control (transform node)
        *args: State of the menu item (if existing) send by mgear's dagmenu
    """

    # gets controller node from the given control. Returns if none is found
    tag = cmds.ls(cmds.listConnections(control), type="controller")
    if not tag:
        return

    # query child controls
    children = get_all_tag_children(tag)

    # adds to current selection the children elements
    cmds.select(children, add=True) 
Example #10
Source File: rigging.py    From anima with MIT License 6 votes vote down vote up
def setup_stretchy_spline_ik_curve(cls):
        """
        """
        selection = pm.ls(sl=1)
        curve = selection[0]
        curve_info = pm.createNode("curveInfo")
        mult_div = pm.createNode("multiplyDivide")
        curve_shape = pm.listRelatives(curve, s=1)

        curve_shape[0].worldSpace >> curve_info.ic
        curve_info.arcLength >> mult_div.input1X

        curve_length = curve_info.arcLength.get()
        mult_div.input2X.set(curve_length)
        mult_div.operation.set(2)
        pm.select(mult_div, curve_info, curve_shape[0], add=True) 
Example #11
Source File: rigging.py    From anima with MIT License 6 votes vote down vote up
def finalize_setup(self):
        """does final clean up
        """
        self.check_main_control()

        # group the node together
        parent_group = pm.nt.Transform(name='SquashStretchBendRiggerGroup#')
        pm.parent(self.main_control.getParent(), parent_group)
        pm.parent(self.aim_locator1, parent_group)
        if self.use_squash:
            pm.parent(self.squash_handle, parent_group)

        pm.parent(self.bend_handle, parent_group)

        # set visibilities
        self.aim_locator1.v.set(0)
        if self.use_squash:
            self.squash_handle.v.set(0)
        self.bend_handle.v.set(0)

        # as a gesture select the main control
        pm.select(self.main_control) 
Example #12
Source File: publish.py    From anima with MIT License 5 votes vote down vote up
def check_history(progress_controller=None):
    """No history

    there should be no history on the objects
    """
    if progress_controller is None:
        progress_controller = ProgressControllerBase()
    excluded_types = ['mesh', 'shadingEngine', 'groupId', 'RedshiftProxyMesh']
    nodes_with_history = []

    # delete any objectSets with name textureEditorIsolateSelectSet for Maya 2018
    pm.delete(pm.ls('textureEditorIsolateSelectSet*'))

    # get all shapes
    all_shapes = pm.ls(type='mesh')
    progress_controller.maximum = len(all_shapes)
    for node in all_shapes:
        history_nodes = []
        for h_node in node.listHistory(pdo=1, lv=1):
            if h_node.type() not in excluded_types:
                history_nodes.append(h_node)

        if len(history_nodes) > 0:
            nodes_with_history.append(node)
        progress_controller.increment()

    progress_controller.complete()
    if len(nodes_with_history):
        pm.select(nodes_with_history)
        # there is history
        raise PublishError(
            'There is history on:\n\n'
            '%s'
            '\n\n'
            'there should be no '
            'history in Model versions' %
            '\n'.join(
                map(lambda x: x.name(),
                    nodes_with_history[:MAX_NODE_DISPLAY])
            )
        ) 
Example #13
Source File: publish.py    From anima with MIT License 5 votes vote down vote up
def check_if_root_nodes_have_no_transformation(progress_controller=None):
    """Root nodes have no transformation

    checks if transform nodes directly under world have 0 transformations
    """
    if progress_controller is None:
        progress_controller = ProgressControllerBase()

    root_transform_nodes = auxiliary.get_root_nodes()
    progress_controller.maximum = len(root_transform_nodes)

    non_freezed_root_nodes = []
    for node in root_transform_nodes:
        t = node.t.get()
        r = node.r.get()
        s = node.s.get()
        if t.x != 0 or t.y != 0 or t.z != 0 \
           or r.x != 0 or r.y != 0 or r.z != 0 \
           or s.x != 1 or s.y != 1 or s.z != 1:
            non_freezed_root_nodes.append(node)
        progress_controller.increment()

    progress_controller.complete()
    if len(non_freezed_root_nodes):
        pm.select(non_freezed_root_nodes)
        raise PublishError(
            'Please freeze the following node transformations:\n\n%s' %
            '\n'.join(
                map(lambda x: x.name(),
                    non_freezed_root_nodes[:MAX_NODE_DISPLAY])
            )
        ) 
Example #14
Source File: modeling.py    From anima with MIT License 5 votes vote down vote up
def vertex_aligned_locator(cls):
        """creates vertex aligned locator, select 3 vertices
        """
        selection = pm.ls(os=1, fl=1)

        # get the axises
        p0 = selection[0].getPosition(space='world')
        p1 = selection[1].getPosition(space='world')
        p2 = selection[2].getPosition(space='world')

        v1 = p0 - p1
        v2 = p2 - p1
        #v3 = p0 - p2

        v1.normalize()
        v2.normalize()

        dcm = pm.createNode('decomposeMatrix')

        x = v1
        z = v2
        y = z ^ x
        y.normalize()

        dcm.inputMatrix.set(
            [x[0], x[1], x[2], 0,
             y[0], y[1], y[2], 0,
             z[0], z[1], z[2], 0,
                0,    0,    0, 1], type='matrix')

        loc = pm.spaceLocator()

        loc.t.set(p1)
        loc.r.set(dcm.outputRotate.get())

        pm.delete(dcm) 
Example #15
Source File: selection_manager.py    From anima with MIT License 5 votes vote down vote up
def subtract(self):
        """
        """
        pm.select(self.__storedSelList__, d=1) 
Example #16
Source File: modeling.py    From anima with MIT License 5 votes vote down vote up
def polySmoothFace(cls, method):
        selection = pm.ls(sl=1)
        for item in selection:
            pm.polySmooth(
                item, mth=method, dv=1, c=1, kb=0, ksb=0, khe=0, kt=1, kmb=0,
                suv=1, peh=0, sl=1, dpe=1, ps=0.1, ro=1, ch=1
            )
        pm.select(selection) 
Example #17
Source File: selection_manager.py    From anima with MIT License 5 votes vote down vote up
def add(self):
        """adds the given list of objects to the set

        :param objectList[]: A list of maya objects
        """
        pm.select(self.__storedSelList__, add=1) 
Example #18
Source File: selection_manager.py    From anima with MIT License 5 votes vote down vote up
def replace(self):
        try:
            pm.select(self.__storedSelList__, replace=True)
        except pm.MayaNodeError:
            # nodes should have been deleted
            # remove anything that doesn't exist
            pass 
Example #19
Source File: fix_bound_joint.py    From anima with MIT License 5 votes vote down vote up
def get_check_box_states_and_run(*args, **kwargs):
    """Gets the data from UI and runs the script
    """
    freeze = pm.checkBox("FBJ_checkBox1", q=True, v=True)
    apply_to_children = pm.checkBox("FBJ_checkBox2", q=True, v=True)
    selection_list = pm.ls(sl=1, type="joint")
    do_fix(selection_list, freeze, apply_to_children)
    pm.select(selection_list) 
Example #20
Source File: general.py    From anima with MIT License 5 votes vote down vote up
def select_set_members(cls):
        selection = pm.ls(sl=1)
        if not selection:
            pass
        else:
            pm.select(selection[0].inputs()) 
Example #21
Source File: general.py    From anima with MIT License 5 votes vote down vote up
def dereference_selected_objects(cls):
        selection = pm.ls(sl=True)
        for item in selection:
            if item.overrideEnabled.get(se=True):
                item.overrideEnabled.set(0)
            if item.overrideDisplayType.get(se=True):
                item.overrideDisplayType.set(0)

        pm.select(cl=True) 
Example #22
Source File: general.py    From anima with MIT License 5 votes vote down vote up
def reference_selected_objects(cls):
        selection = pm.ls(sl=True)
        for item in selection:
            if item.overrideEnabled.get(se=True):
                item.overrideEnabled.set(1)
            if item.overrideDisplayType.get(se=True):
                item.overrideDisplayType.set(2)

        pm.select(cl=True) 
Example #23
Source File: render.py    From anima with MIT License 5 votes vote down vote up
def import_gpu_content(self):
        """imports the selected GPU content
        """
        import os

        imported_nodes = []

        for node in pm.ls(sl=1):
            gpu_node = node.getShape()
            gpu_path = gpu_node.getAttr('cacheFileName')

            new_nodes = pm.mel.eval(
                'AbcImport -mode import -reparent "%s" "%s";' % (node.fullPath(), os.path.expandvars(gpu_path))
            )

            # get imported nodes
            new_nodes = node.getChildren()
            new_nodes.remove(gpu_node)

            imported_node = None

            # filter material node
            for n in new_nodes:
                if n.name() != 'materials':
                    imported_node = n
                else:
                    pm.delete(n)

            if imported_node:
                imported_node.t.set(0, 0, 0)
                imported_node.r.set(0, 0, 0)
                imported_node.s.set(1, 1, 1)
                pm.parent(imported_node, world=1)

                imported_nodes.append(imported_node)

        pm.select(imported_nodes) 
Example #24
Source File: publish.py    From anima with MIT License 5 votes vote down vote up
def check_empty_groups(progress_controller=None):
    """No empty groups

    check if there are empty groups
    """
    if progress_controller is None:
        progress_controller = ProgressControllerBase()
    # skip if this is a representation
    v = staging.get('version')
    if v and Representation.repr_separator in v.take_name:
        progress_controller.complete()
        return

    empty_groups = []
    all_transforms = pm.ls(type='transform')
    progress_controller.maximum = len(all_transforms)
    for node in all_transforms:
        # skip any instancer nodes
        if isinstance(node, (
            pm.nt.Instancer, pm.nt.Constraint, pm.nt.IkHandle,
            pm.nt.IkEffector, pm.nt.Joint
        )):
            continue

        if len(node.listRelatives(children=1)) == 0:
            empty_groups.append(node)
        progress_controller.increment()

    progress_controller.complete()
    if len(empty_groups):
        pm.select(empty_groups)
        raise PublishError(
            'There are <b>empty groups</b> in your scene, '
            'please remove them!!!'
        ) 
Example #25
Source File: modeling.py    From SISideBar with MIT License 5 votes vote down vote up
def cehck_zero_poly_object(mesh=None, pop_msg=True):
    #mesh 入力メッシュ
    #pop_msg 探索結果を表示するかどうか
    if mesh == None:
        polyMeshes = common.search_polygon_mesh(cmds.ls(tr=True))
    else:
        polyMeshes = common.search_polygon_mesh(mesh)
    zeroPolyObj = []
    if polyMeshes == None:
        if pop_msg:
            cmds.confirmDialog( title="Check",message='Zero Polygon Object Count :  0')
        return zeroPolyObj
    for p in polyMeshes:
        vtx = cmds.polyListComponentConversion(p, tv=True)
        if vtx == []:
            zeroPolyObj.append(p)
    if not pop_msg:
        return zeroPolyObj
    if zeroPolyObj == []:
        cmds.confirmDialog( title="Check",message='Zero Polygon Object Count :  0')
    else:
        msg = 'Zero Polygon Object Count : '+str(len(zeroPolyObj))
        for p in zeroPolyObj:
            msg+='\n[ '+p+' ]'
        cmds.confirmDialog( title="Check",message=msg )
        cmds.select(zeroPolyObj, r=True)
    return zeroPolyObj
    
#スキニングを保ったままメッシュマージする関数 
Example #26
Source File: publish.py    From anima with MIT License 5 votes vote down vote up
def check_empty_shapes(progress_controller=None):
    """No empty mesh nodes

    checks if there are empty mesh nodes
    """
    if progress_controller is None:
        progress_controller = ProgressControllerBase()

    empty_shape_nodes = []
    all_meshes = pm.ls(type='mesh')
    progress_controller.maximum = len(all_meshes)
    for node in all_meshes:
        if node.numVertices() == 0:
            empty_shape_nodes.append(node)
        progress_controller.increment()

    progress_controller.complete()
    if len(empty_shape_nodes) > 0:
        pm.select(map(
            lambda x: x.getParent(),
            empty_shape_nodes
        ))
        raise PublishError(
            'There are <b>meshes with no geometry</b> in your scene, '
            'please delete them!!!'
        ) 
Example #27
Source File: render.py    From anima with MIT License 5 votes vote down vote up
def setup_outer_eye_render_attributes(cls):
        """sets outer eye render attributes for characters, select outer eye
        objects and run this
        """
        for node in pm.ls(sl=1):
            shape = node.getShape()
            shape.setAttr('castsShadows', 0)
            shape.setAttr('visibleInReflections', 0)
            shape.setAttr('visibleInRefractions', 0)
            shape.setAttr('aiSelfShadows', 0)
            shape.setAttr('aiOpaque', 0)
            shape.setAttr('aiVisibleInDiffuse', 0)
            shape.setAttr('aiVisibleInGlossy', 0) 
Example #28
Source File: render.py    From anima with MIT License 5 votes vote down vote up
def convert_to_linear(cls):
        """adds a gamma_gain node in between the selected nodes outputs to make the
        result linear
        """

        #
        # convert to linear
        #

        selection = pm.ls(sl=1)

        for file_node in selection:
            # get the connections
            outputs = file_node.outputs(plugs=True)

            if not len(outputs):
                continue

            # and insert a mip_gamma_gain
            gamma_node = pm.createNode('mip_gamma_gain')
            gamma_node.setAttr('gamma', 2.2)
            gamma_node.setAttr('reverse', True)

            # connect the file_node to gamma_node
            try:
                file_node.outValue >> gamma_node.input
                file_node.outValueA >> gamma_node.inputA
            except AttributeError:
                file_node.outColor >> gamma_node.input

            # do all the connections from the output of the gamma
            for output in outputs:
                try:
                    gamma_node.outValue >> output
                except RuntimeError:
                    gamma_node.outValueA >> output

        pm.select(selection) 
Example #29
Source File: render.py    From anima with MIT License 5 votes vote down vote up
def replace_shaders_with_last(cls):
        """Assigns the last shader selected to all the objects using the shaders
        on the list
        """
        sel_list = pm.ls(sl=1)
        target_node = sel_list[-1]

        for node in sel_list[:-1]:
            pm.hyperShade(objects=node)
            pm.hyperShade(assign=target_node)

        pm.select(None) 
Example #30
Source File: picker.py    From anima with MIT License 5 votes vote down vote up
def select_anim_curves(self):
        """selects animCurves of parentConstraint and stabilizerParent nodes for
        keyframe editing
        """
        if not self._is_setup:
            return

        pm.select(
            auxiliary.get_anim_curves(self._parent_constraint),
            auxiliary.get_anim_curves(self._stabilizer_parent)
        )