################################################################################# # # Put this script and all files used as library # to :poserscripts:LuxExporter # or change the pathnames used (don't forget to chdir to your path). # # Start this script to export a whole scene from Poser. # ################################################################################# import os, sys, time try: import poser scene = poser.Scene() except: poser = None scene = None __version__ = "0.1e" ###ODF >>> Some introspection magic from BB to find out which folder we live in def findMyFolder(): # return the folder containing this script import sys from os.path import dirname p = dirname(findMyFolder.func_code.co_filename) return p myFolder= findMyFolder() outFolder = os.path.join(myFolder, 'toLux') if not os.path.isdir(outFolder): os.mkdir(outFolder) ###ODF <<< ################################################################################# # globalParameters is primarily filled up with things we cannot request # from Poser, or to overwrite Poser parameters. # Each exporter has its own section to avoid overlapping parameter names. # The complete dictionary is given as parameter to each exporter class. # Because we use a Python shelve as dictionary all changes are directly written # to disk (writeback=True). So no "sync" is required (may be changed for speed # reasons if the dictionary grows bigger than expected now). import shelve ###ODF >>> Read the configuration from the folder the script is in confPath = os.path.join(myFolder, "LuxExporterParameters.conf") globalParameters = shelve.open(confPath, protocol=None, writeback=True) ###ODF <<< if len(globalParameters) == 0 : globalParameters["Film"] = dict() globalParameters["Scene"] = dict() globalParameters["Materials"] = dict() globalParameters["Figure"] = dict() globalParameters["Actor"] = dict() globalParameters["Light"] = dict() globalParameters["camera"] = dict() ################################################################################# # set global parameters here until we have a user-interface ###ODF >>> D'uh! if not globalParameters.has_key("Geom"): globalParameters["Geom"] = dict() ###ODF <<< globalParameters["Geom"]["forceTriangles"] = False # use quads, not triangles # hardcoded outputpath for Lux files # change to reflect your environment ###ODF >>> Better use script folder for default (see below) #globalParameters["Film"]["luxpath"] = r"C:\Programme\LuxRender" # path to Lux #globalParameters["Film"]["outputpath"] = r"Z:\LuxFiles\Poser" # path to Lux content ###ODF <<< ################################################################################# if __name__ == "__main__" : import traceback try: # Do some preparation for the globals here until we have a user-interface. globalparm = globalParameters.get("Film", dict()) ###ODF >>> if no program path is given, use the one we determined programpath = globalparm.get("programpath", myFolder) ###ODF <<< if programpath is None : # If no other path is set we use directory "LuxExporter" # in the common Poser python directory as work-path. # Make sure all additional libs for this exporter are located here. programpath = globalparm["programpath"] = \ os.path.join(os.path.dirname(poser.AppLocation()), "Runtime", "Python", "poserscripts", "LuxExporter") ###ODF >>> use a subfolder of the one the script lives in as default outputpath = globalparm.get("outputpath", outFolder) ###ODF <<< if outputpath is None : # If no other path is set we use directory "LuxExporter/out" # in the common Poser python directory as path for anything this Exporter outputs. # The "Film" part and files to be included can be found here outputpath = globalparm["programpath"] = \ os.path.join(os.path.dirname(poser.AppLocation()), "Runtime", "Python", "poserscripts", "LuxExporter", "out") if not os.path.exists(programpath) : os.makedirs(programpath) # make sure library import works os.chdir(programpath) # I have to add another directory where my sourcecode resides # os.chdir(r"Z:\poserpython\POSER\luxrender") # create outputpath if needed if not os.path.exists(outputpath) : os.makedirs(outputpath) # grab the already defined filename for outputfiles pr create one filename = globalparm.get("filename", None) if filename is None : globalparm["filename"] = filename = "poserscene_%s" % __version__ # if no image resolution is defined yet, set one according to Poser if globalparm.get("resolution", None) is None: globalparm["resolution"] = scene.OutputRes() # the two standard included files if globalparm.get("includes", None) is None: globalparm["includes"] = filename + ".lxm", filename + ".lxo" sys.path.append(programpath) # Here are the required imports to do something. # Change the name to the library you want to try out. try: import LuxPoserExporter_worker_01e reload(LuxPoserExporter_worker_01e) from LuxPoserExporter_worker_01e import ExportFilm, \ ExportScene, \ ExportMaterials, \ __version__ as __geomversion__ except ImportError,err: raise Exception, "Make sure all files from the package are installed into the same directory.\n%s" % err print "Version %s (geom-exporter: %s), exporting Lux files to\n" % (__version__, __geomversion__), os.path.join(os.path.abspath(".")) t = time.time() f = open(os.path.join(outputpath, filename + ".lxs"), "w") ExportFilm(globalParameters).write(f) f.close() ###ODF >>> Code moved. See below! ###ODF <<< f = open(os.path.join(outputpath, filename + ".lxo"), "w") ExportScene(scene, globalParameters).write(f) f.close() ###ODF >>> Preloading of materials does not seem to work; this does f = open(os.path.join(outputpath, filename + ".lxm"), "w") ExportMaterials().write(f) f.close() ###ODF <<< except Exception, err: # catch errors reported from a library traceback.print_exc(file=sys.stdout) # make sure files are closed and not left unusable try: globalParameters.close() except: pass try: close(f) except: pass else: globalParameters.close() print "Time used: %0.2f seconds" % (time.time() - t)