def execute(self, context): from os.path import basename, splitext filepath = self.filepath # change the menu title to the most recently chosen option preset_class = getattr(bpy.types, self.menu_idname) preset_class.bl_label = bpy.path.display_name(basename(filepath)) nb = bpy.context.scene.nb nb.settingprops.sp_presetlabel = preset_class.bl_label ext = splitext(filepath)[1].lower() # execute the preset using script.python_file_run if ext == ".py": # bpy.ops.script.python_file_run(override, filepath=filepath) # NOTE: override because of RuntimeError on running from headless for area in bpy.context.screen.areas: if area.type == 'VIEW_3D': override = bpy.context.copy() override['area'] = area bpy.ops.script.python_file_run(override, filepath=filepath) break elif ext == ".xml": import rna_xml rna_xml.xml_file_run(context, filepath, preset_class.preset_xml_map) else: self.report({'ERROR'}, "unknown filetype: %r" % ext) return {'CANCELLED'} return {'FINISHED'}
def execute_preset(context, filepath, menu_idname): """scripts/startup/bl_operators/presets.py: 202: class ExecutePreest""" # change the menu title to the most recently chosen option preset_class = getattr(bpy.types, menu_idname) preset_class.bl_label = bpy.path.display_name(os.path.basename(filepath)) ext = os.path.splitext(filepath)[1].lower() # execute the preset using script.python_file_run if ext == ".py": # bpy.ops.script.python_file_run(filepath=filepath) try: with open(filepath, 'r') as f: txt = f.read() exec(txt) except: traceback.print_exc() elif ext == ".xml": import rna_xml rna_xml.xml_file_run(context, filepath, preset_class.preset_xml_map) else: # self.report({'ERROR'}, "unknown filetype: %r" % ext) return {'CANCELLED'} return {'FINISHED'}
def execute(self, context): from os.path import basename, splitext filepath = self.filepath # change the menu title to the most recently chosen option preset_class = getattr(bpy.types, self.menu_idname) preset_class.bl_label = bpy.path.display_name(basename(filepath)) ext = splitext(filepath)[1].lower() # execute the preset using script.python_file_run if ext == ".py": #FRACTURE MODIFIER HACK, cant get bpy.context.fracture to be run via py script else... #so fake a context here mod = False if context.object is not None: for md in context.object.modifiers: if md.type == 'FRACTURE': mod = True break if (mod): ctx = bpy.context.copy() ctx["fracture"] = md bpy.ops.script.python_file_run(ctx, filepath=filepath) else: bpy.ops.script.python_file_run(filepath=filepath) elif ext == ".xml": import rna_xml rna_xml.xml_file_run(context, filepath, preset_class.preset_xml_map) else: self.report({'ERROR'}, "unknown filetype: %r" % ext) return {'CANCELLED'} return {'FINISHED'}
def execute(self, context): from os.path import basename, splitext filepath = self.filepath # change the menu title to the most recently chosen option preset_class = getattr(bpy.types, self.menu_idname) preset_class.bl_label = bpy.path.display_name(basename(filepath)) ext = splitext(filepath)[1].lower() if ext not in {".py", ".xml"}: self.report({'ERROR'}, "unknown filetype: %r" % ext) return {'CANCELLED'} if hasattr(preset_class, "reset_cb"): preset_class.reset_cb(context) if ext == ".py": try: bpy.utils.execfile(filepath) except Exception as ex: self.report({'ERROR'}, "Failed to execute the preset: " + repr(ex)) elif ext == ".xml": import rna_xml rna_xml.xml_file_run(context, filepath, preset_class.preset_xml_map) if hasattr(preset_class, "post_cb"): preset_class.post_cb(context) return {'FINISHED'}
def execute(self, context): from os.path import basename, splitext filepath = self.filepath # change the menu title to the most recently chosen option preset_class = getattr(bpy.types, 'RENDER_MT_output') preset_class.bl_label = bpy.path.display_name(basename(filepath)) ext = splitext(filepath)[1].lower() # execute the preset using script.python_file_run if ext == ".py": bpy.ops.script.python_file_run(filepath=filepath) render = context.scene.render preset_filepath = render.filepath if preset_filepath.startswith('{'): blend_filepath = context.blend_data.filepath if blend_filepath: filename = bpy.path.display_name_from_filepath(blend_filepath) render.filepath = '//' + preset_filepath.format(filename=filename) else: render.filepath = '/tmp/' + preset_filepath.format(filename='untitled') else: print("Unsupported markup") elif ext == ".xml": import rna_xml rna_xml.xml_file_run(context, filepath, preset_class.preset_xml_map) else: self.report({'ERROR'}, "unknown filetype: %r" % ext) return {'CANCELLED'} return {'FINISHED'}
def update(filepath): import rna_xml context = bpy.context print("Updating theme: %r" % filepath) preset_xml_map = ( ("user_preferences.themes[0]", "Theme"), ("user_preferences.ui_styles[0]", "Theme"), ) rna_xml.xml_file_run(context, filepath, preset_xml_map) rna_xml.xml_file_write(context, filepath, preset_xml_map)
def update(filepath): import rna_xml context = bpy.context print("Updating theme: %r" % filepath) preset_xml_map = (("user_preferences.themes[0]", "Theme"), ) rna_xml.xml_file_run(context, filepath, preset_xml_map) rna_xml.xml_file_write(context, filepath, preset_xml_map)
def execute(self, context): from os.path import basename, splitext filepath = self.filepath # change the menu title to the most recently chosen option preset_class = getattr(bpy.types, self.menu_idname) preset_class.bl_label = bpy.path.display_name(basename(filepath)) ext = splitext(filepath)[1].lower() # execute the preset using script.python_file_run if ext == ".py": bpy.ops.script.python_file_run(filepath=filepath) elif ext == ".xml": import rna_xml rna_xml.xml_file_run(context, filepath, preset_class.preset_xml_map) else: self.report({'ERROR'}, "unknown filetype: %r" % ext) return {'CANCELLED'} return {'FINISHED'}
def execute(self, context): from os.path import basename, splitext filepath = self.filepath # change the menu title to the most recently chosen option preset_class = getattr(bpy.types, self.menu_idname) preset_class.bl_label = bpy.path.display_name(basename(filepath)) ext = splitext(filepath)[1].lower() # execute the preset using script.python_file_run if ext == ".py": bpy.ops.script.python_file_run(filepath=filepath) elif ext == ".xml": import rna_xml rna_xml.xml_file_run(context, filepath, preset_class.preset_xml_map) else: self.report({"ERROR"}, "unknown filetype: %r" % ext) return {"CANCELLED"} return {"FINISHED"}
def execute(self, context): from os.path import basename, splitext filepath = self.filepath # change the menu title to the most recently chosen option preset_class = getattr(bpy.types, 'RENDER_MT_output') preset_class.bl_label = bpy.path.display_name(basename(filepath)) ext = splitext(filepath)[1].lower() # execute the preset using script.python_file_run if ext == ".py": bpy.ops.script.python_file_run(filepath=filepath) render = context.scene.render preset_filepath = render.filepath if preset_filepath.startswith('{'): blend_filepath = context.blend_data.filepath if blend_filepath: filename = bpy.path.display_name_from_filepath( blend_filepath) render.filepath = '//' + preset_filepath.format( filename=filename) else: render.filepath = '/tmp/' + preset_filepath.format( filename='untitled') else: print("Unsupported markup") elif ext == ".xml": import rna_xml rna_xml.xml_file_run(context, filepath, preset_class.preset_xml_map) else: self.report({'ERROR'}, "unknown filetype: %r" % ext) return {'CANCELLED'} return {'FINISHED'}