예제 #1
0
def replace_reference(select_info, prefix, options):
    from tactic_load import load_anim, load
    # quick hack
    '''
    if options.find("connection=file system") != -1:
        options = "load_mode=replace|connection=file system"
    else:
        options = "load_mode=replace|connection=http"
    '''
    info = TacticInfo.get() 
    server = info.get_xmlrpc_server()
    ticket = info.get_ticket()
   
    option_dict  = Common.get_option_dict(options)
    option_dict['load_mode'] = 'replace'

    
    # check if user wants to pick a node to update
    user_selected_nodes = []
    if option_dict.get('replace_selected') =='true':
        user_selected_nodes = info.get_app().get_selected_nodes()
        if not user_selected_nodes:
            raise TacticException('A minimum of 1 node must be selected for this "replace selected reference" operation')

    # some instance reference is actually just replace assets from model pipeline
    # In that case, there are only 4 items
    items = select_info.split("|")
    if prefix =='prod/shot_instance' and len(items) == 6:
        snapshot_code, shot_code, instance, context, ns, snap_node_name = \
            select_info.split("|")
        if not user_selected_nodes:
            user_selected_nodes = [snap_node_name]

        for user_selected_node in user_selected_nodes:
            node_name = _check_node_exists(user_selected_node, ns) 
            if node_name:
                option_dict['replacee']= node_name
            options = Common.get_option_str(option_dict)
            load_anim(snapshot_code, shot_code, instance, context, options)
       

    else:
        # this assumes only 1 instance of this asset exist
        snapshot_code, context, ns, snap_node_name = select_info.split("|")
        
        if not user_selected_nodes:
            user_selected_nodes = [snap_node_name]

        for user_selected_node in user_selected_nodes:
            node_name = _check_node_exists(user_selected_node, ns) 

            if node_name:
                option_dict['replacee']= node_name
            options = Common.get_option_str(option_dict)
            load(snapshot_code, context, options)
예제 #2
0
def replace_reference(select_info, prefix, options):
    from tactic_load import load_anim, load
    # quick hack
    '''
    if options.find("connection=file system") != -1:
        options = "load_mode=replace|connection=file system"
    else:
        options = "load_mode=replace|connection=http"
    '''
    info = TacticInfo.get()
    server = info.get_xmlrpc_server()
    ticket = info.get_ticket()

    option_dict = Common.get_option_dict(options)
    option_dict['load_mode'] = 'replace'

    # check if user wants to pick a node to update
    user_selected_nodes = []
    if option_dict.get('replace_selected') == 'true':
        user_selected_nodes = info.get_app().get_selected_nodes()
        if not user_selected_nodes:
            raise TacticException(
                'A minimum of 1 node must be selected for this "replace selected reference" operation'
            )

    # some instance reference is actually just replace assets from model pipeline
    # In that case, there are only 4 items
    items = select_info.split("|")
    if prefix == 'prod/shot_instance' and len(items) == 6:
        snapshot_code, shot_code, instance, context, ns, snap_node_name = \
            select_info.split("|")
        if not user_selected_nodes:
            user_selected_nodes = [snap_node_name]

        for user_selected_node in user_selected_nodes:
            node_name = _check_node_exists(user_selected_node, ns)
            if node_name:
                option_dict['replacee'] = node_name
            options = Common.get_option_str(option_dict)
            load_anim(snapshot_code, shot_code, instance, context, options)

    else:
        # this assumes only 1 instance of this asset exist
        snapshot_code, context, ns, snap_node_name = select_info.split("|")

        if not user_selected_nodes:
            user_selected_nodes = [snap_node_name]

        for user_selected_node in user_selected_nodes:
            node_name = _check_node_exists(user_selected_node, ns)

            if node_name:
                option_dict['replacee'] = node_name
            options = Common.get_option_str(option_dict)
            load(snapshot_code, context, options)
예제 #3
0
파일: xsi_impl.py 프로젝트: 0-T-0/TACTIC
 def get_app_file_group_path(my, file_name, file_range):
     '''get the group path notation specific for the application'''
     pat = re.compile('\.(#+)\.')
     m = pat.search(file_name)
     new_str = file_name
     if m:
         group = m.groups()[0]
         frame_start, frame_end, frame_by = Common.get_file_range(file_range)
         replace_str = '.[%s..%s;%s].'%(frame_start, frame_end, len(group))
         
         new_str = pat.sub(replace_str, file_name)
     return new_str
