From d1dd3e5a2b9567c6acb3ee19a88457110a6f4a3f Mon Sep 17 00:00:00 2001 From: Stan Seibert Date: Sat, 8 Oct 2011 16:22:45 -0400 Subject: Add a helper module to the chroma.models directory that takes inventory of all the .stl/.stl.bz2 files present and creates building functions for each of them in the models module. This allows usage like the following: chroma-cam chroma.models.lionsolid chroma-cam chroma.models.tie_interceptor6 You don't need to worry about where the chroma package was actually installed. Loading from STL files listed on the command line still works, of course. --- chroma/models/__init__.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 chroma/models/__init__.py diff --git a/chroma/models/__init__.py b/chroma/models/__init__.py new file mode 100644 index 0000000..4b19f94 --- /dev/null +++ b/chroma/models/__init__.py @@ -0,0 +1,20 @@ +import os.path +import glob +import sys + +from chroma.stl import mesh_from_stl + +class Loader(object): + def __init__(self, filename): + self.filename = filename + def __call__(self): + return mesh_from_stl(self.filename) + +# Create functions to load +this_module = sys.modules[__name__] +for filename in glob.glob(os.path.join(os.path.dirname(__file__),'*.stl*')): + name, ext = os.path.splitext(os.path.basename(filename)) + while ext != '': + name, ext = os.path.splitext(name) + setattr(this_module, name, Loader(filename)) + -- cgit