Skip to content

Instantly share code, notes, and snippets.

@eelstork
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eelstork/37713b7ad3437b5a8380 to your computer and use it in GitHub Desktop.
Save eelstork/37713b7ad3437b5a8380 to your computer and use it in GitHub Desktop.
Export a copy of the current file to the OUTPUT folder; only the specified LAYERS are exported. The current file will be saved before exporting.
# =============================================================
# Copyright TEA DE SOUZA 2014. Free to use and
# modify, do not remove this notice.
# =============================================================
#
# Export a copy of the current file to the OUTPUT folder.
# Only the specified LAYERS are exported.
# The current file will be saved before exporting.
#
# =============================================================
LAYERS = [0,1,2,3,4,5,6,7,8,9]
OUTPUT = "/Volumes/Aka/uni-x/village/Assets/models/terrain/"
# =============================================================
import bpy
def export():
showAllLayers()
for k in bpy.context.scene.objects:
k.select = not isExportable(k)
bpy.ops.object.delete()
path = OUTPUT+filename()
if path==bpy.data.filepath:
print("WARNING: cannot overwrite source file")
print("WARNING: please change output directory")
else:
print("Saving to "+path)
bpy.ops.wm.save_as_mainfile(filepath=path,copy=True,compress=True)
def isExportable(object):
for i in LAYERS:
if object.layers[i]: return True
return False
def filename():
p = bpy.data.filepath
return p[p.rfind("/")+1:]
def showAllLayers():
sel = []
for i in range(0,20): sel.append(True)
bpy.context.scene.layers = sel
# ===============================================================
# MAIN SECTION
# ===============================================================
print("EXPORT SELECTED LAYERS")
bpy.ops.wm.save_as_mainfile(compress=True)
export()
bpy.ops.wm.revert_mainfile()
print("EXPORT COMPLETE")
# EOF ===========================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment