def doRemovePivotOffsets(arg=None): '''Button: Remove Pivot Offsets. ''' sys.stdout.write("Removing pivot offsets... \n") cmds.undoInfo(openChunk=True) currentAssetCategory = getAssetCategory() nodes = getSelectionList() if nodes: ddRemovePivotOffsets.do(nodes=nodes, returnToPos=True, currentAssetCategory=currentAssetCategory) cmds.undoInfo(closeChunk=True)
def do(nodes=None, replaceWithReference=True, export=True, currentAssetCategory="environments", notify=True): # double check if necessary environment variables exist before continuing print "should we notify? %s" % str(notify) vpe.VP_Environment().test() currentAssetLibrary = ddConstants.ASSET_DIRECTORIES[currentAssetCategory] # Check if assetLibrary folder exists if not os.path.isdir(currentAssetLibrary): confirm = cmds.confirmDialog( title="Warning", messageAlign="center", message="AssetLibrary path does not exist: %s" % currentAssetLibrary, button=["Ok"], defaultButton="Ok", cancelButton="Ok", dismissString="Ok", ) return # Get selection if not nodes: nodes = cmds.ls(selection=True, objectsOnly=True, long=True) if len(nodes) == 0: confirm = cmds.confirmDialog( title="Warning", messageAlign="center", message="Select at least one group object.", button=["Ok"], defaultButton="Ok", cancelButton="Ok", dismissString="Ok", ) return if not isinstance(nodes, list): nodes = [nodes] invalidNodes = list() invalid_textured_nodes = list() override = False resultTopNodes = list() # Clean and export for sel in nodes: sys.stdout.write("\n--> %s\n" % sel.rpartition("|")[2]) currentNode = sel nodeParent = cmds.listRelatives(sel, parent=True, path=True) if cmds.referenceQuery(currentNode, isNodeReferenced=True): currentNode = ddImportFromReference.do(currentNode)[0] invalidNode = ddCheckNames.do(nodes=currentNode, currentAssetCategory=currentAssetCategory) valid_textures = ddCheckTextures.do(node=currentNode)[0] if not invalidNode and valid_textures: publish_details = {} # no need to grab notes from user if not sending email if notify: publish_details["Notes"] = publish_notes.PublishNotes().notes validNode = ddRemoveNamespaces.doRemoveNamespaces(node=currentNode) topGrpLayer = ddRemoveFromLayers.do(nodes=validNode)[0] pos = cmds.xform(validNode, query=True, worldSpace=True, absolute=True, rotatePivot=True) rot = cmds.getAttr("%s.r" % validNode)[0] scl = cmds.getAttr("%s.s" % validNode)[0] ddUnlockGeoTransforms.do(nodes=validNode) returnedNodes = ddRemovePivotOffsets.do( nodes=validNode, returnToPos=False, currentAssetCategory=currentAssetCategory ) if returnedNodes: validNode = returnedNodes[0] ddAddGeoMetadata.do(nodes=validNode) ddLockGeoTransforms.do(nodes=validNode) advancedAssets = cmds.ls(type="container", long=True) if advancedAssets: sys.stdout.write("Deleting advanced assets...\n") cmds.delete(advancedAssets) unknownNodes = cmds.ls(type="unknown", long=True) if unknownNodes: try: sys.stdout.write("Deleting unknown nodes...\n") cmds.delete(unknownNodes) except: cmds.warning("Unable to delete unknown nodes.") if not export: continue if currentAssetLibrary == ddConstants.CHAR_ASSETLIBRARY: exportedNode, exportedPath = exportCharacterAsset(sel) # attempt to collect publish details for character piece charType = {"hero": "hero", "bg": "background", "sec": "secondary"} scene_patt = re.compile("char_(%s)_[A-Z]{3}_[a-z]+" % "|".join(charType.values())) char_patt = re.compile("[A-Z]{3}_[a-zA-Z]+") if scene_patt.search(exportedNode): publish_details["Character"] = char_patt.search(exportedNode).group() publish_details["Template_Category"] = "vad_chesspiece" else: exportedNode, exportedPath, override = exportAsset( node=validNode, override=False, currentAssetCategory=currentAssetCategory ) env_patt = re.compile("[a-z]{3,4}(_[a-z]{3})*(_[a-z]+)*_([a-zA-Z]+[0-9]*[A-Z]v[A-Z])_*") if env_patt.search(exportedNode): publish_details["Enviro_Asset"] = env_patt.search(exportedNode).groups()[-1] publish_details["Template_Category"] = "vad_enviro_asset" if exportedPath: ddScreenBoardGrab.do_boards( nodes=exportedNode.rpartition("|")[2], current_asset_category=currentAssetCategory ) # ddScreenGrab.do(nodes=exportedNode.rpartition("|")[2], currentAssetCategory=currentAssetCategory) else: if currentNode != sel: cmds.delete(currentNode) sys.stdout.write("Export of %s was Canceled..." % exportedNode) return # update publish details with version, file # and file path information version_patt = re.compile("_v([0-9]{2,4})_*") if version_patt.search(exportedNode): publish_details["Version"] = version_patt.search(exportedNode).groups()[0] publish_details["FILEPATH"] = "%s.ma" % exportedPath publish_details["FILE"] = os.path.basename(publish_details["FILEPATH"]) if replaceWithReference and exportedPath: currentSceneFile = cmds.file(query=True, sceneName=True).replace("/", os.sep) exportedFile = "%s.ma" % exportedPath if currentSceneFile == exportedFile: confirm = cmds.confirmDialog( title="Warning", messageAlign="center", message="Scene file is already open. Cannot reference a file into itself.", button=["Ok"], defaultButton="Ok", cancelButton="Ok", dismissString="Ok", ) if confirm == "Ok": continue # Delete original GRP confirm = cmds.confirmDialog( title="Warning", messageAlign="center", message="Delete original GRP?", button=["Ok", "Keep Original"], defaultButton="Ok", cancelButton="Keep Original", dismissString="Keep Original", ) if confirm == "Ok": cmds.delete(exportedNode) else: # Move group back. cmds.xform(exportedNode, worldSpace=True, absolute=True, translation=pos) cmds.setAttr("%s.r" % exportedNode, rot[0], rot[1], rot[2]) cmds.setAttr("%s.s" % exportedNode, scl[0], scl[1], scl[2]) # Reference a copy of the exported file namespace = os.path.split(exportedPath)[1].partition(".")[0] newReferencedNodes = cmds.file( "%s.ma" % exportedPath, reference=True, namespace=namespace, returnNewNodes=True ) referencedTopGrp = "" refTransforms = [x for x in newReferencedNodes if cmds.nodeType(x) == "transform"] for refTransform in refTransforms: refParent = cmds.listRelatives(refTransform, parent=True, fullPath=True) if not refParent or not refParent[0] in refTransforms: referencedTopGrp = refTransform cmds.xform(referencedTopGrp, worldSpace=True, absolute=True, translation=pos) cmds.setAttr("%s.r" % referencedTopGrp, rot[0], rot[1], rot[2]) cmds.setAttr("%s.s" % referencedTopGrp, scl[0], scl[1], scl[2]) if topGrpLayer: cmds.editDisplayLayerMembers(topGrpLayer, referencedTopGrp, noRecurse=True) if nodeParent: referencedTopGrp = cmds.parent(referencedTopGrp, nodeParent[0])[0] resultTopNodes.append(referencedTopGrp.rpartition("|")[2]) else: # Move group back. cmds.xform(exportedNode, worldSpace=True, absolute=True, translation=pos) cmds.setAttr("%s.r" % exportedNode, rot[0], rot[1], rot[2]) cmds.setAttr("%s.s" % exportedNode, scl[0], scl[1], scl[2]) resultTopNodes.append(exportedNode.rpartition("|")[2]) if topGrpLayer: cmds.editDisplayLayerMembers(topGrpLayer, exportedNode, noRecurse=True) if nodeParent: exportedNode = cmds.parent(exportedNode, nodeParent[0])[0] # prep and send publish email publish_details["SHOW"] = os.getenv("SHOW") publish_details["ARTIST"] = os.getenv("ARTIST") if os.getenv("ARTIST") else "Some Artist" # send publish email if user specified notification if notify: sys.stdout.write("Sending email. \n") set_email = pub_mail.PublishEmail(publish_details["Template_Category"]) set_email.publish_details = publish_details set_email.build_email() set_email.send_mail() else: sys.stdout.write("Holding off on sending publish email by request. \n") else: if invalidNode: sys.stdout.write("Invalid name %s. Skipping...\n" % invalidNode[0].rpartition("|")[2]) invalidNodes.append(sel) elif not valid_textures: sys.stdout.write("Invalid texture found on node %s. Skipping...\n" % sel.rpartition("|")[2]) invalid_textured_nodes.append(sel) if invalidNodes: nodeString = "" for invalidNode in invalidNodes: nodeString += "%s, " % invalidNode.rpartition("|")[2] confirm = cmds.confirmDialog( title="Warning", messageAlign="center", message="Please legalize the %s names of the following groups and re-export:\n\n%s" % (currentAssetCategory[:-1], nodeString[:-2]), button=["Ok"], defaultButton="Ok", cancelButton="Ok", dismissString="Ok", ) cmds.select(invalidNodes, replace=True) # report back any nodes found with invalid textures if invalid_textured_nodes: node_string = ", ".join(invalid_textured_nodes) confirm = cmds.confirmDialog( title="Warning", messageAlign="center", message="Please fix the textures of the following groups and re-export:\n\n%s" % (node_string), button=["Ok"], defaultButton="Ok", cancelButton="Ok", dismissString="Ok", ) if invalidNodes: # add to selection of other invalid nodes cmds.select(invalid_textured_nodes, add=True) else: # select only these invalid nodes cmds.select(invalid_textured_nodes, replace=True) if resultTopNodes: try: cmds.select(resultTopNodes, r=1) except: pass