def AlembicSwap(self, ModifierName): NewCachePath = bpy.context.scene.NewCachePath #upload new cache bpy.ops.cachefile.open(filepath=NewCachePath) NewCache = bpy.data.cache_files.get(basename(NewCachePath)) #just in case there's been a missmatch because of a previously loaded cache file with the same name... if abspath(NewCache.filepath) != abspath(NewCachePath): for CF in bpy.data.cache_files: if CF.name.contains(basename(NewCachePath)) and abspath( CF.filepath) == abspath(NewCachePath): NewCache = CF #look for objects with same current cache CurrentCache = bpy.context.active_object.modifiers[ ModifierName].cache_file for obj in bpy.context.scene.objects: if len(obj.modifiers) > 0: for mod in obj.modifiers: if mod.type == "MESH_SEQUENCE_CACHE": if mod.cache_file == CurrentCache: #swap cache mod.cache_file = NewCache self.report({'INFO'}, 'Cache succesfully changed :)')
def draw(self, context): layout = self.layout obj = context.object scene = context.scene row = layout.row() row.label(text="Active object: " + obj.name, icon='OBJECT_DATA') IdentifyCache = self.IdentifyCache(obj) row = layout.row() row.label(text=IdentifyCache["text"], icon=IdentifyCache["icon"]) if IdentifyCache["CurrentCacheFile"]: layout.separator() box = layout.box() box.label(text="New Cache File") box.prop(scene, "NewCachePath", text="") if basename(scene.NewCachePath ) == IdentifyCache["CurrentCacheFile"]["name"]: box.label( text= "Attention: Same cache file name as current, are you sure you want to re-upload?", translate=True, icon='ERROR') row = layout.row() row.operator( "scene.upload_and_swap", icon='ARROW_LEFTRIGHT').CurrentCacheFile = IdentifyCache[ "CurrentCacheFile"]["mod_name"] + '___' + IdentifyCache[ "CurrentCacheFile"]["format"]
def get_save_ID(): blendname = basename(bpy.data.filepath).rpartition('.')[0] rndr = bpy.context.scene.render format = rndr.image_settings.file_format \ = bpy.context.scene.auto_save_format if format == 'OPEN_EXR_MULTILAYER': extension = '.exr' if format == 'JPEG': extension = '.jpg' if format == 'PNG': extension = '.png' filepath = get_filepath() #imagefiles starting with the blendname files = [f for f in listdir(filepath) \ if f.startswith(blendname) \ and f.lower().endswith(('.png', '.jpg', '.jpeg', '.exr'))] highest = 0 if files: for f in files: #find last numbers in the filename after the blendname suffix = findall('\d+', f.split(blendname)[-1]) if suffix: if int(suffix[-1]) > highest: highest = int(suffix[-1]) save_ID = blendname + '_' + str(highest).zfill(3) + extension return save_ID
def find_all_node_slot_images( context, use_image_file_name=True ): # type: (bpy.Optional[bpy.ContextType], bool) -> SlotImages """use_image_file_name will use the basename of the file path as opposed to the name of the image data block""" nodes = nodes_from_context(context) if nodes is None: return SlotImages(set(), set()) all_image_names = set() # type: set[str] selected_image_names = set() # type: set[str] for item in nodes: node = is_a_scene_node(item) if node is None: continue if node.number_of_slots <= 0: continue for i in range(node.number_of_slots): image = get_slot_image(node, i + 1) if image is None: continue name = basename( image.filepath) if use_image_file_name else image.name all_image_names.add(name) if node.select: selected_image_names.add(name) return SlotImages(all_image_names, selected_image_names)
def get_save_ID(): rdff = bpy.context.scene.render.image_settings.file_format blendname = basename(bpy.data.filepath).rpartition('.')[0] formats=['BMP', 'IRIS', 'PNG', 'JPEG', 'JPEG2000', 'TARGA', 'TARGA_RAW', \ 'CINEON', 'DPX', 'OPEN_EXR_MULTILAYER', 'OPEN_EXR', 'HDR', 'TIFF', \ 'AVI_JPEG', 'AVI_RAW', 'FFMPEG'] exts=['.bmp', '.rgb', '.png', '.jpg', '.jp2', '.tga', '.tga', '.cin', \ '.exr', '.exr', '.hdr', '.tiff', '.avi', '.avi', '.ffmpeg'] format = bpy.context.scene.auto_save_format if format not in formats: format = rdff i = 0 while i < len(formats): if formats[i] == format: extension = exts[i] i += 1 filepath = get_filepath() # imagefiles starting with the blendname files = [f for f in listdir(filepath) \ if f.startswith(blendname) \ and f.lower().endswith(('.png', '.jpg', '.jpeg', '.exr'))] highest = 0 if files: for f in files: # find last numbers in the filename after the blendname suffix = findall('\d+', f.split(blendname)[-1]) if suffix: if int(suffix[-1]) > highest: highest = int(suffix[-1]) save_ID = blendname + '_' + str(highest).zfill(3) + extension return save_ID
def SerializeString(self, writer, string): string = path.basename(string) writer.write(struct.pack("B", len(string))) for c in string.encode(): writer.write(struct.pack("b", c))
def auto_save_render(scene): if not scene.save_after_render or not bpy.data.filepath: return rndr = scene.render original_format = rndr.image_settings.file_format format = rndr.image_settings.file_format = scene.auto_save_format if format == 'OPEN_EXR_MULTILAYER': extension = '.exr' if format == 'JPEG': extension = '.jpg' if format == 'PNG': extension = '.png' blendname = basename(bpy.data.filepath).rpartition('.')[0] filepath = dirname(bpy.data.filepath) + '/auto_saves' if not exists(filepath): mkdir(filepath) if scene.auto_save_subfolders: filepath = join(filepath, blendname) if not exists(filepath): mkdir(filepath) #imagefiles starting with the blendname files = [f for f in listdir(filepath) \ if f.startswith(blendname) \ and f.lower().endswith(('.png', '.jpg', '.jpeg', '.exr'))] highest = 0 if files: for f in files: #find last numbers in the filename after the blendname suffix = findall('\d+', f.split(blendname)[-1]) if suffix: if int(suffix[-1]) > highest: highest = int(suffix[-1]) save_name = join(filepath, blendname) + '_' + str(highest + 1).zfill(3) + extension image = bpy.data.images['Render Result'] if not image: print('Auto Save: Render Result not found. Image not saved') return print('Auto_Save:', save_name) image.save_render(save_name, scene=None) if scene.save_blend: save_name_blend = join( filepath, blendname) + '_' + str(highest + 1).zfill(3) + '.blend' print('Blend_Save:', save_name_blend) bpy.ops.wm.save_as_mainfile(filepath=save_name_blend, copy=True) rndr.image_settings.file_format = original_format
def get_filepath(): blendname = basename(bpy.data.filepath).rpartition('.')[0] filepath = dirname(bpy.data.filepath) + SEP +'auto_saves' if not exists(filepath): mkdir(filepath) if bpy.context.scene.auto_save_subfolders: filepath = join(filepath, blendname) if not exists(filepath): mkdir(filepath) return filepath
def get_filepath(): blendname = basename(bpy.data.filepath).rpartition('.')[0] filepath = dirname(bpy.data.filepath) + SEP + 'auto_saves' if not exists(filepath): mkdir(filepath) if bpy.context.scene.auto_save_subfolders: filepath = join(filepath, blendname) if not exists(filepath): mkdir(filepath) return filepath
def auto_save_render(scene): if not scene.save_after_render or not bpy.data.filepath: return rndr = scene.render original_format = rndr.image_settings.file_format format = rndr.image_settings.file_format = scene.auto_save_format if format == 'OPEN_EXR_MULTILAYER': extension = '.exr' if format == 'JPEG': extension = '.jpg' if format == 'PNG': extension = '.png' blendname = basename(bpy.data.filepath).rpartition('.')[0] filepath = dirname(bpy.data.filepath) + '/auto_saves' if not exists(filepath): mkdir(filepath) if scene.auto_save_subfolders: filepath = join(filepath, blendname) if not exists(filepath): mkdir(filepath) #imagefiles starting with the blendname files = [f for f in listdir(filepath) \ if f.startswith(blendname) \ and f.lower().endswith(('.png', '.jpg', '.jpeg', '.exr'))] highest = 0 if files: for f in files: #find last numbers in the filename after the blendname suffix = findall('\d+', f.split(blendname)[-1]) if suffix: if int(suffix[-1]) > highest: highest = int(suffix[-1]) save_name = join(filepath, blendname) + '_' + str(highest+1).zfill(3) + extension image = bpy.data.images['Render Result'] if not image: print('Auto Save: Render Result not found. Image not saved') return print('Auto_Save:', save_name) image.save_render(save_name, scene=None) if scene.save_blend: save_name_blend = join(filepath, blendname) + '_' + str(highest+1).zfill(3) + '.blend' print('Blend_Save:',save_name_blend) bpy.ops.wm.save_as_mainfile(filepath=save_name_blend, copy=True) rndr.image_settings.file_format = original_format
def auto_save_render(scene): if not scene.save_after_render or not bpy.data.filepath: return rndr = scene.render original_format = rndr.image_settings.file_format format = rndr.image_settings.file_format = scene.auto_save_format if format == "OPEN_EXR_MULTILAYER": extension = ".exr" if format == "JPEG": extension = ".jpg" if format == "PNG": extension = ".png" blendname = basename(bpy.data.filepath).rpartition(".")[0] filepath = dirname(bpy.data.filepath) + "/auto_saves" if not exists(filepath): mkdir(filepath) if scene.auto_save_subfolders: filepath = join(filepath, blendname) if not exists(filepath): mkdir(filepath) # imagefiles starting with the blendname files = [ f for f in listdir(filepath) if f.startswith(blendname) and f.lower().endswith((".png", ".jpg", ".jpeg", ".exr")) ] highest = 0 if files: for f in files: # find last numbers in the filename after the blendname suffix = findall("\d+", f.split(blendname)[-1]) if suffix: if int(suffix[-1]) > highest: highest = int(suffix[-1]) save_name = join(filepath, blendname) + "_" + str(highest + 1).zfill(3) + extension image = bpy.data.images["Render Result"] if not image: print("Auto Save: Render Result not found. Image not saved") return print("Auto_Save:", save_name) image.save_render(save_name, scene=None) rndr.image_settings.file_format = original_format
def get_node_slots(inNode, num_slots): # type: (bpy.AllSceneNodeTypes, int) -> list[str] slots = [] # type: list[str] for i in range(num_slots): slot_num = i + 1 image = get_slot_image(inNode, slot_num) if image is None: raise SceneFramesError(f"There is no image for slot #{slot_num}") image_name = basename(image.filepath) if image_name == "": raise SceneFramesError(f"There is no image for slot #{slot_num}") slots.append(image_name) return slots
def CurrentCacheFile(self, obj, mod_name): CacheFile = {"format": None, "name": None, "mod_name": mod_name} mod = obj.modifiers[mod_name] if mod.type == "MESH_SEQUENCE_CACHE": CacheFile["format"] = 'ABC' CacheFile["name"] = mod.cache_file.name elif mod.type == "MESH_CACHE": CacheFile["format"] = mod.cache_format CacheFile["name"] = basename(mod.filepath) return CacheFile
def poll(cls, context): scene = context.scene smurf = scene.smurf tree = context.scene.node_tree tgt_nodes = [] '''Checks if the string to be replaced (B) is contained in any of the images' filepath, and if the potential outcome of switching it to A would point to an existing file. ''' for nodes in tree.nodes: if nodes.type == 'IMAGE': if nodes.image: if smurf.suf2 in bpath.basename(nodes.image.filepath): nodepath = bpath.abspath(nodes.image.filepath).replace(smurf.suf2, smurf.suf1) if opath.isfile(nodepath): tgt_nodes.append(nodes.name) return tgt_nodes
from bpy import data from math import pi import sys argv = sys.argv argv = argv[argv.index("--") + 1:] # get all args after "--" print(app.version_string) blenderVersion = app.version blenderVersionChar = app.version_char blenderBuildBranch = app.build_branch scene = context.scene scene.render.image_settings.file_format = 'PNG' scene.render.image_settings.compression = 25 sceneName = path.basename(context.blend_data.filepath) scene.render.resolution_percentage = 40 meshName = 'gpiow_book00' if meshName == 'gpiow_book01': scene.render.resolution_x = 1080 scene.render.resolution_y = 1920 active_cam = context.scene.camera data.cameras[active_cam.name].lens = 16 data.objects[active_cam.name].rotation_euler[0] = 100 * pi / 180 print('Scene: {}'.format(sceneName)) print('Resolution: {} x {}'.format(scene.render.resolution_x, scene.render.resolution_y))
def get_texture_name(self): if self.image: return basename(self.image.filepath).split('.')[0] return "None"
def auto_save_render(scene): if not scene.save_after_render or not bpy.data.filepath: return rndr = scene.render original_format = rndr.image_settings.file_format format = rndr.image_settings.file_format if format == 'BMP': extension = '.bmp' elif format == 'OPEN_EXR_MULTILAYER': extension = '.exr' elif format == 'JPEG': extension = '.jpg' elif format == 'PNG': extension = '.png' elif format == 'IRIS': extension = '.iris' elif format == 'JPEG2000': extension = '.jpg' elif format == 'TARGA': extension = '.tga' elif format == 'TARGA_RAW': extension = '.tga' elif format == 'CINEON': extension = '.cineon' elif format == 'DPX': extension = '.dpx' elif format == 'OPEN_EXR': extension = '.exr' elif format == 'HDR': extension = '.hdr' elif format == 'TIFF': extension = '.tif' # format = rndr.image_settings.file_format = scene.auto_save_format # if format == 'OPEN_EXR_MULTILAYER': extension = '.exr' # if format == 'JPEG': extension = '.jpg' # if format == 'PNG': extension = '.png' blendname = basename(bpy.data.filepath).rpartition('.')[0] filepath = dirname(bpy.data.filepath) + '/auto_saves' if not exists(filepath): mkdir(filepath) if scene.auto_save_subfolders: filepath = join(filepath, blendname) if not exists(filepath): mkdir(filepath) #imagefiles starting with the blendname files = [f for f in listdir(filepath) \ if f.startswith(blendname) \ and f.lower().endswith(('.png', '.jpg', '.jpeg', '.exr'))] highest = 0 if files: for f in files: #find last numbers in the filename after the blendname suffix = findall('\d+', f.split(blendname)[-1]) if suffix: if int(suffix[0]) > highest: highest = int(suffix[0]) framenum = bpy.context.scene.frame_current save_name = join(filepath, blendname) + '_' + str(highest+1).zfill(3) + "-f" + str(framenum) + extension image = bpy.data.images['Render Result'] if not image: print('Auto Save: Render Result not found. Image not saved') return print('Auto_Save:', save_name) image.save_render(save_name, scene=bpy.context.scene) rndr.image_settings.file_format = original_format
def auto_save_render(scene): render_time = datetime.now() - TIMER if not scene.save_after_render or not bpy.data.filepath: return rndr = scene.render original_format = rndr.image_settings.file_format format = rndr.image_settings.file_format = scene.auto_save_format if format == 'OPEN_EXR_MULTILAYER': extension = '.exr' if format == 'JPEG': extension = '.jpg' if format == 'PNG': extension = '.png' blendname = basename(bpy.data.filepath).rpartition('.')[0] filepath = dirname(bpy.data.filepath) + '/auto_saves' if not exists(filepath): mkdir(filepath) if scene.auto_save_subfolders: filepath = join(filepath, blendname) if not exists(filepath): mkdir(filepath) #imagefiles starting with the blendname files = [f for f in listdir(filepath) \ if f.startswith(blendname) \ and f.lower().endswith(('.png', '.jpg', '.jpeg', '.exr'))] highest = 0 if files: for f in files: #find last numbers in the filename after the blendname suffix = findall('\d+', f.split(blendname)[-1]) if suffix: if int(suffix[-1]) > highest: highest = int(suffix[-1]) save_name = join(filepath, blendname) + '_' + str(highest+1).zfill(3) + extension image = bpy.data.images['Render Result'] if not image: print('Auto Save: Render Result not found. Image not saved') return print('Auto_Save:', save_name) image.save_render(save_name, scene=None) if scene.save_blend: save_name_blend = join(filepath, blendname) + '_' + str(highest+1).zfill(3) + '.blend' print('Blend_Save:',save_name_blend) bpy.ops.wm.save_as_mainfile(filepath=save_name_blend, copy=True) if scene.logfile: md_textname = 'save log' if not md_textname in bpy.data.texts: bpy.data.texts.new(md_textname) bpy.data.texts[md_textname].filepath = join(filepath, blendname + '_log.md') save_name = basename(save_name) link_text = save_name.rpartition('.')[0] text = '\n**{}** '.format(link_text) \ + datetime.now().strftime('{%Y-%m-%d %H:%M} \n') \ + '![]({}) \n'.format(save_name) \ + 'Render time: {} \n'.format(render_time) bpy.data.texts[md_textname].write(text) rndr.image_settings.file_format = original_format
def get_scene_frames(scene): # type: (bpy.types.Scene) -> bpy.SceneInfoType """Go through each frame one by one and find the position and visibility of each sprite""" empty_images = [ o for o in [image_object(o) for o in scene.objects] if (o is not None and not ('font_disable_export' in o and o['font_disable_export'])) ] out = [] # type: "list[bpy.FrameInfo]" highest_slot = 0 # type: int found_slots = set() # type: set[int] for frame in range(scene.frame_start, scene.frame_end + 1, scene.frame_step): # using show_empty_image_orthographic instead of visibility # because visibility makes editing keyframes # very hard. # Edit show_empty_image_orthographic in # Properties > Object Data Properties > Empty > Show in > Orthographic # make sure you set it as a keyframe visible_images = [ o for o in empty_images if image_is_visible(o, frame=frame) ] # a frame can only position a maximum of 64 images # old warning we can have as many images as # we want now # if len(visible_images) > 64: # raise SceneFramesError( # f"Too many images in a frame #{frame}. Maximum is 64 but found {len(visible_images)} images") words = {} # type: dict[int,bpy.SpriteWordInfo] sprites = {} # type: bpy.SpriteList slots = {} # type: bpy.SlotList for empty_image_o in visible_images: x, y = get_location(empty_image_o, frame=frame) if "font_word_id" in empty_image_o: word = empty_image_o["font_word"] if len(word) != 1: word_id = empty_image_o["font_word_id"] if word_id in words: # already handled this word continue parent = empty_image_o.parent if parent is None: raise Exception( f"Word {word} {word_id} does not have a parent, so can't find a location for it.\nObject: {empty_image_o.name}\nScene: {scene.name}" ) word_position = empty_image_o["font_word_position"] x_location = _get_location(parent, frame=frame, accum=(word_position[0], 0)) # TODO This rely's on the assumption that all words are the same y position words[word_id] = {"word": word, "x": x_location[0], "y": y} continue # not really a word because there is only # one char. It's more of a sprite # so let's add it to sprites instead position = { 'x': fea_position(x), 'y': fea_position(y) } # type: bpy.FrameInfoPosition slot_info = get_slot_info(empty_image_o) if slot_info is not None: highest_slot = max(slot_info.number, highest_slot) found_slots.add(slot_info.number) key = f"slot{slot_info.number}" positions = slots.setdefault(str(slot_info.number), []) positions.append(position) continue key = (basename(empty_image_o.data.filepath) if not empty_image_o.name.startswith("MissingDingNo") else missingDingNoSprite()) positions = sprites.setdefault(key, []) positions.append(position) out_words = {} # type: bpy.SpriteList for word_info in words.values(): positions = out_words.setdefault(word_info["word"], []) positions.append({ "x": fea_position(word_info["x"]), "y": fea_position(word_info["y"]) }) out_info = { "sprites": sprites, } # type: bpy.FrameInfoBaked if len(words) > 0: out_info["words"] = out_words if len(slots) > 0: out_info["slots"] = slots out.append(out_info) number_of_slots = len(found_slots) if number_of_slots > 0 and number_of_slots < (highest_slot + 1): raise SceneFramesError( f"Missing slot!. Go to slot number #{highest_slot} but there are only {number_of_slots} used. All found slots: ${found_slots}" ) return {'frames': out, 'slots': number_of_slots}
def auto_save_render(scene): if not scene.auto_save_after_render or not bpy.data.filepath: return rndr = scene.render original_format = rndr.image_settings.file_format if scene.auto_save_format == 'SCENE': if original_format not in IMAGE_FORMATS: print('{} Format is not an image format. Not Saving'.format( original_format)) return elif scene.auto_save_format == 'PNG': rndr.image_settings.file_format = 'PNG' elif scene.auto_save_format == 'OPEN_EXR_MULTILAYER': rndr.image_settings.file_format = 'OPEN_EXR_MULTILAYER' elif scene.auto_save_format == 'JPEG': rndr.image_settings.file_format = 'JPEG' frame_current = bpy.context.scene.frame_current extension = rndr.file_extension blendname = basename(bpy.data.filepath).rpartition('.')[0] filepath = dirname(bpy.data.filepath) + '/auto_saves' if not exists(filepath): mkdir(filepath) if scene.auto_save_subfolders: filepath = join(filepath, blendname) if not exists(filepath): mkdir(filepath) # imagefiles starting with the blendname files = [f for f in listdir(filepath) if f.startswith(blendname) and f.lower().endswith(IMAGE_EXTENSIONS)] def save_number_from_files(files): ''' Returns the new highest count number from file names as 3 digit string. ''' highest = 0 if files: for f in files: # find last numbers in the filename suffix = findall(r'\d+', f.split(blendname)[-1]) if suffix: if int(suffix[-1]) > highest: highest = int(suffix[-1]) return str(highest+1).zfill(3) def this_frame_files(files): ''' Filters out files which have the current frame number in the file name ''' match_files = [] frame_pattern = r'_f[0-9]{4}_' for file in files: res = search(frame_pattern, file) if res: if int(res[0][2:-1]) == frame_current: match_files.append(file) return match_files if scene.auto_save_use_framenumber: if scene.auto_save_use_continuous: save_number = save_number_from_files(files) else: frame_files = this_frame_files(files) save_number = save_number_from_files(frame_files) frame_number = 'f' + str(frame_current).zfill(4) save_name = '_'.join([blendname, frame_number, save_number]) else: save_number = save_number_from_files(files) save_name = '_'.join([blendname, save_number]) save_name += extension save_name = join(filepath, save_name) image = bpy.data.images['Render Result'] if not image: print('Auto Save: Render Result not found. Image not saved') return print('Auto_Save:', save_name) image.save_render(save_name, scene=None) if scene.auto_save_blend: save_name_blend = join(filepath, save_name) + '.blend' print('Blend_Save:', save_name_blend) bpy.ops.wm.save_as_mainfile(filepath=save_name_blend, copy=True) rndr.image_settings.file_format = original_format
def execute(self, context): main(context) # # # # # # # # ################################################################ ################################################################ old_path = bpy.context.scene.render.filepath old_fileformat = bpy.context.scene.render.image_settings.file_format old_extension = bpy.context.scene.render.use_file_extension old_x = bpy.context.scene.render.resolution_x old_y = bpy.context.scene.render.resolution_y old_percentage = bpy.context.scene.render.resolution_percentage old_aspect_x = bpy.context.scene.render.pixel_aspect_x old_aspect_y = bpy.context.scene.render.pixel_aspect_y # # # # # # # # ################################################################ ################################################################ # path to the folder file_path = bpy.data.filepath file_name = bpy.path.display_name_from_filepath(file_path) file_ext = '.blend' file_dir = file_path.replace(file_name + file_ext, '') mainScreen = bpy.context.screen #current scene scene = mainScreen.scene #set render settings scene.render.resolution_x = 128 scene.render.resolution_y = 128 scene.render.resolution_percentage = 100 #render from view (set view_context = False for the camera render) bpy.ops.render.opengl(view_context=True) # # # # # # # # ################################################################ ################################################################ rndr = scene.render original_format = rndr.image_settings.file_format format = rndr.image_settings.file_format = scene.auto_save_format if format == 'OPEN_EXR_MULTILAYER': extension = '.exr' if format == 'JPEG': extension = '.jpg' if format == 'PNG': extension = '.png' blendname = basename(bpy.data.filepath).rpartition('.')[0] # self.filepath_z = str(addon_prefs.filepath_x) # Set path for instant meshes # # if self.filepath_z == "": # print("Path to 'instant Meshes' not specified. Terminating...") # return {'CANCELLED'} # else: # filepath = dirname(bpy.data.filepath) + str(addon_prefs.filepath) #'/auto_saves' # filepath = os.path.basename(context.user_preferences.addons["save_thumbnail"].preferences.filepath_x) addon_preferences = bpy.context.user_preferences.addons[ __name__].preferences filepath = dirname(bpy.data.filepath) + addon_preferences.filepath_x # user_preferences = context.user_preferences # addon_prefs = user_preferences.addons[__name__].preferences # # self.filepath_x = str(addon_prefs.filepath_x) # Set path for instant meshes # # info = ("Path: %s" % (addon_prefs.filepath_x)) # # if self.filepath_x == "": # print("Path to 'instant Meshes' not specified. Terminating...") # return {'CANCELLED'} if not exists(filepath): mkdir(filepath) if scene.auto_save_subfolders: filepath = join(filepath, blendname) if not exists(filepath): mkdir(filepath) # # # # # # # # ################################################################ ################################################################ #imagefiles starting with the blendname files = [f for f in listdir(filepath) \ if f.startswith(blendname) \ and f.lower().endswith(('.png', '.jpg', '.jpeg', '.exr'))] highest = 0 if files: for f in files: #find last numbers in the filename after the blendname suffix = findall('\d+', f.split(blendname)[-1]) if suffix: if int(suffix[-1]) > highest: highest = int(suffix[-1]) ############################################################### ################################################################ # # # # # # # # active_object = bpy.context.active_object name = active_object.name #save and load the render (you can't keep the render result) #save_name = name + ".png" # save_name = join(filepath, blendname) + '_' + str(highest+1).zfill(3) + extension #save_name = scene.name+".png" #改良前 save_name = join(filepath, blendname) + name + ".png" # save_name = join(filepath) + name + ".png" save_name = join(filepath) + name + ".png" image = bpy.data.images['Render Result'] if not image: print('Auto Save: Render Result not found. Image not saved') return print('Auto_Save:', save_name) image.save_render(save_name, scene=None) rndr.image_settings.file_format = original_format # # # # # # # # ################################################################ # restore old settings bpy.context.scene.render.filepath = old_path bpy.context.scene.render.image_settings.file_format = old_fileformat bpy.context.scene.render.use_file_extension = old_extension bpy.context.scene.render.resolution_x = old_x bpy.context.scene.render.resolution_y = old_y bpy.context.scene.render.resolution_percentage = old_percentage bpy.context.scene.render.pixel_aspect_x = old_aspect_x bpy.context.scene.render.pixel_aspect_y = old_aspect_y ################################################################ # # # # # # # # return {'FINISHED'}
def execute(self, context): main(context) # # # # # # # # ################################################################ ################################################################ old_path = bpy.context.scene.render.filepath old_fileformat = bpy.context.scene.render.image_settings.file_format old_extension = bpy.context.scene.render.use_file_extension old_x = bpy.context.scene.render.resolution_x old_y = bpy.context.scene.render.resolution_y old_percentage = bpy.context.scene.render.resolution_percentage old_aspect_x = bpy.context.scene.render.pixel_aspect_x old_aspect_y = bpy.context.scene.render.pixel_aspect_y # # # # # # # # ################################################################ ################################################################ # path to the folder file_path = bpy.data.filepath file_name = bpy.path.display_name_from_filepath(file_path) file_ext = '.blend' file_dir = file_path.replace(file_name+file_ext, '') mainScreen = bpy.context.screen #current scene scene = mainScreen.scene #set render settings scene.render.resolution_x = 128 scene.render.resolution_y = 128 scene.render.resolution_percentage = 100 #render from view (set view_context = False for the camera render) bpy.ops.render.opengl(view_context = True) # # # # # # # # ################################################################ ################################################################ rndr = scene.render original_format = rndr.image_settings.file_format format = rndr.image_settings.file_format = scene.auto_save_format if format == 'OPEN_EXR_MULTILAYER': extension = '.exr' if format == 'JPEG': extension = '.jpg' if format == 'PNG': extension = '.png' blendname = basename(bpy.data.filepath).rpartition('.')[0] # self.filepath_z = str(addon_prefs.filepath_x) # Set path for instant meshes # # if self.filepath_z == "": # print("Path to 'instant Meshes' not specified. Terminating...") # return {'CANCELLED'} # else: # filepath = dirname(bpy.data.filepath) + str(addon_prefs.filepath) #'/auto_saves' # filepath = os.path.basename(context.user_preferences.addons["save_thumbnail"].preferences.filepath_x) addon_preferences = bpy.context.user_preferences.addons[__name__].preferences filepath = dirname(bpy.data.filepath) + addon_preferences.filepath_x # user_preferences = context.user_preferences # addon_prefs = user_preferences.addons[__name__].preferences # # self.filepath_x = str(addon_prefs.filepath_x) # Set path for instant meshes # # info = ("Path: %s" % (addon_prefs.filepath_x)) # # if self.filepath_x == "": # print("Path to 'instant Meshes' not specified. Terminating...") # return {'CANCELLED'} if not exists(filepath): mkdir(filepath) if scene.auto_save_subfolders: filepath = join(filepath, blendname) if not exists(filepath): mkdir(filepath) # # # # # # # # ################################################################ ################################################################ #imagefiles starting with the blendname files = [f for f in listdir(filepath) \ if f.startswith(blendname) \ and f.lower().endswith(('.png', '.jpg', '.jpeg', '.exr'))] highest = 0 if files: for f in files: #find last numbers in the filename after the blendname suffix = findall('\d+', f.split(blendname)[-1]) if suffix: if int(suffix[-1]) > highest: highest = int(suffix[-1]) ############################################################### ################################################################ # # # # # # # # active_object = bpy.context.active_object name = active_object.name #save and load the render (you can't keep the render result) #save_name = name + ".png" # save_name = join(filepath, blendname) + '_' + str(highest+1).zfill(3) + extension #save_name = scene.name+".png" #改良前 save_name = join(filepath, blendname) + name + ".png" # save_name = join(filepath) + name + ".png" save_name = join(filepath) + name + ".png" image = bpy.data.images['Render Result'] if not image: print('Auto Save: Render Result not found. Image not saved') return print('Auto_Save:', save_name) image.save_render(save_name, scene=None) rndr.image_settings.file_format = original_format # # # # # # # # ################################################################ # restore old settings bpy.context.scene.render.filepath = old_path bpy.context.scene.render.image_settings.file_format = old_fileformat bpy.context.scene.render.use_file_extension = old_extension bpy.context.scene.render.resolution_x = old_x bpy.context.scene.render.resolution_y = old_y bpy.context.scene.render.resolution_percentage = old_percentage bpy.context.scene.render.pixel_aspect_x = old_aspect_x bpy.context.scene.render.pixel_aspect_y = old_aspect_y ################################################################ # # # # # # # # return {'FINISHED'}