def execute(self, operation, file_path, **kwargs):
        """
        Main hook entry point
        
        :operation: String
                    Scene operation to perform
        
        :file_path: String
                    File path to use if the operation
                    requires it (e.g. open)
                    
        :returns:   Depends on operation:
                    'current_path' - Return the current scene
                                     file path as a String
                    all others     - None
        """

        if operation == "current_path":
            # return the current scene path
            return FarmAPI.GetKatanaFileName()
        elif operation == "open":
            # do new scene as Maya doesn't like opening
            # the scene it currently has open!
            KatanaFile.Load(file_path)
        elif operation == "save":
            current_file = FarmAPI.GetKatanaFileName()
            # save the current scene:
            KatanaFile.Save(current_file)
Пример #2
0
def kanana_analyse(katana_scene, anal_txt):

    print katana_scene
    print anal_txt
    #yourKatanaScene = "/home/ladaojeiang/yes/demos/katana_files/aovs_prman.katana"
    KatanaFile.Load(
        katana_scene)  # Loading scene /yourDirectory/yourFile.katana

    render_info_dict = {}

    render_nodes = NodegraphAPI.GetAllNodesByType("Render")
    if len(render_nodes) != 0:
        print len(render_nodes)
        print render_nodes
        for render_node in render_nodes:
            if render_node.isBypassed() == False:
                render_outputs = {}
                Source_list = []
                Variance_list = []
                Final_list = []

                render_name = render_node.getName()
                print render_name
                render_node_info = Nodes3DAPI.RenderNodeUtil.GetRenderNodeInfo(
                    render_node)

                for render_output_name in render_node_info.getAllOutputNames():

                    render_output = render_node_info.getOutputInfoByName(
                        render_output_name, 0)['outputFile']
                    #print render_output

                    if render_output.find('tmp') == 1:
                        #print render_output
                        pass
                    elif render_output.find('Source') > 0:
                        Source_list.append(render_output)
                    elif render_output.find('Variance') > 0:
                        Variance_list.append(render_output)
                    elif render_output.find('Final') > 0:
                        Final_list.append(render_output)

                render_outputs['Source'] = Source_list
                render_outputs['Variance'] = Variance_list
                render_outputs['Final'] = Final_list
                render_info_dict[render_name] = render_outputs
            else:
                render_name = render_node.getName()
                print render_name + "  is  not render , this node is disabled"
        print len(render_info_dict.keys())
        #print render_info_dict
        anal_txt_handle = file(anal_txt, 'w')
        anal_txt_handle.write(json.dumps(render_info_dict))
        anal_txt_handle.close()
    else:
        print 'the render node 0, analysis failed!'
        if os.path.exists(anal_txt):
            os.remove(anal_txt)
            sys.exit(1)
Пример #3
0
def writeScript(katanaFile=None, jsonFile):
    from Katana import KatanaFile, NodegraphAPI

    if katanaFile is not None:
        KatanaFile.Load(katanaFile)
    json_data = {}
    print "\n\n########################"
    for node in NodegraphAPI.GetAllNodes():
        if node.getType() == "ArnoldShadingNode":
            node_name = node.getName()
            shader_type = node.getParameter('nodeType').getValue(0)
            if shader_type.startswith("lc_"):
                #~ check if shader_type in SHADERMAPPING
                if not shader_type in SHADERMAPPING:
                    print "#ERROR#", shader_type
                    continue
                json_data[node_name] = []
                #~ read paramter value and record it!
                json_data[node_name].append(shader_type)
                shader_data = []
                for para_name in SHADERMAPPING[shader_type][1]:
                    node.checkDynamicParameters()
                    k_parameter_value = node.getParameter(
                        'parameters.%s.value' % para_name)
                    k_parameter_enable = node.getParameter(
                        'parameters.%s.enable' % para_name)
                    #~ if parameter connected to a node
                    if isPortConnected(node, para_name):
                        connected_node = node.getInputPort(
                            para_name).getConnectedPorts()[0].getNode()
                        # if k_parameter_value.getType() == "numberArray":
                        #     if node_name == "bg_remap_color":
                        #         print node.getInputPort(para_name).getConnectedPorts()[0].getNode()
                        # else:
                        #     connected_node = node.getInputPort(para_name).getConnectedPorts()[0].getNode()
                        shader_data.append(
                            (False, para_name, True, connected_node.getName()))
                    #~ if parameter is a value
                    else:
                        value = []
                        enable = False
                        if k_parameter_enable.getValue(0):
                            enable = True
                        if k_parameter_value.getType() == "numberArray":
                            for child in k_parameter_value.getChildren():
                                value.append(child.getValue(0))
                        else:
                            value.append(k_parameter_value.getValue(0))
                        shader_data.append((enable, para_name, False, value))
                json_data[node_name].append(shader_data)

    print "#$~", jsonFile
    outfile = open(jsonFile, 'w')
    json.dump(json_data, outfile, ensure_ascii=False, sort_keys=True, indent=4)
    outfile.close()
    print "########################\n"
