Skip to content

Instantly share code, notes, and snippets.

@lab1092
Created March 17, 2015 16:31
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 lab1092/b1b732e3a92fe1ce8e14 to your computer and use it in GitHub Desktop.
Save lab1092/b1b732e3a92fe1ce8e14 to your computer and use it in GitHub Desktop.
OBJファイルを自動的にインポートした状態でBlenderを開く、の続き
c:\blender\blender.exe -P C:\Users\username\desktop\testconv.py -b -- %1
on main(input)
try
do shell script "/Applications/Blender274RC1/blender.app/Contents/MacOS/blender -P ~/Desktop/testconv.py -b --" & space & input
end try
end main
on open argv
repeat with aFile in argv
main(quoted form of POSIX path of aFile)
end repeat
end open
on run
main(quoted form of POSIX path of (choose file))
end run
import bpy
import sys
import os
def delete_all():
for item in bpy.context.scene.objects:
bpy.context.scene.objects.unlink(item)
for item in bpy.data.objects:
bpy.data.objects.remove(item)
for item in bpy.data.meshes:
bpy.data.meshes.remove(item)
for item in bpy.data.materials:
bpy.data.materials.remove(item)
def convert_file(filepath):
basename = filename = fileext = ext = outpath =''
dirname = os.path.dirname(filepath)
basename = os.path.basename(filepath)
(filename,fileext) = os.path.splitext(basename)
ext = fileext.lower()
if os.path.isfile(filepath):
# .obj -> .fbx
if ext =='.obj':
bpy.ops.import_scene.obj(filepath=filepath)
outpath = os.path.join(dirname,filename+".fbx")
bpy.ops.export_scene.fbx(filepath=outpath)
else:
None
if __name__ == "__main__":
delete_all()
convert_file(filepath=sys.argv[-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment