def Search_replace(self, sender, evtid): ix.begin_command_batch('Undo Search_replace') Selected_Hierarchy = Hierarchy_checkbox.get_value() oldtext = oldtext_lineEdit.get_text() newtext = newtext_lineEdit.get_text() counter = 0 for i in range( ix.selection.get_count() ): selected_obj = str(ix.selection[i]) selected_obj_name = selected_obj.split('/') if len(oldtext) != 0 : new_name = selected_obj_name[-1].replace( oldtext , newtext ) ix.cmds.RenameItem( selected_obj , new_name ) if str(selected_obj_name[-1]) != new_name: counter += 1 if Selected_Hierarchy : if ix.selection[i].is_context(): Hierarchy_list = Hierarchy_lister( ix.selection[i] , True , True ) for iii in range(len(Hierarchy_list)): selected_obj_name = Hierarchy_list[iii].split('/') if len(oldtext) != 0 : new_name = selected_obj_name[-1].replace( oldtext , newtext ) ix.cmds.RenameItem( Hierarchy_list[iii] , new_name ) if str(selected_obj_name[-1]) != new_name: counter += 1 ix.log_info ( str(counter) + " Object has been renamed" + " -- from renamer" ) ix.end_command_batch()
def add_prefix(self, sender, evtid): ix.begin_command_batch('Undo Add Prefix') Selected_Hierarchy = Hierarchy_checkbox.get_value() string_Prefix = Prefix_lineEdit.get_text() counter = 0 for i in range(ix.selection.get_count()): selected_obj = str(ix.selection[i]) selected_obj_name = selected_obj.split('/') if len(string_Prefix) != 0: new_name = (string_Prefix + str(selected_obj_name[-1])) ix.cmds.RenameItem(selected_obj, new_name) if str(selected_obj_name[-1]) != new_name: counter += 1 if Selected_Hierarchy: if ix.selection[i].is_context(): Hierarchy_list = Hierarchy_lister( ix.selection[i], True, True) for iii in range(len(Hierarchy_list)): selected_obj_name = Hierarchy_list[iii].split('/') new_name = (string_Prefix + str(selected_obj_name[-1])) ix.cmds.RenameItem(Hierarchy_list[iii], new_name) if str(selected_obj_name[-1]) != new_name: counter += 1 ix.log_info( str(counter) + " Object has been added your Prefix" + " -- from AWA renamer") ix.end_command_batch()
def Filereader_Renamer(self, sender, evtid): ix.begin_command_batch('Undo Filereader Rename') Selected_Hierarchy = Hierarchy_checkbox.get_value() file_suffix = file_suffix_checkbox.get_value() object_type_suffix = object_type_suffix_checkbox.get_value() counter = 0 for i in range(ix.selection.get_count() ): selected_obj = str(ix.selection[i]) selected_obj_name = selected_obj.split('/') #True Type if ix.selection[i].is_context() is False : object_type_fullname = ix.selection[i].get_class_name() if object_type_fullname in dict_suffix_short: #has dirctory if len( str( ix.selection[i].attrs.filename) ) > 2 : filename_full_path = ix.selection[i].attrs.filename #print (filename_full_path[0]) file_name_and_extension = os.path.splitext( os.path.split( str(filename_full_path[0]) )[1]) #print (file_name_and_extension) new_name = file_name_and_extension[0] if file_suffix : new_name = new_name + "_" + file_name_and_extension[1][ 1: ] if object_type_suffix : new_name = new_name + "_" + dict_suffix_short.get(object_type_fullname) ix.cmds.RenameItem( selected_obj , new_name ) if str(selected_obj_name[-1]) != new_name : counter += 1 if Selected_Hierarchy : if ix.selection[i].is_context(): Hierarchy_list = Hierarchy_lister( ix.selection[i] , True , True ) for iii in range(len(Hierarchy_list)): selected_obj_name = str(Hierarchy_list[iii]).split('/') #True Type if Hierarchy_list[iii].is_context() is False : object_type_fullname = Hierarchy_list[iii].get_class_name() if object_type_fullname in dict_suffix_short: #has dirctory if len( str( Hierarchy_list[iii].attrs.filename) ) > 2 : filename_full_path = Hierarchy_list[iii].attrs.filename #print (filename_full_path[0]) file_name_and_extension = os.path.splitext( os.path.split( str(filename_full_path[0]) )[1]) #print (file_name_and_extension) new_name = file_name_and_extension[0] if file_suffix : new_name = new_name + "_" + file_name_and_extension[1][ 1: ] if object_type_suffix : new_name = new_name + "_" + dict_suffix_short.get(object_type_fullname) ix.cmds.RenameItem( Hierarchy_list[iii] , new_name ) if str(selected_obj_name[-1]) != new_name : counter += 1 ix.log_info (str(counter) + " Object has been renamed" + " -- from AWA renamer") ix.end_command_batch()
def create_dome(name, path_to_hdri_map): ix.log_info("Creating HDRI Dome, you can Undo.") create_env = None ix.begin_command_batch("AssetNinjaImportHdri") clean_name = str(name) mapfile = ix.cmds.CreateObject(clean_name, 'TextureMapFile') mapfile.attrs.projection = 5 path_to_hdri_map = str(path_to_hdri_map) mapfile.attrs.filename = path_to_hdri_map mapfile.attrs.interpolation_mode = 1 mapfile.attrs.mipmap_filtering_mode = 1 mapfile.attrs.color_space_auto_detect = False mapfile.attrs.file_color_space = 'linear' mapfile.attrs.pre_multiplied = False ibl_name = "IBL_" + clean_name light = ix.cmds.CreateObject(ibl_name, 'LightPhysicalEnvironment') ix.cmds.SetTexture([light.get_full_name() + ".color"], mapfile.get_full_name()) if create_env: env = ix.cmds.CreateObject('ibl_env', 'GeometrySphere') env_mat = ix.cmds.CreateObject('ibl_mat', 'MaterialMatte') env.attrs.override_material = env_mat env.attrs.unseen_by_camera = True env.attrs.cast_shadows = False env.attrs.receive_shadows = False env.attrs.is_emitter = False env.attrs.radius = 500001 env.attrs.unseen_by_rays = True env.attrs.unseen_by_reflections = True env.attrs.unseen_by_refractions = True env.attrs.unseen_by_gi = True env.attrs.unseen_by_sss = True ix.cmds.SetTexture([env_mat.get_full_name() + ".color"], mapfile.get_full_name()) ix.cmds.SetTexture([light.get_full_name() + ".parent"], env.get_full_name()) ix.end_command_batch() ix.log_info("Dome IBL Done.")
def combiner_group_Renamer(self, sender, evtid): ix.begin_command_batch('Undo Combiner Group Rename') Selected_Hierarchy = Hierarchy_checkbox.get_value() object_type_suffix = combiner_group_object_type_suffix_checkbox.get_value( ) counter = 0 for i in range(ix.selection.get_count()): selected_obj = str(ix.selection[i]) selected_obj_name = selected_obj.split('/') if ix.selection[i].is_context() is False: object_type_fullname = ix.selection[i].get_class_name() #True Type #SceneObjectCombiner if object_type_fullname == "SceneObjectCombiner": #has dirctory if len(str(ix.selection[i].attrs.objects)) > 1: First_Ref_Path = str(ix.selection[i].attrs.objects[0]) new_name = First_Ref_Path.split('/')[-1] if object_type_suffix == 1: new_name = new_name + "_" + "Combiner" ix.cmds.RenameItem(selected_obj, new_name) if str(selected_obj_name[-1]) != new_name: counter += 1 #True Type #SceneObjectCombiner if object_type_fullname == "Group": #has dirctory if len(str(ix.selection[i].attrs.inclusion_items)) > 1: First_Ref_Path = str( ix.selection[i].attrs.inclusion_items[0]) new_name = First_Ref_Path.split('/')[-1] if object_type_suffix == 1: new_name = new_name + "_" + "Group" ix.cmds.RenameItem(selected_obj, new_name) if str(selected_obj_name[-1]) != new_name: counter += 1 if Selected_Hierarchy: if ix.selection[i].is_context(): Hierarchy_list = Hierarchy_lister(ix.selection[i], True, True) for iii in range(len(Hierarchy_list)): selected_obj_name = str(Hierarchy_list[iii]).split('/') if Hierarchy_list[iii].is_context() is False: object_type_fullname = Hierarchy_list[ iii].get_class_name() #True Type #SceneObjectCombiner if object_type_fullname == "SceneObjectCombiner": #has dirctory if len(str(Hierarchy_list[iii].attrs.objects) ) > 1: First_Ref_Path = str( Hierarchy_list[iii].attrs.objects[0]) new_name = First_Ref_Path.split('/')[-1] if object_type_suffix == 1: new_name = new_name + "_" + "Combiner" ix.cmds.RenameItem(Hierarchy_list[iii], new_name) if str(selected_obj_name[-1]) != new_name: counter += 1 #True Type #SceneObjectCombiner if object_type_fullname == "Group": if len( str(Hierarchy_list[iii].attrs. inclusion_items)) > 1: First_Ref_Path = str( Hierarchy_list[iii].attrs. inclusion_items[0]) new_name = First_Ref_Path.split('/')[-1] if object_type_suffix == 1: new_name = new_name + "_" + "Group" ix.cmds.RenameItem(Hierarchy_list[iii], new_name) if str(selected_obj_name[-1]) != new_name: counter += 1 ix.log_info( str(counter) + " Object has been renamed" + " -- from AWA renamer") ix.end_command_batch()
final_matrix.copy_from(source_mx) target.get_module().set_matrix(final_matrix, ix.api.ModuleSceneItem.SPACE_LOCAL) #---------------------------------------------------- # Set Parent #---------------------------------------------------- def setParent(source, target): ix.cmds.SetParent(['%s.parent' % target], ['%s' % source], [0]) #---------------------------------------------------- # RUN #---------------------------------------------------- ix.begin_command_batch('copyMatrixSetParent') folderName = 'loc_lgt' folderPath = '%s/%s' % (ix.get_current_context(), folderName) createContext(folderPath) selectObj = ix.selection selectObjNum = ix.selection.get_count() obj = [] for i in range(selectObjNum): obj.append(selectObj[i]) for i in obj: if i.get_class().is_kindof("SceneItem"):
def do_export(): # extensions = 'All Known Files...\t*.{zip}\nZip Archive (*.zip)\t*.{zip}\n' extensions = 'All Known Files...\t*' dest_dir = '/var/tmp' if platform.system() == "Windows": dest_dir = ix.api.GuiWidget.save_file(ix.application, '', 'Select temp folder',extensions) # if dest_file[-4:] == ".zip": dest_file = dest_file[:-4] # dest_dir = os.path.dirname(dest_file) # if dest_file == '' or not os.path.isdir(dest_dir): # if dest_file == '': # pass # cancel # else: # ix.log_error("The specified directory is invalid") # return # else: ix.enable_command_history() ix.begin_command_batch("ExportRenderPackage()") # first we flatten all contexts make_all_context_local() # then we gather all external file resources unique_files = {} attrs = ix.api.OfAttr.get_path_attrs() new_file_list = [] attr_list = [] scene_info = {"output_path": ""} for i in range(attrs.get_count()): # deduplicating file_path = attrs[i].get_string() if not os.path.isfile(file_path): # Find the output path... if attrs[i].get_name() == "save_as": scene_info['output_path'] = os.path.dirname(file_path) print("Skipping file %s" % file_path) continue attr_list.append(attrs[i].get_full_name()) if not file_path in unique_files: # de-windoify path new_file_path = os.path.abspath(file_path).replace("\\", '/').replace(':', '').replace('\\\\', '/') # getting the absolute path of the file new_file_path = "$PDIR/" + new_file_path unique_files[file_path] = new_file_path new_file_list.append(new_file_path) else: new_file_list.append(unique_files[file_path]) # updating attribute path with new filename ix.enable_command_history() ix.cmds.SetValues(attr_list, new_file_list) ix.log_info("saving project file...") ix.application.check_for_events() name = ix.application.get_current_project_filename() name = os.path.basename(name) if name == '': name = "Untitled.project" if name.endswith(".project"): name = name[:-8] + ".render" else: name += ".render" # generating temp folder in Clarisse temp directory gen_tempdir = tempfile.mkdtemp('', '', dest_dir) # ix.application.export_context_as_project(gen_tempdir + '/' + name, ix.application.get_factory().get_root()) ix.application.export_render_archive(gen_tempdir + '/' + name) # restoring file attributes with original paths # copying files in new directory # return_files = [gen_tempdir + '/' + name] scene_info["scene_file"] = "%s/%s" % (gen_tempdir, name) scene_info["dependencies"] = [gen_tempdir + '/' + name] for file_path in unique_files: target = unique_files[file_path][5:] target_dir = gen_tempdir + os.path.dirname(target) if not os.path.isdir(target_dir): os.makedirs(target_dir) ix.log_info("copying file '" + file_path + "'..." ) ix.application.check_for_events() new_path = gen_tempdir + target scene_info["dependencies"].append(new_path) if platform.system == "Windows": shutil.copyfile(file_path, new_path) else: os.symlink(file_path, new_path) # The stuff that is commented out packages the dependencies into an archive # this is something we do not support at the moment, but I'm leaving around # for future reference... # ix.log_info("building archive...") ix.application.check_for_events() # shutil.make_archive(dest_file, 'zip', gen_tempdir) # ix.log_info("cleaning temporary files...") # ix.application.check_for_events() # shutil.rmtree(gen_tempdir) # ix.log_info("Package successfully exported in '" + dest_file + ".zip'.") ix.end_command_batch() # # restore original state ix.application.get_command_manager().undo() ix.disable_command_history() print("Dependencies: ") for filename in scene_info["dependencies"]: print("\t%s" % filename) return scene_info