Python maya.cmds.setToolTo() Examples

The following are 13 code examples of maya.cmds.setToolTo(). 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 maya.cmds , or try the search function .
Example #1
Source File: commands.py    From maya-skinning-tools with GNU General Public License v3.0 6 votes vote down vote up
def paint():
    """
    Initialize the smooth weight context, make sure to have a mesh selected 
    with a skin cluster attached to it. Once this command is run the context
    will be set as the active tool.
    """
    if not cmds.artUserPaintCtx(CONTEXT, query=True, exists=True):
        cmds.artUserPaintCtx(CONTEXT)
            
    cmds.artUserPaintCtx(
        CONTEXT, 
        edit=True, 
        ic=CONTEXT_INITIALIZE, 
        svc=CONTEXT_UPDATE, 
        whichTool="userPaint", 
        fullpaths=True,
        outwhilepaint=True,
        brushfeedback=False,
        selectedattroper="additive"
    )

    cmds.setToolTo(CONTEXT) 
Example #2
Source File: AEsporeNodeTemplate.py    From spore with MIT License 5 votes vote down vote up
def selection_changed(self, *args):
        """ make sure to opt out of the current spore tool when the selction
        is changed """

        if cmds.currentCtx().startswith('spore'):
            cmds.setToolTo('selectSuperContext') 
Example #3
Source File: AEsporeNodeTemplate.py    From spore with MIT License 5 votes vote down vote up
def emit(self, *args):
        """ run the actual sample command and check if transforms are frozen """

        # exit spore context since it looses track of points after sampling
        if cmds.currentCtx().startswith('spore'):
            cmds.setToolTo('selectSuperContext')

        in_mesh = node_utils.get_connected_in_mesh(self._node)
        transform = cmds.listRelatives(in_mesh, p=True, f=True)[0]
        if cmds.getAttr(transform + '.translateX') != 0\
        or cmds.getAttr(transform + '.translateY') != 0\
        or cmds.getAttr(transform + '.translateZ') != 0\
        or cmds.getAttr(transform + '.rotateX') != 0\
        or cmds.getAttr(transform + '.rotateY') != 0\
        or cmds.getAttr(transform + '.rotateZ') != 0\
        or cmds.getAttr(transform + '.scaleX') != 1\
        or cmds.getAttr(transform + '.scaleY') != 1\
        or cmds.getAttr(transform + '.scaleZ') != 1:
            msg = 'Feeze transformations to sample the geomety!'
            result = message_utils.IOHandler().confirm_dialog(msg, 'Freeze Transformations')
            if result:
                cmds.makeIdentity(transform, a=True, s=True, r=True, t=True, n=0)
            else:
                return

        cmds.setAttr('{}.emit'.format(self._node), 1)
        cmds.sporeSampleCmd()

    # ------------------------------------------------------------------------ #
    # clear button
    # ------------------------------------------------------------------------ # 
Example #4
Source File: commands.py    From maya-skinning-tools with GNU General Public License v3.0 5 votes vote down vote up
def paint(mesh, influence):
    """
    Initialize the remove influence context. Once this command is run the 
    context will be set as the active tool.
    
    :param str mesh:
    :param str influence:
    """
    # initialize paint tool
    cmds.paintRemoveInfluenceCtxInitialize(
        mesh,
        influence
    )
    
    # initialize context
    if not cmds.artSelectCtx(CONTEXT, query=True, exists=True):
        cmds.artSelectCtx(CONTEXT)
            
    cmds.artSelectCtx( 
        CONTEXT, 
        edit=True, 
        beforeStrokeCmd=CONTEXT_BEFORE,
        afterStrokeCmd=CONTEXT_AFTER,
        selectop="unselect", 
        outwhilepaint=True,
        brushfeedback=False 
    )
     
    # set tool
    cmds.setToolTo(CONTEXT) 
Example #5
Source File: Modify.py    From rush with MIT License 5 votes vote down vote up
def alignTool():
    mel.eval("setToolTo alignToolCtx") 
Example #6
Source File: Modify.py    From rush with MIT License 5 votes vote down vote up
def snapTogetherTool():
    cmds.setToolTo(cmds.snapTogetherCtx()) 