예제 #4
0
    def get_app_file_group_path(self, file_name, file_range):
        '''get the group path notation specific for the application'''
        pat = re.compile('\.(#+)\.')
        m = pat.search(file_name)
        new_str = file_name
        if m:
            group = m.groups()[0]
            frame_start, frame_end, frame_by = Common.get_file_range(
                file_range)
            replace_str = '.[%s..%s;%s].' % (frame_start, frame_end,
                                             len(group))

            new_str = pat.sub(replace_str, file_name)
        return new_str
예제 #5
0
    def get_textures_from_session(self, node_name):
        texture_nodes = []
        texture_paths = []
        texture_attrs = []

        self.app.xsi.LogMessage("get_textures_from_session")

        root = self.app.xsi.ActiveProject.ActiveScene.Root

        node = root.FindChild(node_name)
        # skip if it is not a Model node
        if not node or node.Type != '#model':
            return [], [], []

        self.app.xsi.LogMessage("node: [%s]" % node)
        try:
            fs = node.ExternalFiles
            tex_node_dict = self._get_texture_node_dict(node_name)
            for f in fs:
                if not f:
                    continue
                path = f.ResolvedPath
                if self.is_file_group(path):
                    group_exists = True
                    file_path = self.get_tactic_file_group_path(path)
                    file_range = self.get_file_range(path)
                    file_group = Common.expand_paths(file_path, file_range)
                    for item in file_group:
                        if not os.path.exists(item):
                            self.app.message(
                                "WARNING: one of the file groups does not exist"
                            )
                            group_exists = False
                            break
                    if not group_exists:
                        continue
                #TODO: add a self.impl.path_exists()
                else:
                    if not os.path.exists(path):
                        continue
                #self.app.xsi.LogMessage("f.PATH " + path)
                owner = f.Owners[0]

                if not path:
                    self.app.message(
                        "WARNING: external file for node [%s] is empty" %
                        node_name)
                    continue

                # check if this is a reference. if so, ignore
                if owner.LockType == c.siLockTypeRefModel:
                    continue

                # if FileType is not Pictures, skip
                if f.FileType != "Pictures":
                    continue

                #to check if a path has either 'ght'(to check if lightmap name exists) since we want to ignore this file
                #along with
                #pat = re.compile('(.*ght.*\.map)|(.*\.(fgmap|phmap|htm))$',re.IGNORECASE)
                #if pat.match(path):
                #    continue

                # texture node contains the mesh node in the model node
                texture_node_list = tex_node_dict.get(path)
                if not texture_node_list:
                    self.app.message(
                        'WARNING: [%s] does not have a corresponding node' %
                        path)
                    continue
                for texture_node in texture_node_list:
                    # texture node should be unique
                    if texture_node not in texture_nodes:
                        texture_nodes.append(texture_node)
                        texture_paths.append(path)
                        texture_attrs.append('SourceFileName')

        except AppException, e:
            self.app.xsi.LogMessage("WARNING: %s" % e.__str__())
예제 #6
0
파일: xsi_impl.py 프로젝트: 0-T-0/TACTIC
    def get_textures_from_session(my, node_name):
        texture_nodes = []
        texture_paths = []
        texture_attrs = []

        my.app.xsi.LogMessage("get_textures_from_session")

        root = my.app.xsi.ActiveProject.ActiveScene.Root

        node = root.FindChild(node_name)
        # skip if it is not a Model node
        if not node or node.Type != '#model':
            return [], [], []

        my.app.xsi.LogMessage("node: [%s]" % node)
        try:
            fs = node.ExternalFiles
            tex_node_dict = my._get_texture_node_dict(node_name)
            for f in fs:
                if not f:
                    continue
                path = f.ResolvedPath
                if my.is_file_group(path):
                    group_exists = True
                    file_path = my.get_tactic_file_group_path(path)
                    file_range = my.get_file_range(path)
                    file_group = Common.expand_paths(file_path, file_range)
                    for item in file_group:
                        if not os.path.exists(item):
                            my.app.message("WARNING: one of the file groups does not exist")
                            group_exists = False
                            break
                    if not group_exists:
                        continue
                #TODO: add a my.impl.path_exists()
                else:
                    if not os.path.exists(path):
                        continue
                #my.app.xsi.LogMessage("f.PATH " + path)
                owner = f.Owners[0]

                if not path:
                    my.app.message("WARNING: external file for node [%s] is empty" % node_name)
                    continue

                # check if this is a reference. if so, ignore
                if owner.LockType == c.siLockTypeRefModel:
                    continue

                # if FileType is not Pictures, skip
                if f.FileType != "Pictures":
                    continue

                #to check if a path has either 'ght'(to check if lightmap name exists) since we want to ignore this file
                #along with 
                #pat = re.compile('(.*ght.*\.map)|(.*\.(fgmap|phmap|htm))$',re.IGNORECASE)
                #if pat.match(path):
                #    continue
                
                # texture node contains the mesh node in the model node
                texture_node_list = tex_node_dict.get(path)
                if not texture_node_list:
                    my.app.message('WARNING: [%s] does not have a corresponding node'%path) 
                    continue
                for texture_node in texture_node_list:
                    # texture node should be unique
                    if texture_node not in texture_nodes:
                        texture_nodes.append(texture_node)
                        texture_paths.append(path)
                        texture_attrs.append('SourceFileName')

        except AppException, e:
            my.app.xsi.LogMessage("WARNING: %s" % e.__str__())
