def load(filename, **options): """Load a file. This function loads the given file without deleting the scene, so the contents of the file is appended to the current scene. To be able to load the file there must be an appropriate import class (protocol: "Import") available in the plugin manager. The class is determined by examining the file extension. If no importer is found a NoImporter exception is thrown. Any exception generated in the importer is passed to the caller. \param filename (\c str) File name \param options Options that are passed to the import plugin """ # Extract the extension (without '.') and make it lower case ext = os.path.splitext(filename)[1][1:].lower() # Find the appropriate import plugin class by comparing the extension for objdesc in pluginmanager.iterProtoObjects("Import"): if ext in objdesc.object.extension(): break else: raise NoImporter('No import plugin found for extension "%s".' % ext) if not os.path.exists(filename): raise IOError('File "%s" does not exist.' % filename) # Change into the directory of the given file oldpath = os.getcwd() dir = os.path.dirname(os.path.abspath(filename)) os.chdir(dir) # Import the file imp = objdesc.object() try: imp.importFile(os.path.basename(filename), **options) except: os.chdir(oldpath) raise # Change back to the previous directory os.chdir(oldpath)
def load(filename, **options): """Load a file. This function loads the given file without deleting the scene, so the contents of the file is appended to the current scene. To be able to load the file there must be an appropriate import class (protocol: "Import") available in the plugin manager. The class is determined by examining the file extension. If no importer is found a NoImporter exception is thrown. Any exception generated in the importer is passed to the caller. \param filename (\c str) File name \param options Options that are passed to the import plugin """ # Extract the extension (without '.') and make it lower case ext = os.path.splitext(filename)[1][1:].lower() # Find the appropriate import plugin class by comparing the extension for objdesc in pluginmanager.iterProtoObjects("Import"): if ext in objdesc.object.extension(): break else: raise NoImporter('No import plugin found for extension "%s".'%ext) if not os.path.exists(filename): raise IOError('File "%s" does not exist.'%filename) # Change into the directory of the given file oldpath = os.getcwd() dir = os.path.dirname(os.path.abspath(filename)) os.chdir(dir) # Import the file imp = objdesc.object() try: imp.importFile(os.path.basename(filename), **options) except: os.chdir(oldpath) raise # Change back to the previous directory os.chdir(oldpath)
def save(filename, **options): """Save the scene to a file. This function saves the current scene. To be able to save the scene there must be an appropriate export class (protocol: "Export") available in the plugin manager. The class is determined by examining the file extension. If no exporter is found a NoExporter exception is thrown. Any exception generated in the exporter is passed to the caller. \param filename (\c str) File name \param options Options that are passed to the export plugin """ # Extract the extension (without '.') and make it lower case ext = os.path.splitext(filename)[1][1:].lower() # Find the appropriate export plugin class by comparing the extension for objdesc in pluginmanager.iterProtoObjects("Export"): if ext in objdesc.object.extension(): break else: raise NoExporter('No export plugin found for extension "%s".' % ext) # Change into the directory of the given file oldpath = os.getcwd() dir = os.path.dirname(os.path.abspath(filename)) os.chdir(dir) # Export the file exp = objdesc.object() exp.exportFile(os.path.basename(filename), **options) # Change back to the previous directory os.chdir(oldpath)
def save(filename, **options): """Save the scene to a file. This function saves the current scene. To be able to save the scene there must be an appropriate export class (protocol: "Export") available in the plugin manager. The class is determined by examining the file extension. If no exporter is found a NoExporter exception is thrown. Any exception generated in the exporter is passed to the caller. \param filename (\c str) File name \param options Options that are passed to the export plugin """ # Extract the extension (without '.') and make it lower case ext = os.path.splitext(filename)[1][1:].lower() # Find the appropriate export plugin class by comparing the extension for objdesc in pluginmanager.iterProtoObjects("Export"): if ext in objdesc.object.extension(): break else: raise NoExporter('No export plugin found for extension "%s".'%ext) # Change into the directory of the given file oldpath = os.getcwd() dir = os.path.dirname(os.path.abspath(filename)) os.chdir(dir) # Export the file exp = objdesc.object() exp.exportFile(os.path.basename(filename), **options) # Change back to the previous directory os.chdir(oldpath)