Пример #4
0
def check(file):
    from Katana import KatanaFile, NodegraphAPI
    KatanaFile.Load(file)

    print ""
    for node in NodegraphAPI.GetAllNodes():
        if node.getType() == "ArnoldShadingNode":
            node_name = node.getName()
            shader_type = node.getParameter('nodeType').getValue(0)
            if shader_type.startswith("lc_"):
                #~ check if shader_type in SHADERMAPPING
                print "#ERROR#", node_name, shader_type
                continue
Пример #5
0
def open_katana_scene(katana_scene):
    '''
    :description to open the specific katana scene
    :param katana_scene <str>   
    :example
        from core import scene
        scene.open_katana_scene()        
    '''
    if not os.path.isfile(katana_scene):
        print '#warnings: not found katana scene'
        return
    KatanaFile.Load(katana_scene, isCrashFile=False)
    print '#info: open katana scene', katana_scene
    return True
Пример #6
0
def kanana_analyse(katana_scene,anal_txt):


    #yourKatanaScene = "/home/ladaojeiang/yes/demos/katana_files/aovs_prman.katana"
    KatanaFile.Load( katana_scene ) # Loading scene /yourDirectory/yourFile.katana

    render_info_dict={}
    render_nodes = NodegraphAPI.GetAllNodesByType("Render")
    if len(render_nodes) != 0:    
        for render_node in render_nodes:
            render_output_dict={}
            render_frame_dict={}
            render_name=render_node.getName() 
            #print render_node.getParameters().getXML()
            #print render_name
            render_node_info=Nodes3DAPI.RenderNodeUtil.GetRenderNodeInfo(render_node)

            for render_output_name in render_node_info.getAllOutputNames():
                #print render_node_info.getOutputInfoByName(render_output_name,0)
                render_output=render_node_info.getOutputInfoByName(render_output_name,0)['outputFile']
                print render_output_name,render_output
                if render_output.find('Temp')>0:
                    
                    print ("the %s output is %s ,it is tmp ,dont copy"  % (render_output_name,render_output))
                else:                       
                    render_output_dict[render_output_name]=render_output
                #print render_output_dict



            #if render_node.getParameter('farmSettings.setActiveFrameRange').getValue(0)=="Yes":
            render_start= render_node.getParameter('farmSettings.activeFrameRange.start').getValue(0)
            render_end= render_node.getParameter('farmSettings.activeFrameRange.end').getValue(0)
            #print range(0,Nodes3DAPI.RenderNodeUtil.GetNumRenderOutputs(render_node))
            #print Nodes3DAPI.RenderNodeUtil.GetDefaultIncludedOutputs(render_node).keys()
            render_frame_dict["start"]=render_start 
            render_frame_dict["end"]=render_end    
            #print render_start,render_end
            #print render_frame_dict
            render_info_dict[render_name]=render_output_dict,render_frame_dict
            print render_info_dict
        anal_txt_handle = file(anal_txt, 'w')
        anal_txt_handle.write(json.dumps(render_info_dict))
        anal_txt_handle.close()
    else:
        print 'the render node 0, analysis failed!'
        if  os.path.exists(anal_txt):
            os.remove(anal_txt)
        sys.exit(1)
Пример #7
0
def convert(katanaFile, renderer, outputnode, startframe, endframe, imagename,
            imagedir, threadId):
    KatanaFile.Load(katanaFile)

    for i in range(int(startframe), (int(endframe) + 1)):
        NodegraphAPI.SetCurrentTime(i)
        fileExtension = ''
        if renderer == 'prman':
            fileExtension = 'rib'
        elif renderer == 'arnold':
            fileExtension = 'ass'
        fileName = os.path.join(imagedir,
                                '%s%04d.%s') % (imagename, i, fileExtension)
        print '############################', fileName, '###############################'
        NodeDebugOutput.WriteRenderOutput(NodegraphAPI.GetNode(outputnode),
                                          renderer,
                                          filename=fileName)
        sys.stdout.write('[k2rrFrameConvProgress]_' + str(i) + '_thread_' +
                         str(threadId) + '_')

    sys.stdout.write('[k2rrThreadFinished]_' + str(threadId) + '_')
