def test_removeFromActiveSelection(self): cmds.select([self.node, cmds.createNode("transform")]) selected = scene.getSelectedNodes() self.assertEquals(len(selected), 2) scene.removeFromActiveSelection(nodes.asMObject(self.node)) selected = scene.getSelectedNodes() self.assertEquals(len(selected), 1)
def resolveArguments(self, arguments): selected = scene.getSelectedNodes() if len(selected) < 2: self.cancel("Please Select at least 2 nodes") driver = om2.MObjectHandle(selected[0]) # driver driven = map(om2.MObjectHandle, selected[1:]) # driven arguments["driver"] = driver arguments["driven"] = driven return arguments
def validateAndBuild(parentMenu, nodeName): if cmds.objExists(nodeName): triggerNode = nodes.asMObject(nodeName) else: # ::note should we just check for selection here and validate? return 0 if not utils.hasTrigger(triggerNode): return 0 triggerNodes = [triggerNode] + [ i for i in scene.getSelectedNodes() if i != triggerNode ] visited = [] validLayout = None dynamic = False # gather the trigger information from the current node and the selection for st in triggerNodes: # get the compound trigger plug triggerPlugs = utils.triggerPlugsFromNode(st) # for each compound found, consolidate and gather info for tp in triggerPlugs: node = tp.node() if node in visited: continue visited.append(node) # pull the command type and command string from the compoundplug commandType = tp.child(0).asInt() commandStr = tp.child(1).asString() if commandType == utils.LAYOUT_TYPE: layout = menu.findLayout(commandStr) if not layout: continue if validLayout: validLayout.merge(layout) else: validLayout = layout elif commandType == utils.DYNAMIC_TYPE: dynamic = True break if not dynamic: if validLayout is None: return 0 validLayout.solve() mainMenu = menu.MarkingMenu(validLayout, "zooTriggerMenu", parentMenu, menu.Registry()) mainMenu.attach(**{"nodes": map(om2.MObjectHandle, triggerNodes)}) else: menu.MarkingMenu.buildDynamicMenu( commandStr, parent=parentMenu, arguments={"nodes": map(om2.MObjectHandle, triggerNodes)}) return 1
def resolveArguments(self, arguments): selected = scene.getSelectedNodes() if len(selected) < 2: self.cancel("Please Select more than 2 nodes") target = om2.MObjectHandle(selected[-1]) # driver driven = [om2.MObjectHandle(i) for i in selected[:-1]] # driven data = [None] * len(driven) for i, nod in enumerate(iter(driven)): data[i] = (nod, nodes.getRotation(nod.object(), om2.MSpace.kTransform)) self.transformations = data arguments["target"] = target arguments["driven"] = driven return arguments
def resolveArguments(self, arguments): nodes = arguments.get("nodes") if not nodes: self.cancel("No nodes to select") self.currentSelection = om2.MSelectionList() for i in scene.getSelectedNodes(): self.currentSelection.add(i) validNodes = [] for i in nodes: mHandle = om2.MObjectHandle(i) if mHandle.isValid() and mHandle.isAlive(): validNodes.append(mHandle) arguments["nodes"] = validNodes return arguments
def resolveArguments(self, arguments): selected = scene.getSelectedNodes() if len(selected) < 2: self.cancel("Please Select 2 or more nodes") targets = [ om2.MObjectHandle(i) for i in selected[1:] if i.hasFn(om2.MFn.kDagNode) ] driver = om2.MObjectHandle(selected[0]) if selected[0].hasFn( om2.MFn.kDagNode) else None if not targets or not driver: self.cancel( "Incorrect node types selected only kDagNode acceptable!") arguments.update({"targets": targets, "driver": driver}) return arguments
def selectedChannelboxAttributes(): gChannelBoxName = mel.eval('$temp=$gChannelBoxName') attrs = cmds.channelBox(gChannelBoxName, query=True, selectedMainAttributes=True) selectedNodes = scene.getSelectedNodes() if not attrs: return list(), selectedNodes apiPlugs = [] for node in selectedNodes: fn = om2.MFnDependencyNode(node) for a in attrs: # is there a a gurnettee that the node has the attribute? if fn.hasAttribute(a): p = fn.findPlug(a, False) apiPlugs.append(p) return apiPlugs, selectedNodes
def test_getSelected(self): cmds.select([self.node, cmds.createNode("transform")]) selected = scene.getSelectedNodes() self.assertEquals(len(selected), 2) self.assertTrue(all(isinstance(i, om2.MObject) for i in selected))