Exemple #1
0
class CameraCreator:
    def __init__(self):
        self.project = Project()

    def go(self):
        #get shot to add camera to
        shotList = self.project.list_existing_shots(
        )  #we shouldn't be adding cameras to shots that haven't been created yet anyway

        self.item_gui = sfl.SelectFromList(
            l=shotList,
            parent=maya_main_window(),
            title="Select shot to add extra camera to")
        self.item_gui.submitted.connect(self.shot_results)

    def shot_results(self, value):
        shot_name = value[0]

        shot = self.project.get_shot(shot_name)
        if shot is None:
            qd.error("There was a problem loading the shot.")
            return

        prevNum = shot.get_camera_number()
        newNum = prevNum + 1
        shot.set_camera_number(newNum)

        message = "There are now " + str(
            newNum) + " cameras in shot " + shot_name

        qd.message(message)
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("")
Exemple #5
0
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)
Exemple #6
0
class CameraCloner:
    def __init__(self):
        self.project = Project()

    def clone(self):
        shot_list = self.project.list_existing_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.shot_results)

    def shot_results(self, value):
        self.shot_name = value[0]
        self.shot = self.project.get_shot(self.shot_name)
        element = self.shot.get_element(Asset.CAMERA)

        asset_list = next(os.walk(element._filepath))[1]
        for name in asset_list:
            if name == "cache":
                asset_list.remove(name)
        asset_list.sort(key=unicode.lower)

        self.item_gui = sfl.SelectFromList(l=asset_list,
                                           parent=hou.ui.mainQtWindow(),
                                           title="Select an camera to clone")
        self.item_gui.submitted.connect(self.camera_results)

    #this could use some more testing once there's more cameras published
    def camera_results(self, value):
        camera_name = value[0]
        element = self.shot.get_element(os.path.join(Asset.CAMERA,
                                                     camera_name))

        if element.get_last_version < 0:
            qd.error("There are no publishes for this camera.")
            return
        path = element.get_last_publish()[3]
        cameraNode = hou.node("/obj").createNode("cenoteCamera")
        cameraNode.setName(self.shot_name + "_camera", 1)
        cameraNode.parm("fileName").set(path)
        cameraNode.parm("scale").set(0.01)
        cameraNode.parm("buildHierarchy").pressButton()
class ShotSaver:
    def __init__(self):
        self.project = Project()
        qd.message(
            "This action will save a copy of this Maya file in the groups folder, but will not publish "
            + "anything to the pipeline.")

    def save(self):
        shot_list = self.project.list_shots()

        self.item_gui = sfl.SelectFromList(l=shot_list,
                                           parent=maya_main_window(),
                                           title="Select a shot to save to")
        self.item_gui.submitted.connect(self.results)

    def results(self, value):
        shot_name = value[0]
        self.item_gui.close()

        shot = self.project.get_shot(shot_name)
        element = None
        try:
            element = shot.get_element(Asset.MAYA)
        except:
            element = shot.create_element(Asset.MAYA, Element.DEFAULT_NAME)

        path = os.path.join(element._filepath, "temp.mb")
        mc.file(rename=path)
        mc.file(save=True, type="mayaBinary")

        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

        comment = qd.input(title="Comment on changes",
                           label=publishes_string_list)
        username = Environment().get_user().get_username()

        element.update_app_ext(".mb")
        element.publish(username, path, comment, shot_name)
    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)
Exemple #9
0
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 ShotOpener:
    def __init__(self):
        self.project = Project()

    def open(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="Select a shot to open")
        self.item_gui.submitted.connect(self.results)

    def results(self, value):
        shot_name = value[0]
        self.name = shot_name

        shot = self.project.get_shot(shot_name)
        element = None
        try:
            element = shot.get_element(Asset.MAYA)
        except:
            element = shot.create_element(Asset.MAYA, Element.DEFAULT_NAME)

        if element.get_last_version() >= 0 and self.quick:
            filepath = element.get_last_publish()[3]
            print(filepath)
            mc.file(filepath, o=True, f=True)
        elif element.get_last_version() >= 0 and not self.quick:
            self.element = element
            self.publishes = element.list_publishes()

            if not self.publishes:
                qd.error("There have been no publishes in this department.")
                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 a version to open")
            self.item_gui.submitted.connect(self.version_results)

        else:
            qd.error("There's no maya file published for this shot.")

    def version_results(self, value):
        selected_publish = None
        for item in self.sanitized_publish_list:
            if value[0] == item:
                selected_publish = item

        selected_scene_file = None
        position = 0
        for publish in self.publishes:
            label = publish[0] + " " + publish[1] + " " + publish[2]
            if label == selected_publish:
                version_path = self.element.get_version_dir(position)
                version_path = os.path.join(version_path, self.name + ".mb")
                selected_scene_file = version_path
                break
            position += 1

        print(selected_scene_file)
        mc.file(selected_scene_file, o=True, f=True)
Exemple #11
0
class AnimCloner:
    def __init__(self):
        self.project = Project()

    def clone(self):
        shot_list = self.project.list_existing_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.shot_results)

    def shot_results(self, value):
        self.shot_name = value[0]
        self.shot = self.project.get_shot(self.shot_name)
        element = self.shot.get_element(Asset.ANIMATION)

        asset_list = next(os.walk(element._filepath))[1]
        for name in asset_list:
            if name == "cache":
                asset_list.remove(name)
        asset_list.sort(key=unicode.lower)

        self.item_gui = sfl.SelectFromList(l=asset_list,
                                           parent=hou.ui.mainQtWindow(),
                                           title="Select an asset to clone")
        self.item_gui.submitted.connect(self.asset_results)

    def asset_results(self, value):
        self.asset_name = value[0]
        element = self.shot.get_element(
            os.path.join(Asset.ANIMATION, self.asset_name))

        if element.get_last_version < 0:
            qd.error("There are no publishes for this asset in this shot.")
            return
        path = element.get_last_publish()[3]
        self.build_network(path)

    def build_network(self, path):
        animNode = hou.node("/obj").createNode("cenoteAnimation")
        animNode.setName(self.asset_name + "_anim", 1)
        animNode.parm("fileName").set(path)
        animNode.parm("scale").set(0.01)
        animNode.parm("buildHierarchy").pressButton()
        #animNode.parm("rendersubd").set(True)

        matPath = self.getMatPath()
        hdaPath = matPath.split(".")[0] + ".hda"
        if os.path.exists(hdaPath):
            hou.hda.installFile(hdaPath)
            for child in hou.node("/mat").children():
                if child.type().name() == re.sub(r'\W+', '', self.asset_name):
                    child.destroy()
            newMat = hou.node("/mat").createNode(
                re.sub(r'\W+', '', self.asset_name))
            newMat.setName(self.asset_name, 1)
            newMat.setMaterialFlag(True)

            animNode.parm("materialPath").set("/mat/" + newMat.name())
        else:
            qd.error(
                "The material for " + self.asset_name +
                " needs to be republished before it can be cloned in. Republish the material and try again."
            )

    def getMatPath(self):
        asset = self.project.get_asset(self.asset_name)
        element = asset.get_element(Asset.MATERIALS)
        if element.get_last_version() < 0:
            return os.path.join(element._filepath,
                                self.asset_name + "_main.usda")
        path = element.get_last_publish()[3]
        return path
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)