def execute(self, context): roots = ioUtils.getExportModels() if not roots: log("No properly defined models selected or present in scene.", 'ERROR') return {'CANCELLED'} elif not self.exportall: roots = [ root for root in roots if root['modelname'] == self.modelname ] if len(roots) > 1: log( "Ambiguous model definitions: " + self.modelname + " exists " + str(len(roots)) + " times.", "ERROR") return {'CANCELLED'} for root in roots: # setup paths exportpath = ioUtils.getExportPath() if not securepath(exportpath): log("Could not secure path to export to.", "ERROR") continue log("Export path: " + exportpath, "DEBUG") ioUtils.exportModel(models.deriveModelDictionary(root), exportpath) # select all exported models after export is done if ioUtils.getExpSettings().selectedOnly: for root in roots: objectlist = sUtils.getChildren(root, selected_only=True, include_hidden=False) sUtils.selectObjects(objectlist, clear=False) else: bpy.ops.object.select_all(action='DESELECT') for root in roots: sUtils.selectObjects(list([root]), False) bpy.ops.phobos.select_model() # report success to user log("Export successful.", "INFO") return {'FINISHED'}
def execute(self, context): """ Args: context: Returns: """ roots = ioUtils.getExportModels() if not roots: log("No properly defined models selected or present in scene.", 'ERROR') return {'CANCELLED'} elif not self.exportall: roots = [ root for root in roots if nUtils.getModelName(root) == self.modelname ] if len(roots) > 1: log( "Ambiguous model definitions: " + self.modelname + " exists " + str(len(roots)) + " times.", "ERROR", ) return {'CANCELLED'} for root in roots: # setup paths exportpath = ioUtils.getExportPath() if not securepath(exportpath): log("Could not secure path to export to.", "ERROR") continue log("Export path: " + exportpath, "DEBUG") ioUtils.exportModel(models.deriveModelDictionary(root), exportpath) # select all exported models after export is done if ioUtils.getExpSettings().selectedOnly: for root in roots: objectlist = sUtils.getChildren(root, selected_only=True, include_hidden=False) sUtils.selectObjects(objectlist, clear=False) else: bpy.ops.object.select_all(action='DESELECT') for root in roots: sUtils.selectObjects(list([root]), False) bpy.ops.phobos.select_model() # TODO: Move mesh export to individual formats? This is practically SMURF # export meshes in selected formats # for meshtype in meshes.mesh_types: # mesh_path = ioUtils.getOutputMeshpath(meshtype) # try: # typename = "export_mesh_" + meshtype # if getattr(bpy.data.worlds[0], typename): # securepath(mesh_path) # for meshname in model['meshes']: # meshes.mesh_types[meshtype]['export'](model['meshes'][meshname], mesh_path) # except KeyError: # log("No export function available for selected mesh function: " + meshtype, # "ERROR", "ExportModelOperator") # print(sys.exc_info()[0]) # TODO: Move texture export to individual formats? This is practically SMURF # export textures # if ioUtils.textureExportEnabled(): # texture_path = '' # for materialname in model['materials']: # mat = model['materials'][materialname] # for texturetype in ['diffuseTexture', 'normalTexture', 'displacementTexture']: # if texturetype in mat: # texpath = os.path.join(os.path.expanduser(bpy.path.abspath('//')), mat[texturetype]) # if os.path.isfile(texpath): # if texture_path == '': # texture_path = securepath(os.path.join(export_path, 'textures')) # log("Exporting textures to " + texture_path, "INFO", "ExportModelOperator") # try: # shutil.copy(texpath, os.path.join(texture_path, os.path.basename(mat[texturetype]))) # except shutil.SameFileError: # log("{} already in place".format(texturetype), "INFO", "ExportModelOperator") # report success to user log("Export successful.", "INFO", end="\n\n") return {'FINISHED'}
def execute(self, context): """ Args: context: Returns: """ roots = ioUtils.getExportModels() if not roots: log("No properly defined models selected or present in scene.", 'ERROR') return {'CANCELLED'} elif not self.exportall: roots = [root for root in roots if nUtils.getModelName(root) == self.modelname] if len(roots) > 1: log( "Ambiguous model definitions: " + self.modelname + " exists " + str(len(roots)) + " times.", "ERROR", ) return {'CANCELLED'} for root in roots: # setup paths exportpath = ioUtils.getExportPath() if not securepath(exportpath): log("Could not secure path to export to.", "ERROR") continue log("Export path: " + exportpath, "DEBUG") ioUtils.exportModel(models.deriveModelDictionary(root), exportpath) # select all exported models after export is done if ioUtils.getExpSettings().selectedOnly: for root in roots: objectlist = sUtils.getChildren(root, selected_only=True, include_hidden=False) sUtils.selectObjects(objectlist, clear=False) else: bpy.ops.object.select_all(action='DESELECT') for root in roots: sUtils.selectObjects(list([root]), False) bpy.ops.phobos.select_model() # TODO: Move mesh export to individual formats? This is practically SMURF # export meshes in selected formats # for meshtype in meshes.mesh_types: # mesh_path = ioUtils.getOutputMeshpath(meshtype) # try: # typename = "export_mesh_" + meshtype # if getattr(bpy.data.worlds[0], typename): # securepath(mesh_path) # for meshname in model['meshes']: # meshes.mesh_types[meshtype]['export'](model['meshes'][meshname], mesh_path) # except KeyError: # log("No export function available for selected mesh function: " + meshtype, # "ERROR", "ExportModelOperator") # print(sys.exc_info()[0]) # TODO: Move texture export to individual formats? This is practically SMURF # export textures # if ioUtils.textureExportEnabled(): # texture_path = '' # for materialname in model['materials']: # mat = model['materials'][materialname] # for texturetype in ['diffuseTexture', 'normalTexture', 'displacementTexture']: # if texturetype in mat: # texpath = os.path.join(os.path.expanduser(bpy.path.abspath('//')), mat[texturetype]) # if os.path.isfile(texpath): # if texture_path == '': # texture_path = securepath(os.path.join(export_path, 'textures')) # log("Exporting textures to " + texture_path, "INFO", "ExportModelOperator") # try: # shutil.copy(texpath, os.path.join(texture_path, os.path.basename(mat[texturetype]))) # except shutil.SameFileError: # log("{} already in place".format(texturetype), "INFO", "ExportModelOperator") # report success to user log("Export successful.", "INFO", end="\n\n") return {'FINISHED'}