class LayoutCloner: def __init__(self): self.project = Project() def clone(self): shot_list = self.project.list_shots() self.item_gui = sfl.SelectFromList(l=shot_list, parent=hou.ui.mainQtWindow(), title="Select a shot to clone from") self.item_gui.submitted.connect(self.results) def results(self, value): self.shot_name = value[0] self.shot = self.project.get_shot(self.shot_name) if not self.shot: self.shot = self.project.create_shot(self.shot_name) if not self.shot: qd.error("Something's wrong here. Talk to Stephanie") self.layout_element = self.shot.get_element(Asset.LAYOUT) path = os.path.join(self.layout_element._filepath, self.shot_name + ".usda") if not os.path.exists(path): # no layout is associated with this shot yet layouts = self.project.list_existing_layouts() self.item_gui = sfl.SelectFromList( l=layouts, parent=hou.ui.mainQtWindow(), title="Select a layout for this shot") self.item_gui.submitted.connect(self.layout_results) return self.load(path) def layout_results(self, value): layout_name = value[0] # copy ref file into the shot layout_body = self.project.get_layout(layout_name) element = layout_body.get_element(Asset.LAYOUT) src = os.path.join(element._filepath, layout_name + "_ref.usda") dst = os.path.join(self.layout_element._filepath, self.shot_name + ".usda") shutil.copy(src, dst) pio.set_permissions(dst) self.load(dst) def load(self, file): ref = hou.node("/stage").createNode("loadlayer") ref.setName("layout_ref", 1) ref.parm("filepath").set(file) ref.setDisplayFlag(True) rop = hou.node("/stage").createNode("usd_rop") rop.setInput(0, ref) rop.parm("enableoutputprocessor_simplerelativepaths").set(0) rop.parm("lopoutput").set(file) rop.setName("save_layout", 1)
class LightPublisher: def __init__(self): self.project = Project() def publish(self): shot_list = self.project.list_shots() self.item_gui = sfl.SelectFromList(l=shot_list, parent=hou.ui.mainQtWindow(), title="Select a shot to publish to") self.item_gui.submitted.connect(self.results) def results(self, value): self.shot_name = value[0] shot = self.project.get_shot(self.shot_name) if not shot: shot = self.project.create_shot(self.shot_name) if not shot: qd.error("Get Stephanie, because something broke bad.") self.element = shot.get_element(Asset.LIGHTS) if len(hou.selectedNodes()) != 1: qd.error("Only select the last node in the network of lights.") return last = hou.selectedNodes()[0] rop = hou.node("/stage").createNode("usd_rop") rop.setInput(0, last) self.savePath = os.path.join(self.element._filepath, "temp.usda") rop.parm("lopoutput").set(self.savePath) rop.parm("enableoutputprocessor_simplerelativepaths").set(0) rop.parm("execute").pressButton() rop.destroy() publishes = self.element.list_publishes() publishes_string_list = "" for publish in publishes: label = publish[0] + " " + publish[1] + " " + publish[2] + "\n" publishes_string_list += label self.comment = qd.HoudiniInput(parent=hou.qt.mainWindow(), title="Comment for publish?", info=publishes_string_list) self.comment.submitted.connect(self.comment_results) def comment_results(self, value): comment = str(value) username = Environment().get_user().get_username() self.element.update_app_ext(".usda") self.element.publish(username, self.savePath, comment, self.shot_name)
class ShotPublisher: def __init__(self): self.project = Project() def publish(self): shot_list = self.project.list_shots() self.item_gui = sfl.SelectFromList(l=shot_list, parent=hou.ui.mainQtWindow(), title="Select a shot to publish") self.item_gui.submitted.connect(self.results) def results(self, value): self.shot_name = value[0] shot = self.project.get_shot(self.shot_name) if not shot: shot = self.project.create_shot(self.shot_name) if not shot: qd.error("Get Stephanie, because something broke bad.") self.element = shot.get_element(Asset.HIP) self.path = os.path.join(self.element._filepath, "temp.hipnc") hou.hipFile.setName(self.shot_name) hou.hipFile.save(file_name=self.path, save_to_recent_files=False) publishes = self.element.list_publishes() publishes_string_list = "" for publish in publishes: label = publish[0] + " " + publish[1] + " " + publish[2] + "\n" publishes_string_list += label self.input = qd.HoudiniInput(parent=hou.qt.mainWindow(), title="Comment ", info=publishes_string_list) self.input.submitted.connect(self.comment_results) def comment_results(self, value): comment = str(value) username = Environment().get_user().get_username() name = self.shot_name self.element.update_app_ext(".hipnc") self.element.publish(username, self.path, comment, name) self.element.update_assigned_user("")
class UpdateShots: def __init__(self): self.project = Project() def update_shots(self): shot_list = ShotgunReader().getShotList() #print(shot_list) list_file = open( os.path.join(self.project.get_shots_dir(), ".shot_list"), "w") list_file.truncate(0) for shot in shot_list: #print("shot " + shot) list_file.write(shot + "\n") self.create_shot(shot) list_file.close() qd.message("Shots updated successfully.") def create_shot(self, shot): stage = hou.node("/stage") #print(shot) #check if there's already a shot hip file, and if so, don't do anything body = self.project.get_shot(shot) if not body: body = self.project.create_shot(shot) element = body.get_element(Asset.HIP) file_name = os.path.join(element._filepath, shot + "_main.hipnc") if os.path.exists(file_name) or element.get_last_version() >= 0: #don't save over work already done return #copy over the template file and publish it src = os.path.join(self.project.get_project_dir(), "template.hipnc") dst = os.path.join(element._filepath, "temp.hipnc") shutil.copyfile(src, dst) comment = "blank shot file" username = "******" element.update_app_ext(".hipnc") element.publish(username, dst, comment, shot)
def shot_comment(self, value): # hou.hipFile.setName('newName_v01') #this will change the name of the file: can be versioned. So that's nice. comment = value if comment is None: comment = "Publish by " + \ str(user.get_username()) + \ '. Ask them to leave a comment next time lol' # FIXME: make variable more specific to shot? chosen_shot = self.chosen_shot project = Project() print('Selected shot name: ' + chosen_shot) # print(project.get_body(chosen_shot)) shot_body = project.create_shot(chosen_shot) if shot_body is None: shot_body = project.get_shot(chosen_shot) if shot_body is None: print("Something is horribly wrong. Talk to Stephanie") return filepath = shot_body.get_filepath() shot_element = shot_body.get_element("hip") shot_element.update_app_ext(".hip") prev_vers = shot_element.get_last_version() # path = os.path.abspath(inspect.getfile(project.get_body(chosen_shot))) #trying to get path here. filepath = os.path.join(shot_element._filepath, chosen_shot + ".hip") # print('file path is ', filepath) hou.hipFile.setName(filepath) src = hou.hipFile.save() # # hou.hipFile.saveAndIncrementFileName() #this actually works! Dunno if I want to use it though. # # #Publish user = Environment().get_user() pipeline_io.set_permissions(src) # try that asset name is body name. dst = self.publish_element(shot_element, user, filepath, comment)
class Exporter: def __init__(self): pass def go(self, alembic=False, usd=False, obj=False, mb=False, camera=False): self.alembic = alembic self.usd = usd self.obj = obj self.mb = mb self.camera = camera self.project = Project() self.chosen_asset = None if self.camera and self.alembic: #previs publish case shot_list = self.project.list_shots() self.item_gui = sfl.SelectFromList( l=shot_list, parent=maya_main_window(), title="What shot is this camera in?") self.item_gui.submitted.connect(self.shot_results) else: asset_list = self.project.list_assets() self.item_gui = sfl.SelectFromList( l=asset_list, parent=maya_main_window(), title="Select an asset to export to") self.item_gui.submitted.connect(self.asset_results) def export(self): publish_info = [] if self.obj: #modeling publish case publish_info.append(ObjExporter().exportSelected( self.chosen_asset)) #self.publish(publish_info) if self.usd: #modeling publish case publish_info.append(USDExporter().exportSelected( self.chosen_asset)) self.publish(publish_info) if self.alembic: #animation publish case shot_list = self.project.list_shots() self.item_gui = sfl.SelectFromList( l=shot_list, parent=maya_main_window(), title="What shot is this animation in?") self.item_gui.submitted.connect(self.shot_results) if self.mb: #rigging publish case publish_info.append(MbExporter().export(self.chosen_asset)) self.publish(publish_info) def asset_results(self, value): self.chosen_asset = value[0] #check if asset already exists #if not, create it self.project.create_asset(name=self.chosen_asset) self.export() def shot_results(self, value): self.chosen_shot = value[0] print(self.chosen_shot) shot = self.project.create_shot(self.chosen_shot) #if the shot didn't exist already, set the frame range if shot is not None: pass else: print("we're here") shot = self.project.get_shot(self.chosen_shot) if shot is None: print("uh oh stinky") return #pre-vis publish publish_info = [] if self.camera: camera_num = int(shot.get_camera_number()) if camera_num == 1: #only one camera in the shot self.chosen_asset = "camera1" publish_info.append(AlembicExporter().exportSelected( asset_name=self.chosen_asset, shot_name=self.chosen_shot, camera=self.camera)) self.publish(publish_info) else: #pick which camera to publish cam_list = [] for number in range(1, camera_num + 1): camera_name = "camera" + str(number) cam_list.append(camera_name) self.item_gui = sfl.SelectFromList( l=cam_list, parent=maya_main_window(), title="Which camera are you publishing?") self.item_gui.submitted.connect(self.camera_results) #animation publish else: publish_info.append(AlembicExporter().exportSelected( asset_name=self.chosen_asset, shot_name=self.chosen_shot, camera=self.camera)) self.publish(publish_info) def camera_results(self, value): publish_info = [] self.chosen_asset = value[0] publish_info.append(AlembicExporter().exportSelected( asset_name=self.chosen_asset, shot_name=self.chosen_shot, camera=self.camera)) self.publish(publish_info) def publish(self, publishes): publish_info = publishes[0] element = publish_info[0] path = publish_info[1] self.publishes = element.list_publishes() publishes_string_list = "" for publish in self.publishes: label = publish[0] + " " + publish[1] + " " + publish[2] + "\n" publishes_string_list += label # get comment and update element file with publish info comment = qd.input(title="Comment for publish", label=publishes_string_list) if comment is None or comment == "": comment = "No comment." username = Environment().get_user().get_username() for pub_info in publishes: element = pub_info[0] path = pub_info[1] element.publish(username, path, comment, self.chosen_asset)
class UsdReader: def __init__(self): pm.loadPlugin("mayaUsdPlugin") self.project = Project() def go(self, quick=True): self.quick = quick shot_list = self.project.list_shots() self.item_gui = sfl.SelectFromList( l=shot_list, parent=maya_main_window(), title="Which shot is this layout in?") self.item_gui.submitted.connect(self.shot_results) def shot_results(self, value): self.shot_name = value[0] self.shot = self.project.get_shot(self.shot_name) if not self.shot: self.shot = self.project.create_shot(self.shot_name) if not self.shot: qd.error("This is real :'( (but the shot you picked isn't. talk to stephanie)") self.element = self.shot.get_element(Asset.LAYOUT) if self.element is None: qd.warning("Nothing was cloned.") return if self.quick: path = os.path.join(self.element._filepath, self.shot_name+".usda") if os.path.exists(path): self.open_scene_file(path) return else: self.choose_layout() return self.publishes = self.element.list_publishes() if not self.publishes: self.choose_layout() return # make the list a list of strings, not tuples self.sanitized_publish_list = [] for publish in self.publishes: label = publish[0] + " " + publish[1] + " " + publish[2] self.sanitized_publish_list.append(label) self.item_gui =sfl.SelectFromList( l=self.sanitized_publish_list, parent=maya_main_window(), title="Select publish to clone") self.item_gui.submitted.connect(self.publish_selection_results) def publish_selection_results(self, value): selected_publish = None for item in self.sanitized_publish_list: if value[0] == item: selected_publish = item selected_scene_file = None for publish in self.publishes: label = publish[0] + " " + publish[1] + " " + publish[2] if label == selected_publish: selected_scene_file = publish[3] # selected_scene_file is the one that contains the scene file for the selected commit self.open_scene_file(selected_scene_file) def open_scene_file(self, selected_scene_file): if selected_scene_file is not None: if not os.path.exists(selected_scene_file): qd.error( "That publish is missing. It may have been deleted to clear up space.") return False else: # do the thing command = "mayaUsd_createStageFromFilePath(\"" + selected_scene_file + "\")" pm.Mel.eval(command) return True else: return False def choose_layout(self): layout_list = self.project.list_layouts() self.item_gui =sfl.SelectFromList( l=layout_list, parent=maya_main_window(), title="Select layout to clone") self.item_gui.submitted.connect(self.layout_results) def layout_results(self, value): layout_name = value[0] layout = self.project.get_layout(layout_name) layout_element = layout.get_element(Asset.LAYOUT) src = os.path.join(layout_element._filepath, layout_name + "_ref.usda") dst = os.path.join(self.element._filepath, self.shot_name + ".usda") shutil.copy(src, dst) pio.set_permissions(dst) # basically set up a fake publish since we're not doing version control on this file self.element._datadict[self.element.LATEST_VERSION] = 0 timestamp = pio.timestamp() username = Environment().get_user().get_username() self.element._datadict[self.element.PUBLISHES].append((username, timestamp, "initial publish", dst)) self.element._update_pipeline_file() self.open_scene_file(dst)