Example #7
Source File: ctx.py    From mGui with MIT License 5 votes vote down vote up
def exit(self, *args, **kwargs):
        utils.executeDeferred(self.reset_select_mask)
        if self.repeat:
            lazy_reset = lambda: cmds.setToolTo(self.context_name)
            utils.executeDeferred(lazy_reset) 
Example #8
Source File: ml_pivot.py    From ml_tools with MIT License 5 votes vote down vote up
def editPivotHandle(self):

        qt_maya_window.installEventFilter(self.keypressFilter)

        #create transform
        self.pivotHandle = mc.group(em=True, name='Adjust_Pivot')
        mc.setAttr(self.pivotHandle+'.rotate', lock=True)
        mc.setAttr(self.pivotHandle+'.rx', keyable=False)
        mc.setAttr(self.pivotHandle+'.ry', keyable=False)
        mc.setAttr(self.pivotHandle+'.rz', keyable=False)
        mc.setAttr(self.pivotHandle+'.scale', lock=True)
        mc.setAttr(self.pivotHandle+'.sx', keyable=False)
        mc.setAttr(self.pivotHandle+'.sy', keyable=False)
        mc.setAttr(self.pivotHandle+'.sz', keyable=False)
        mc.setAttr(self.pivotHandle+'.visibility', lock=True, keyable=False)
        mc.setAttr(self.pivotHandle+'.displayHandle', True)

        self.pivotHandle = mc.parent(self.pivotHandle, self.node)[0]

        mc.addAttr(self.pivotHandle, ln='ml_pivot_handle', at='bool', keyable=False)

        #set initial position
        mc.setAttr(self.pivotHandle+'.translate', *mc.getAttr(self.node+'.rotatePivot')[0])

        #lock it so you don't delete it or something.
        mc.lockNode(self.pivotHandle, lock=True)

        self.scriptJob = mc.scriptJob(event=['SelectionChanged', self.cleanup], runOnce=True)

        mc.setToolTo('Move')

        mc.inViewMessage( amg='After moving the pivot, press <hl>Return</hl> to bake or <hl>Esc</hl> to cancel.', pos='midCenterTop', fade=True, fadeStayTime=4000, dragKill=True) 
Example #9
Source File: ml_softWeights.py    From ml_tools with MIT License 5 votes vote down vote up
def softSelectionClusterWeights(*args):

    sel = mc.ls(sl=True, o=True)

    if not sel:
        raise RuntimeError('Please select some vertices.')

    weights = getSoftSelectionWeights()

    if not weights:
        raise RuntimeError('Please select some vertices.')

    #get manipulator position for pivot
    mc.setToolTo('Move')
    moveMode = mc.manipMoveContext('Move', query=True, mode=True)
    mc.manipMoveContext('Move', edit=True, mode=0)
    position = mc.manipMoveContext('Move', query=True, position=True)
    mc.manipMoveContext('Move', edit=True, mode=moveMode)

    clusterNode, clusterHandle = mc.cluster(sel[0])

    for vert in mc.ls(sel[0]+'.vtx[*]', fl=True, l=True):
        weight = 0.0
        if vert in weights.keys():
            weight = weights[vert]
        mc.percent(clusterNode, vert, v=weight)

    #set cluster pivot
    mc.xform(clusterHandle, a=True, ws=True, piv=(position[0], position[1], position[2]))
    clusterShape = mc.listRelatives(clusterHandle, c=True, s=True)
    mc.setAttr(clusterShape[0] + '.origin', position[0], position[1], position[2]) 
Example #10
Source File: ml_utilities.py    From ml_tools with MIT License 5 votes vote down vote up
def setTool(self):
        mc.setToolTo(self.draggerContext) 
