def exec_(application): is_history_enabled = ix.application.get_command_manager().is_history_enabled() PyQtAppClarisseHelper(application).exec_() while are_windows_visible(): if is_history_enabled == False: ix.enable_command_history() ix.application.check_for_events() if is_history_enabled == False: ix.disable_command_history()
def run(self): # we make sure to enable history as by default history is disabled in scripts. # remember the application will be running in the background # we want command history to be enabled! is_history_enabled = ix.application.get_command_manager( ).is_history_enabled() if not is_history_enabled: ix.enable_command_history() self.app.exec_() if not is_history_enabled: ix.disable_command_history()
import ix app = ix.application ix.enable_command_history() working_context = app.get_working_context() if (not working_context.is_editable()) and working_context.is_content_locked() and working_context.is_remote() : ix.log_error("Cannot reference project in a locked context.\n") elif reference_path != "": clarisse_win = app.get_event_window() filenames = ix.api.CoreStringVector() filenames.add(reference_path) clarisse_win.set_mouse_cursor(ix.api.Gui.MOUSE_CURSOR_WAIT) app.disable() ix.reference_file(working_context, filenames) app.enable() clarisse_win.set_mouse_cursor(ix.api.Gui.MOUSE_CURSOR_DEFAULT) ix.disable_command_history()
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