Пример #8
0
 def displayOpenDialog(self):
     fname = str(
         QFileDialog.getOpenFileName(self, 'Open file',
                                     '/s/prodanim/asterix2',
                                     "Katana files (*.katana)"))
     if fname == '':
         print 'No file has been open'
     if self.sender().objectName() == 'openAction':
         KatanaFile.Load(fname)
         print 'Loading : ' + fname
     else:
         currentSelection = NodegraphAPI.GetAllSelectedNodes()
         #deselect all the node to select only the 2 created nodes and put them floating under the mouse
         for node in currentSelection:
             NodegraphAPI.SetNodeSelected(node, False)
         KatanaFile.Import(fname, floatNodes=True)
         print 'importing : ' + fname
         nodeList = NodegraphAPI.GetAllSelectedNodes()
         # Find Nodegraph tab and float nodes
         nodegraphTab = Tabs.FindTopTab('Node Graph')
         if nodegraphTab:
             nodegraphTab.floatNodes(nodeList)
Пример #9
0
def open_file(log, filepath, origin_path=None):
    if not os.path.exists(filepath):
        raise Exception('{0} does not exist'.format(filepath))

    if origin_path is None: origin_path = filepath

    if HOST == STANDALONE:
        from tentaculo.api import standalone
        standalone.message_function("open_file", [filepath])
    elif HOST == MAYA or HOST == MAYA2:
        check_workspace_maya(log, origin_path)
        mc.file(new=True, force=True)
        mc.file(filepath, open=True, force=True)
        log.debug('Maya openned %s', filepath)
    elif HOST == NUKE:
        nuke.scriptClear()
        nuke.Root().setModified(False)
        nuke.scriptOpen(filepath)
        log.debug("Nuke opened %s", filepath)
    elif HOST == HOUDINI:
        hou.hipFile.load(filepath.replace(
            '\\', '/'))  #, suppress_save_prompt = True)
        log.debug("Houdini opened %s", filepath)
    elif HOST == MAX:
        MaxPlus.FileManager.Open(filepath)
        log.debug("Max opened %s", filepath)
    elif HOST == C4D:
        c4d.documents.LoadFile(str(filepath.replace('\\', '/')))
        log.debug("Cinema 4D opened %s", filepath)
    elif HOST == BLENDER:
        bpy.ops.wm.open_mainfile(filepath=filepath)
        log.debug("Blender opened %s", filepath)
    elif HOST == KATANA:
        KatanaFile.Load(filepath)

    return filepath