Example #11
Source File: AEsporeNodeTemplate.py    From spore with MIT License 4 votes vote down vote up
def activateContext(self, context_mode, attr, index):
        """ called whenever a brush button is clicked
        enable/disable context controls & activate tool context
        @param context_mode: indicates which button has been clicked
        @param attr: holds the current node and attribute name
        @param index: the index of the child attr in the combobox """

        # check if there are any source objects
        if not cmds.textScrollList('instanceList', q=True, ai=True):
            self.io.set_message('No source objects selected', 0)
            return

        cmds.setAttr(attr, index)
        attr_name = attr.split('.')[-1]
        node_name = attr.split('.')[0]

        # create a tuple of all controls and a dict that associates each control
        # to a specific context style
        brush_crtls = ('brushRadius', 'minDistance', 'fallOff', 'strength',
                       'numBrushSamples', 'alignTo', 'minRotation',
                       'maxRotation', 'uniformScale', 'minScale',
                       'maxScale', 'scaleFactor', 'scaleAmount',
                       'minOffset', 'maxOffset',
                       'usePressureMapping', 'pressureMapping',
                       'minPressure', 'maxPressure')
        p_map = cmds.getAttr('{}.usePressureMapping'.format(self._node))
        dim_ctrl = {                #    rad    minD,  foff,   stren,  numS,   aliTo   minR,   maxR,   uniS    minS,   maxS,   sFac,   sAmou,  minO,   maxO,   pre,    map,    minP,   maxP
                    'place':            (False, True,   False,  True,   False,  True,   True,   True,   True,   True,   True,   False,  False,  True,   True,   True,   p_map,  p_map,  p_map),
                    'spray':            (True,  True,   False,  True,   True,   True,   True,   True,   True,   True,   True,   False,  False,  True,   True,   True,   p_map,  p_map,  p_map),
                    'scale':            (True,  False,  True,   False,  False,  False,  False,  False,  True,   False,  False,  True,   True,   False,  False,  True,   False,  p_map,  p_map),
                    'align':            (True,  False,  True,   True,   False,  True,   False,  False,  False,  False,  False,  False,  True,  False,  False,  True,   False,  p_map,  p_map),
                    'move':             (True,  False,  True,   True,   False,  False,  False,  False,  False,  False,  False,  False,   False,  False,  False,  True,   False,  p_map,  p_map),
                    'id':               (True,  True,   False,  False,  True,   False,  False,  False,  False,  False,  False,  False,  True,  False,  False,  True,   False,  p_map,  p_map),
                    'remove':           (True,  True,   False,  False,  True,   False,  False,  False,  False,  False,  False,  False,  False,  False,  False,  False,  False,  False,  False),
                    }

        #  dim controls
        for i, ctrl in enumerate(brush_crtls):
            self.dimControl(node_name, ctrl, not dim_ctrl[context_mode][i])

        # colorize button
        buttons = ['placeBtn', 'sprayBtn', 'scaleBtn', 'alignBtn', 'moveBtn',
                   'idBtn', 'removeBtn']
        for btn in buttons:
            cmds.button(btn, e=True, bgc=(0.366, 0.366, 0.366))
        button_name = '{}Btn'.format(context_mode)
        cmds.button(button_name, e=True, bgc=(0.148, 0.148, 0.148))

        # set context
        self.context = cmds.sporeContext()
        cmds.select(self._node)
        cmds.setToolTo(self.context)

    # ------------------------------------------------------------------------ #
    # pen pressure checkbox
    # ------------------------------------------------------------------------ # 