예제 #7
0
    def export_node(my,
                    node_names,
                    context,
                    dir=None,
                    type="mayaAscii",
                    as_ref=False,
                    preserve_ref=True,
                    filename='',
                    instance=None):
        '''exports top node(s) in maya'''

        asset_code = ''
        if isinstance(node_names, list):
            if not list:
                raise MayaException('The list to export is empty')
            my.select_none()
            for node_name in node_names:
                my.select_add(node_name)
            # we just pick a node_name for asset_code which is part of
            # a filename, if used
            if my.is_tactic_node(node_names[0]):
                naming = my.get_node_naming(node_names[0])
                instance = naming.get_instance()
            else:
                instance = node_names[0]

        else:
            my.select(node_names)
            naming = my.get_node_naming(node_names)
            instance = naming.get_instance()

        export_mode = "-es"
        if as_ref:
            export_mode = "-er"

        if preserve_ref:
            export_mode = '-pr %s' % export_mode

        # find the desired extension
        if type == "mayaAscii":
            type_key = type
            ext = "ma"
        elif type == "mayaBinary":
            type_key = type
            ext = "mb"
        elif type == "collada":
            type_key = "COLLADA exporter"
            ext = "dae"
        elif type == "obj":
            type_key = "OBJexport"
            ext = "obj"
        else:
            type_key = "mayaAscii"
            ext = "ma"

        # build the file name
        if filename:
            filename, old_ext = os.path.splitext(filename)
        elif not instance:
            filename = "untitled"
        else:
            filename = instance

        filename = "%s.%s" % (filename, ext)
        filename = Common.get_filesystem_name(filename)

        if dir == None:
            path = mel('file -rename "%s"' % filename)
        else:
            path = "%s/%s" % (dir, filename)

        mel('file -rename "%s"' % path)
        cmd = 'file -force -op "v=0" %s -type "%s"' % (export_mode, type_key)
        print "cmd: ", cmd
        mel(cmd)

        return path
예제 #8
0
    def export_node(self, node_names, context, dir=None, type="mayaAscii", as_ref=False, preserve_ref=True, filename='', instance=None ):
        '''exports top node(s) in maya'''

        asset_code = ''
        if isinstance(node_names, list):
            if not list:
                raise MayaException('The list to export is empty')
            self.select_none()
            for node_name in node_names:
                self.select_add(node_name)
            # we just pick a node_name for asset_code which is part of
            # a filename, if used
            if self.is_tactic_node(node_names[0]):
                naming = self.get_node_naming(node_names[0])
                instance = naming.get_instance()
            else:
                instance = node_names[0]
                
        else:        
            self.select( node_names )
            naming = self.get_node_naming(node_names)
            instance = naming.get_instance()

        export_mode = "-es"
        if as_ref:
            export_mode = "-er"

        if preserve_ref:
            export_mode = '-pr %s' %export_mode

        # find the desired extension
        if type == "mayaAscii":
            type_key = type
            ext = "ma"
        elif type == "mayaBinary":
            type_key = type
            ext = "mb"
        elif type == "collada":
            type_key = "COLLADA exporter"
            ext = "dae"
        elif type == "obj":
            type_key = "OBJexport"
            ext = "obj"
        else:
            type_key = "mayaAscii"
            ext = "ma"


        # build the file name
        if filename:
            filename, old_ext = os.path.splitext(filename)
        elif not instance:
            filename = "untitled"
        else:
            filename = instance

        filename = "%s.%s" % (filename, ext)
        filename = Common.get_filesystem_name(filename) 

        if dir == None:
            path = mel('file -rename "%s"' % filename )
        else:
            path = "%s/%s" % (dir, filename)

        mel('file -rename "%s"' % path )
        cmd = 'file -force -op "v=0" %s -type "%s"' % (export_mode, type_key)
        print "cmd: ", cmd
        mel(cmd)
        
        return path