def getSelectedCollections(): # add the collections from the selected layers to the set selection = getSelection(True, False, False) renderLayers = (utils.nameToUserNode(renderLayerName) for renderLayerName in selection) collectionSet = set(modelCmds.getCollections(renderLayers)) # add the selected collections to the set selection = getSelection(False, True, False) collections = (utils.nameToUserNode(collectionName) for collectionName in selection) collectionSet.update(collections) return collectionSet
def convert(): import maya.app.renderSetup.model.override as override import maya.app.renderSetup.model.collection as collection for selname in cmds.ls(type=BasicSelector.kTypeName): collections = cmds.listConnections(selname, destination=True, source=False, type='collection') for colname in collections: # there should be only one col = utils.nameToUserNode(colname) if col.kTypeName != 'collection': # specialized types of collection should not have had include hierarchy on. # (lightsCollection, "lightsChildCollection", "renderSettingsCollection", ...) # creating subcollection to represent that hierarchy will fail # since they do not accept standard collections as children col.getSelector().setIncludeHierarchy(False) dic = col.encode() convert2016R2(dic) for child in col.getOverrides(): override.delete(child) # need to call parent setSelectorType function because it is redefined to raise # by children classes collection.Collection.setSelectorType( col, dic.values()[0]['selector'].keys()[0]) col._decodeProperties(dic.values()[0], DECODE_AND_MERGE, None) yield colname
def doIt(self, args): # Use an MArgDatabase to parse the command invocation. # try: argDb = OpenMaya.MArgDatabase(self.syntax(), args) except RuntimeError as ex: raise RunTimeError(kParsingError % str(ex)) # add and deselect are non-query mode flags add = argDb.isFlagSet(RenderSetupSelectCmd.kAddFlag) deselect = argDb.isFlagSet(RenderSetupSelectCmd.kDeselectFlag) if argDb.isQuery and (add or deselect): raise RuntimeError(kAddAndDeselectEditOnly) # renderLayers, collections, and overrides are query mode flags renderLayers = argDb.isFlagSet(RenderSetupSelectCmd.kRenderLayersFlag) collections = argDb.isFlagSet(RenderSetupSelectCmd.kCollectionsFlag) overrides = argDb.isFlagSet(RenderSetupSelectCmd.kOverridesFlag) if not argDb.isQuery and (renderLayers or collections or overrides): raise RuntimeError(kNotEditableFlags) if argDb.isQuery: results = getSelection(renderLayers, collections, overrides) self.setResult(results) else: selectionModel = getSelectionModel() if selectionModel is None: if argDb.numberOfFlagsUsed: raise RuntimeError(kSelectionEditFailed) # Can't have both add and deselect at the same time if add and deselect: raise RuntimeError(kAddAndDeselectNoTogether) # Find the items that we are selecting and add them to our item selection from PySide2.QtCore import QItemSelection, QItemSelectionModel import maya.app.renderSetup.views.proxy.renderSetup as renderSetupProxy itemsToSelect = argDb.getObjectStrings() selection = QItemSelection() models = itertools.ifilter(None, (utils.nameToUserNode(item) for item in itemsToSelect)) proxies = [renderSetupProxy.getProxy(model) for model in models] for proxy in proxies: selection.select(proxy.index(), proxy.index()) if not deselect: treeview = getRenderSetupView() for proxy in proxies: parent = proxy.parent() while parent: treeview.setExpanded(parent.index(), True) parent = parent.parent() # Use the appropriate selection method selectMode = QItemSelectionModel.Select if add else QItemSelectionModel.Deselect if deselect else QItemSelectionModel.ClearAndSelect selectionModel.select(selection, selectMode)
def dropOnto(nodeName, mimeData, row): # Note: If nodeName is None, then we are dropping onto the RenderSetup model. if nodeName != renderSetupModel.instance().name(): n = utils.nameToUserNode(nodeName) nProxy = n.getOpaqueData(renderSetupProxy.PROXY_OPAQUE_DATA)() rsProxy = renderSetupUI.renderSetupWindow.centralWidget.renderSetupView.model() rsProxy.dropMimeDataFailure = False # Indicates if the drop was accepted rsProxy.dropMimeData( mimeData, QtCore.Qt.DropAction.MoveAction, row, 0, QtCore.QModelIndex() if nodeName==renderSetupModel.instance().name() else nProxy.index()) return not rsProxy.dropMimeDataFailure
def _createApplyOverride(self, target, nextOvr=None): name = self.name() + "_" + target.partialName( includeNodeName=True, includeNonMandatoryIndices=True, includeInstancedIndices=True) # Namespace qualifies from the original node name cannot be used # to rename the new apply node. Replace the namespace qualifiers with '_'. name = name.replace(':', '_').replace('.', '_') if utils.nameToUserNode(name): return ao = ApplyConnectionOverride.create(name) utils.connect(self._getEnabledPlug(), ao.getEnabledPlug()) ao.finalize(self._getAttrValuePlug()) ao.insert(target, nextOvr) return ao
def _getSources(nodeName): '''Returns objects to add override in. i.e. selected collections in the visible render layer if any, or the layer itself otherwise.''' visibleLayer = renderSetupModel.instance().getVisibleRenderLayer() dic = { name: utils.nameToUserNode(name) for name in viewCmds.getSelection(collections=True) } collections = [ node for name, node in dic.iteritems() if node.getRenderLayer() == visibleLayer and node.parent().name() not in dic ] finalCollections = set([]) for col in collections: finalCollections.add( visibleLayer.getCorrespondingCollection(nodeName, col.name())) if len(finalCollections) > 0: return list(finalCollections) else: return [visibleLayer]
def create(name): """ Create a render layer. Returns the MPxNode object corresponding to the created render collection node. This function is undoable.""" # Using existing command for undo / redo purposes, even if it requires # a name-based lookup to return the user node, since render layer # creation is not performance-critical. If the name flag is specified, # it cannot be an empty string. renderLayerName = cmds.createNode(RenderLayer.kTypeName, name=name, skipSelect=True) if name \ else cmds.createNode(RenderLayer.kTypeName, skipSelect=True) renderLayer = utils.nameToUserNode(renderLayerName) # Second create the associated legacy render layer legacyRenderLayerName = legacyLayer.create(renderLayerName) # Third connect the render layer node to the legacy render layer node cmds.connectAttr(legacyRenderLayerName + '.msg', renderLayerName + '.lrl') return renderLayer
def renderSetupFind(objectNodeNames, renderLayerNames, includeLayers): nodes = ( commonUtils.nameToNode(name) for name in objectNodeNames ) longNames = [ commonUtils.nodeToLongName(node) for node in nodes if node is not None ] renderLayers = (utils.nameToUserNode(renderLayerName) for renderLayerName in renderLayerNames) models = itertools.chain.from_iterable(rl.findIn(longNames, includeSelf=includeLayers) for rl in renderLayers) return [model.name() for model in models]