Example #12
Source File: extrude_edge.py    From SISideBar with MIT License 4 votes vote down vote up
def extrude_edge_uv(self):
        self.ex_edges = []
        sel = cmds.ls(sl=True)
        self.s_edges = common.conv_comp(sel, mode='edge')
        s_vtx = common.conv_comp(sel, mode='vtx')
        #self.saw_uvs(mode='pre')#事前に押し出し対象のUVを縫い合わせておく
        self.marge_uvs(mode='pre')
        if not self.s_edges:
            return
        ev_dict ,vec_dict, ev_uv_dict = self.make_edge_vtx_dict(self.s_edges)
        #print 'ev_dict :', ev_dict
        #print 'vec_dict :', vec_dict
        #押し出しを実行する
        cmds.polyExtrudeEdge(self.s_edges,
                            keepFacesTogether=True,
                            smoothingAngle=self.soft_angle.value(),
                            translate=[0, 0, 0])
        self.ex_edges = cmds.ls(sl=True)
        n_edges = common.conv_comp(self.ex_edges, mode='edge')
        n_faces = common.conv_comp(self.ex_edges, mode='face')
        self.n_uvs = common.conv_comp(n_faces, mode='uv')
        #print 'pre_move_uvs :', self.n_uvs
        #根本の位置合わせする
        new_vec_dict = {}
        for nuv in self.n_uvs[:]:
            vtx = common.conv_comp(nuv, mode='vtx')[0]
            edge = common.conv_comp(nuv, mode='edge')[0]
            if edge+' '+vtx in ev_dict.keys():
                uv_pos = ev_dict[edge+' '+vtx]
                #print 'get_uv_pos', nuv, uv_pos
                cmds.polyEditUV(nuv, u=uv_pos[0], v=uv_pos[1] ,r=False)
                self.n_uvs.remove(nuv)
                key_uv = ev_uv_dict[edge+' '+vtx]
                new_vec_dict[nuv] = vec_dict[key_uv]
        #print 'post push uvs :', self.n_uvs
        #押し出し先を根本につけて押し出しベクトル辞書をつくる
        self.uv_vec_dict = {}
        self.base_pos_dict = {}
        for nuv in self.n_uvs:
            edges = common.conv_comp(nuv, mode='edge')
            face = common.conv_comp(nuv, mode='face')
            f_uvs = common.conv_comp(face, mode='uv')
            for edge in edges:
                if edge in n_edges:
                    continue
                #print 'get new edge :', edge
                e_uvs = common.conv_comp(edge, mode='uv')
                l_uvs = list(set(f_uvs) & set(e_uvs))
                #print 'new edge uvs :', l_uvs
                for uv in l_uvs:
                    if not uv in new_vec_dict.keys():
                        continue
                    uv_pos = cmds.polyEditUV(uv, query=True)
                    cmds.polyEditUV(nuv, u=uv_pos[0], v=uv_pos[1] ,r=False)
                    self.uv_vec_dict[nuv] = new_vec_dict[uv]
                    self.base_pos_dict[nuv] = uv_pos
                    self.saw_edges.append(edge)#縫い合わせ用リストに入れておく
        self.push_out()
        cmds.setToolTo('moveSuperContext') 
Example #13
Source File: sisidebar_sub.py    From SISideBar with MIT License 4 votes vote down vote up
def restore_context_and_axis():
    global current_mode
    global pre_mode
    current_mode = cmds.selectMode(q=True, o=True)
    current_tool = cmds.currentCtx()
    target_tool_list = ['scaleSuperContext', 'RotateSuperContext', 'moveSuperContext', 'selectSuperContext']
    #選択オブジェクトが切り替わったときだけ切り替え実行
    if cmds.selectMode(q=True, co=True):
        if cmds.ls(sl=True, type='transform'):#複合選択モードの時は逃げる
            print 'multi selection mode return :'
            return
        if cmds.ls(sl=True, set=True):#複合選択モードの時は逃げる
            print 'multi selection mode return :'
            return
        if 'pre_sel_comp' in globals():
            current_selection = cmds.ls(sl=True)
            if pre_sel_comp != current_selection:
                if current_tool in target_tool_list:
                    if not cmds.ls(sl=True):
                        if pre_sel_comp:
                            #print 'newsel'
                            try:
                                cmds.select(pre_sel_comp[0])
                            except:
                                pass
                    if cmds.ls(sl=True):
                        sb.window.select_xyz_from_manip()#事前に選択したハンドル方向をなるべくキープする
                        if current_selection != cmds.ls(sl=True):
                            cmds.select(current_selection, r=True)
        global pre_sel_comp
        pre_sel_comp = cmds.ls(sl=True)#Flatにすると比較が無駄に重くなるので注意
    if cmds.selectMode(q=True, o=True):
        if 'pre_sel_obj' in globals():
            current_selection = cmds.ls(sl=True, o=True)
            if pre_sel_obj != current_selection:
                if current_tool in target_tool_list:
                    #print 'ajust context'
                    if not cmds.ls(sl=True):
                        if cmds.ls(hl=True):#ラティスポイントとかの時は逃げる
                            return
                        if pre_sel_obj:
                            #print 'newsel'
                            try:
                                cmds.select(pre_sel_obj[0])
                            except:
                                pass
                    if cmds.ls(sl=True):
                        sb.window.select_xyz_from_manip()#事前に選択したハンドル方向をなるべくキープする
                        if current_selection != cmds.ls(sl=True):
                            cmds.select(current_selection, r=True)
                    cmds.setToolTo('selectSuperContext')
                    cmds.setToolTo(current_tool)
        global pre_sel_obj
        pre_sel_obj = cmds.ls(sl=True, o=True)
    pre_mode = current_mode