def check_unsaved_changes(): unsaved_changes = mc.file(q=True, modified=True) if unsaved_changes: response = qd.yes_or_no("Would you like to publish the current asset before you proceed?", title="Unsaved changes detected", details="(Press No if you just created a new scene or opened Maya.)") if response is True: # instead of saving, publish. scene = mc.file(q=True, sceneName=True) dir_path = scene.split("assets/") try: asset_path = dir_path[1].split("/") except: # scene path is stored in the user directory instead of assets. We can't get the asset name, so they must publish manually. qd.error("Publish failed. Please publish manually before cloning the new asset.") return asset_name = asset_path[0] try: department = asset_path[1].split("/")[0] print("department " + department) except: department = None if department: print("department found") else: qd.warning("Skipping changes to " + str(asset_name)) return publisher = Publisher(quick_publish=True, export=False) publisher.non_gui_publish(asset_name, department)
def set_submission_location(self): submission_location = Project().get_submission_location() option = qd.yes_or_no("Current location is:\n" + str(submission_location) + "\nSet new submission location?") if option: new_location = qd.input("New location: ") else: return if new_location and not new_location == "": Project().set_submission_location(new_location)
def get_body_and_export(self, chosen_asset, export_all=False): project = Project() self.body = project.get_body(chosen_asset) try: print("asset type: " + self.body.get_type()) except: qd.error( "Error: Asset does not have a valid type. Was it created properly?" ) type = self.body.get_type() if type == AssetType.PROP or type == AssetType.ACTOR: creases = qd.yes_or_no("Does this asset use creases?") if creases: self.crease = True if type == AssetType.SHOT: export_all = False self.frame_range = qd.input("How many frames are in this shot?") if self.frame_range is None or self.frame_range == u'': self.frame_range = 1 self.frame_range = str(self.frame_range) if not self.frame_range.isdigit(): qd.error("Invalid frame range input. Setting to 1.") else: self.frame_range = 1 self.body.set_frame_range(self.frame_range) asset_type = self.body.get_type() department_list = get_departments_by_type(asset_type, export=True) if export_all: # tag top level nodes nodes = get_top_level_nodes() print("top level: ", nodes) for node in nodes: tag_node_with_flag(node, "DCC_Alembic_Export_Flag") self.department_results(department_list)
def create_from_current(self): script_name = qd.input("Enter a name for this template: ") if not script_name or script_name == u'': return templates_dir = Environment().get_templates_dir() temp_filepath = os.path.join(templates_dir, script_name + ".nk") basename = os.path.basename(temp_filepath) templates_in_dir = os.listdir(templates_dir) print("templates: ", templates_in_dir) if basename in templates_in_dir: overwrite = qd.yes_or_no( str(script_name) + " already exists. Overwrite it?") if overwrite: nuke.scriptSave(temp_filepath) qd.info("Template created successfully!") else: nuke.scriptSave(temp_filepath) qd.info("Template created successfully!") print("filepath: ", temp_filepath)
def scene_prep(quick_publish, body=None, department=None): if quick_publish: print("skipping check for unsaved changes") else: check_unsaved_changes() # save_scene_file() freeze_and_clear = True if department == Department.RIG: freeze_and_clear = False if body.is_shot() or body.get_type() == AssetType.SET: freeze_and_clear = False if not body.get_type() == AssetType.SHOT: # delete cameras cam_list = pm.ls(ca=True) print("deleting cameras:", cam_list) for cam in cam_list: if str(cam) == "perspShape" or str(cam) == "topShape" or str( cam) == "frontShape" or str(cam) == "sideShape": continue cam_response = qd.yes_or_no( "Camera " + str(cam) + " found in scene. Cameras will cause problems if left in the asset. \n\nProceed to delete this camera?" ) if cam_response: parents = cam.listRelatives(p=True) while parents: if "camera" in str(parents[0]): cam = parents[0] else: break parents = cam.listRelatives(p=True) print("parents: ", parents) pm.delete(cam) if freeze_and_clear: print("clearing construction history") try: clear_construction_history() except: qd.warning( "Clear construction history failed. There may be something unusual in the history that's causing this." ) try: freeze_transformations() except: qd.warning( "Freeze transform failed. There may be 1+ keyframed values in object. Remove all keyframed values and expressions from object." ) try: delete_image_planes() except: qd.warning("Delete image planes failed.") try: group_top_level() except: qd.warning("Group top level failed.")
def go(self, node=None): self.hda = node environment = Environment() project = Project() hda_dir = environment.get_hda_dir() if self.hda is None: self.hda = get_selected_node() if self.hda is None: return node_path = self.hda.path() name = node_path.split('/')[-1] tool_name = name.lower() if tool_name is None: return if not self.hda.canCreateDigitalAsset(): if self.hda.type().definition is not None: # we are dealing with an premade self.hda result = qd.yes_or_no( 'The selected node is already a digial asset. Would you like to copy the definition into the pipeline' ) if not result: return else: copyHDA = True else: qd.error( 'You can\'t make a digital asset from the selected node') return else: copyHDA = False destination = os.path.join(hda_dir, tool_name + ".hda") operatorName = tool_name operatorLabel = str(project.get_name()) + '_' + str(tool_name) saveToLibrary = destination num_inputs = len(self.hda.inputs()) if copyHDA: parent = self.hda.parent() subnet = parent.createNode('subnet') hda_node = subnet.createDigitalAsset(name=operatorName, description=operatorLabel, hda_file_name=saveToLibrary, min_num_inputs=num_inputs) hou.copyNodesTo(self.hda.children(), hda_node) hda_nodeDef = hda_node.type().definition() hdaDef = self.hda.type().definition() #Copy over sections sects = hdaDef.sections() for sectName in sects: hda_nodeDef.addSection(sectName, sects[sectName].contents()) #Copy over NodeGroups nodeGroups = self.hda.nodeGroups() for ng in nodeGroups: newNg = hda_node.addNodeGroup(ng.name()) for node in ng.nodes(): nodePath = hda_node.path() + '/' + str(node.name()) newNode = hou.node(nodePath) if newNode is None: print('Ya that node was null that is a problem') continue newNg.addNode(newNode) # Copy over paramters oldParms = hdaDef.parmTemplateGroup() hda_nodeDef.setParmTemplateGroup(oldParms) else: try: hda_node = self.hda.createDigitalAsset( name=operatorName, description=operatorLabel, hda_file_name=saveToLibrary, min_num_inputs=num_inputs) except hou.OperationFailed, e: qd.error('There was a problem creating a digital asset', details=str(e)) return
def create_hda(self, value): tool_name = create_window.result if tool_name is None: return if not self.hda.canCreateDigitalAsset(): if self.hda.type().definition is not None: # we are dealing with an premade self.hda result = qd.yes_or_no( 'The selected node is already a digial asset. Would you like to copy the definition into the pipeline' ) if not result: return copyHDA = True else: qd.error( 'You can\'t make a digital asset from the selected node') return else: copyHDA = False project = Project() environment = Environment() username = project.get_current_username() tool = project.get_tool(tool_name) hda_element = tool.get_element(Department.HDA) checkout_file = hda_element.checkout(username) operatorName = hda_element.get_short_name() operatorLabel = (project.get_name() + ' ' + tool.get_name()).title() saveToLibrary = checkout_file num_inputs = len(self.hda.inputs()) if copyHDA: parent = self.hda.parent() subnet = parent.createNode('subnet') hda_node = subnet.createDigitalAsset(name=operatorName, description=operatorLabel, hda_file_name=saveToLibrary, min_num_inputs=num_inputs) hou.copyNodesTo(self.hda.children(), hda_node) hda_nodeDef = hda_node.type().definition() hdaDef = self.hda.type().definition() #Copy over sections sects = hdaDef.sections() for sectName in sects: print 'Copying over section: ' + str(sectName) hda_nodeDef.addSection(sectName, sects[sectName].contents()) #Copy over NodeGroups nodeGroups = self.hda.nodeGroups() for ng in nodeGroups: newNg = hda_node.addNodeGroup(ng.name()) print 'New group: ' + str(newNg) for node in ng.nodes(): nodePath = hda_node.path() + '/' + str(node.name()) print 'The Node path is:' + str(nodePath) newNode = hou.node(nodePath) if newNode is None: print('Ya that node was null that is a problem') continue print 'The new Node is: ' + str(newNode) newNg.addNode(newNode) # Copy over paramters oldParms = hdaDef.parmTemplateGroup() hda_nodeDef.setParmTemplateGroup(oldParms) else: try: hda_node = self.hda.createDigitalAsset( name=operatorName, description=operatorLabel, hda_file_name=saveToLibrary, min_num_inputs=num_inputs) except hou.OperationFailed, e: print qd.error('There was a problem creating a digital asset', details=str(e)) return