Пример #10
0
    def execute(self, operation, file_path, context, parent_action,
                file_version, read_only, **kwargs):
        """
        Main hook entry point

        :param operation:       String
                                Scene operation to perform

        :param file_path:       String
                                File path to use if the operation
                                requires it (e.g. open)

        :param context:         Context
                                The context the file operation is being
                                performed in.

        :param parent_action:   This is the action that this scene operation is
                                being executed for.  This can be one of:
                                - open_file
                                - new_file
                                - save_file_as
                                - version_up

        :param file_version:    The version/revision of the file to be opened.  If this is 'None'
                                then the latest version should be opened.

        :param read_only:       Specifies if the file should be opened read-only or not

        :returns:               Depends on operation:
                                'current_path' - Return the current scene
                                                 file path as a String
                                'reset'        - True if scene was reset to an empty
                                                 state, otherwise False
                                all others     - None
        """

        if operation == "current_path":
            # return the current scene path
            return file_path
        elif operation == "open":
            KatanaFile.Load(file_path)
        elif operation == "save":
            if not os.path.exists(os.path.dirname(file_path)):
                os.makedirs(os.path.dirname(file_path))
            KatanaFile.Save(file_path)
        elif operation == "save_as":
            if not os.path.exists(os.path.dirname(file_path)):
                os.makedirs(os.path.dirname(file_path))
            KatanaFile.Save(file_path)

        elif operation == "reset":

            while KatanaFile.IsFileDirty():
                # Changes have been made to the scene
                res = QtGui.QMessageBox.question(
                    None, "Save your scene?",
                    "Your scene has unsaved changes. Save before proceeding?",
                    QtGui.QMessageBox.Yes | QtGui.QMessageBox.No
                    | QtGui.QMessageBox.Cancel)

                if res == QtGui.QMessageBox.Cancel:
                    return False
                elif res == QtGui.QMessageBox.No:
                    break
                else:
                    if not os.path.exists(os.path.dirname(file_path)):
                        os.makedirs(os.path.dirname(file_path))
                KatanaFile.Save(
                    file_path)  # TODO: warning: this may not work...
            return True
    def execute(self, operation, file_path, context, parent_action,
                file_version, read_only, **kwargs):
        """
        Main hook entry point
        
        :param operation:       String
                                Scene operation to perform
        
        :param file_path:       String
                                File path to use if the operation
                                requires it (e.g. open)
                    
        :param context:         Context
                                The context the file operation is being
                                performed in.
                    
        :param parent_action:   This is the action that this scene operation is
                                being executed for.  This can be one of:
                                - open_file
                                - new_file
                                - save_file_as 
                                - version_up
                        
        :param file_version:    The version/revision of the file to be opened.  If this is 'None'
                                then the latest version should be opened.
        
        :param read_only:       Specifies if the file should be opened read-only or not
                            
        :returns:               Depends on operation:
                                'current_path' - Return the current scene
                                                 file path as a String
                                'reset'        - True if scene was reset to an empty 
                                                 state, otherwise False
                                all others     - None
        """

        if file_path:
            file_path = file_path.replace("/", os.path.sep)

        if operation == "current_path":
            # return the current script path
            return "/path/here".replace("/", os.path.sep)  # TODO!!

        elif operation == "open":
            # open the specified script
            KatanaFile.Load(file_path)

        elif operation == "save":
            # save the current script:
            if not os.path.exists(os.path.dirname(file_path)):
                os.makedirs(os.path.dirname(file_path))
            KatanaFile.Save(file_path)  # TODO: warning: this may not work...

        elif operation == "save_as":
            if not os.path.exists(os.path.dirname(file_path)):
                os.makedirs(os.path.dirname(file_path))
            KatanaFile.Save(file_path)

        elif operation == "reset":
            """
            Reset the scene to an empty state
            """
            while KatanaFile.IsFileDirty():
                # Changes have been made to the scene
                res = QtGui.QMessageBox.question(
                    None, "Save your scene?",
                    "Your scene has unsaved changes. Save before proceeding?",
                    QtGui.QMessageBox.Yes | QtGui.QMessageBox.No
                    | QtGui.QMessageBox.Cancel)

                if res == QtGui.QMessageBox.Cancel:
                    return False
                elif res == QtGui.QMessageBox.No:
                    break
                else:
                    if not os.path.exists(os.path.dirname(file_path)):
                        os.makedirs(os.path.dirname(file_path))
                    KatanaFile.Save(
                        file_path)  # TODO: warning: this may not work...
            return True

        # Create a new engine instance from the existing one, with the new context
        # Specify "shot_step" environment if the current context specifies a step
        if context.step:
            env = context.tank.pipeline_configuration.get_environment(
                "shot_step", context=context)
        # Otherwise, just get a "project" level context
        else:
            env = context.tank.pipeline_configuration.get_environment(
                "project", context=context)

        name = "tk-katana"  # TODO: Get this properly?
        new_katana_engine = engine.KatanaEngine(context.tank, context, name,
                                                env)
        new_katana_engine.add_katana_menu()
Пример #12
0
        if node_name:
            nodes.append(NodegraphAPI.GetNode(node_name))
        else:

            nodes = NodegraphAPI.GetAllNodesByType("PrmanShadingNode")
        for node in nodes:
            if node.getParameter("nodeType").getValue(0) == "PxrTexture":
                print(
                    node.getParameter("parameters.filename.value").getValue(0))


if __name__ == '__main__':

    katana_scene = sys.argv[1]
    task_json = sys.argv[2]
    system_json = sys.argv[3]
    #_tid_from_cmd = sys.argv[2]
    #_inf_from_cmd = sys.argv[3]
    KatanaFile.Load(katana_scene)
    print(katana_scene)
    print(task_json)
    print(system_json)
    print(os.path.basename(sys.executable.lower()))
    kanana_analyse = ray_Katana_rendernodes()
    kanana_analyse.kanana_rendernodes(task_json)
    katana_asset = ray_Katana_asset()
    task_dict = katana_asset.open_json(task_json)
    system_dict = katana_asset.open_json(system_json)
    katana_asset.get_Alembic_In()
    katana_asset.get_PrmanShadingNode()
