def doCheckGeoInstance(arg=None): '''Button: Check Geo Instance No. ''' sys.stdout.write("Matching GEO name to GRP... \n") cmds.undoInfo(openChunk=True) nodes = getSelectionList() if nodes: ddCheckGeoInstanceNumber.do(nodes) cmds.undoInfo(closeChunk=True)
def do(nodes=None): ''' Import selected nodes from reference. @param nodes: One or more GEO or GRP nodes. ''' if not nodes: nodes = cmds.ls(selection=True, long=True) if not isinstance(nodes, list): nodes = [nodes] cmds.namespace(setNamespace=":") # Seems to be still causing issues, but appears to work fine for not without # # Try to turn off Viewport 2.0 to prevent fatal errors. # try: # # making to use currently focused panel and switch pythonically # current_view = cmds.getPanel(withFocus=True) # print 'attempting to update current view panel:: %s' % current_view # cmds.modelEditor(current_view, edit=True, # rendererName="base_OpenGL_Renderer") # print 'switched renderer to base opengl..' # #mel.eval('setRendererInModelPanel base_OpenGL_Renderer modelPanel4;') # except: # pass # Create a temporary top group. topGrp = "tempRefGrp" if cmds.objExists(topGrp): cmds.delete(topGrp) topGrp = cmds.createNode("transform", name="tempRefGrp") newTopNodes = list() for node in nodes: if not cmds.objExists(node): continue if not cmds.referenceQuery(node, isNodeReferenced=True): sys.stdout.write("--> %s is not referenced. Skipping...\n" % node.rpartition("|")[2]) continue currentNode = node referenceFile = cmds.referenceQuery(node, filename=True) tempNamespace = "" # Gather the reference node data. try: tempNamespace = "tempNamespace" cmds.file(referenceFile, edit=True, namespace=tempNamespace) currentNode = "%s:%s" % (tempNamespace, node.rpartition(":")[2]) except: pass # Parent the namespace objects under the temporary group. currentParent = cmds.listRelatives(currentNode, path=True, parent=True) cmds.parent(currentNode, topGrp) # Import from reference and merge namespace with root. cmds.file(referenceFile, importReference=True, mergeNamespaceWithRoot=True) if not tempNamespace == "": if cmds.namespace(exists="%s" % tempNamespace): cmds.namespace(removeNamespace=tempNamespace, mergeNamespaceWithRoot=True) # Find the imported nodes under the temporary group and reparent to original location. topNode = cmds.listRelatives(topGrp, children=True, path=True) newTopNode = topNode[0] if currentParent: newTopNode = cmds.parent(newTopNode, currentParent)[0] else: newTopNode = cmds.parent(newTopNode, world=True)[0] # Fix the GEO instance numbers. done = ddCheckGeoInstanceNumber.do(newTopNode) # Reassign the shaders. done = ddRemoveDuplicateShaders.do(newTopNode) newTopNodes.append(newTopNode) # Delete the temporary group. if cmds.objExists(topGrp): cmds.delete(topGrp) return newTopNodes