Пример #13
0
def recoverScript(katanaFile=None, logsFile=None, jsonFile):
    from Katana import KatanaFile, NodegraphAPI
    if katanaFile is not None:
        KatanaFile.Load(katanaFile)
    katana_file = katanaFile
    logs_file = logsFile
    file_name = NodegraphAPI.GetRootNode().getParameter(
        'katanaSceneName').getValue(0)
    katana_file = os.path.join(getVersoonUpKatanaDir(katana_file), file_name)
    #~ version up
    katana_file = katana_path[:-3] + "{:03}".format(int(katana_path[-3:]) + 1)
    infile = open(jsonFile, 'r')
    json_data = json.load(infile)
    infile.close()

    #~ loops all nodes
    for node_name in json_data:
        node = NodegraphAPI.GetNode(node_name)
        node_data = json_data[node_name]
        mx_shader_name = node_data[0]
        mx_shader_data = node_data[1]
        #~ loops all parameters
        for para_data in mx_shader_data:
            #~ read data from json data
            enable = para_data[0]
            name = para_data[1]
            connected = para_data[2]
            value = para_data[3]

            #~ translate data
            translate_shader = SHADERMAPPING[mx_shader_name][0]
            translate_para_list = SHADERMAPPING[mx_shader_name][1]
            translate_name = translate_para_list[name]

            #~ set new shader type
            node.checkDynamicParameters()
            if translate_shader != mx_shader_name:
                node.getParameter('nodeType').setValue(translate_shader, 0)
                node.checkDynamicParameters()
                if translate_shader != mx_shader_name:
                    from Katana import CacheManager
                    CacheManager.flush(isNodeGraphLoading=False)

            #~ if node connected to other
            if connected:
                if not mx_shader_name in SHADERMAPPING:
                    continue
                connected_node = NodegraphAPI.GetNode(value)
                out_port = connected_node.getOutputPorts()[0]

                in_port = node.getInputPort(translate_name)
                node.getInputPort(translate_name).connect(out_port)
            #~ recover parameter value
            else:
                if not enable:
                    continue
                node.checkDynamicParameters()
                para_enable = node.getParameter('parameters.%s.enable' %
                                                translate_name)
                para_enable.setValue(1, 0)
                para_value = node.getParameter('parameters.%s.value' %
                                               translate_name)
                node.checkDynamicParameters()
                if para_value.getType() == "numberArray":
                    children = para_value.getChildren()
                    for i in range(0, len(value)):
                        children[i].setValue(value[i], 0)
                elif para_value.getType() == "number":
                    para_value.setValue(float(value[0]), 0)
                else:
                    para_value.setValue(str(value[0]), 0)

    KatanaFile.Save(katana_path)
    if logsFile is not None:
        JobRecord(logs_file, katana_file)
Пример #14
0
 def openScene(filePath):
     KatanaFile.Load(filePath)
 def setUpClass(cls):
     KatanaFile.Load('basic.katana')
Пример #16
0
    def execute(self, operation, file_path, context, parent_action,
                file_version, read_only, **kwargs):
        """Main hook entry point.

        Args:
            operation (str):
                Scene operation to perform

            file_path (str):
                File path to use if the operation
                requires it (e.g. open)

            context (sgtk.Context):
                The context the file operation is being
                performed in.

            parent_action (str):
                Action that this scene operation is being executed for.
                This can be one of:

                - "open_file"
                - "new_file"
                - "save_file_as"
                - "version_up"

            file_version:
                The version/revision of the file to be opened.
                If this is ``None`` then the latest version should be opened.

            read_only (bool):
                Specifies if the file should be opened read-only or not

        Returns:
            object: Depending on ``operation``:

                - 'current_path': Current scene file path as a ``str``
                - 'reset': ``True`` if scene was reset to an empty state,
                   otherwise ``False``
                - all others: ``None``
        """
        if operation == "current_path":
            # return the current scene path
            return file_path

        elif operation == "open":
            KatanaFile.Load(file_path)

        elif operation == "save":
            if not os.path.exists(os.path.dirname(file_path)):
                os.makedirs(os.path.dirname(file_path))
            KatanaFile.Save(file_path)

        elif operation == "save_as":
            if not os.path.exists(os.path.dirname(file_path)):
                os.makedirs(os.path.dirname(file_path))
            KatanaFile.Save(file_path)

        elif operation == "reset":
            while KatanaFile.IsFileDirty():
                # Changes have been made to the scene
                res = QtGui.QMessageBox.question(
                    None, "Save your scene?",
                    "Your scene has unsaved changes. Save before proceeding?",
                    QtGui.QMessageBox.Yes | QtGui.QMessageBox.No
                    | QtGui.QMessageBox.Cancel)

                if res == QtGui.QMessageBox.Cancel:
                    return False

                elif res == QtGui.QMessageBox.No:
                    break

                else:
                    if not os.path.exists(os.path.dirname(file_path)):
                        os.makedirs(os.path.dirname(file_path))
                KatanaFile.Save(
                    file_path)  # TODO: warning: this may not work...

            return True