Last active
November 30, 2015 11:41
-
-
Save uozias/4fb095a9e849fbda80b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: UTF-8 | |
import os | |
import re | |
import Part | |
import Mesh | |
# | |
# ファイル名を読み込む | |
# | |
target_dir = u'/Users/xxx/Desktop/igs' | |
save_dir = u'/Users/xxx/Desktop/stl' | |
files = os.listdir(target_dir) | |
try: | |
os.stat(save_dir) | |
except: | |
os.mkdir(save_dir) | |
# | |
# 変換処理 | |
# | |
for file in files: | |
file_base_name = re.match("(.*)\.(.+)",file).group(1) # 拡張子なしの名前 | |
if len(file_base_name) > 0: | |
# 新規ドキュメント | |
App.newDocument("doc1") | |
App.setActiveDocument("doc1") | |
App.ActiveDocument=App.getDocument("doc1") | |
Gui.ActiveDocument=Gui.getDocument("doc1") | |
Gui.ActiveDocument.ActiveView.setAnimationEnabled(False) | |
obj_base_name = file_base_name.replace("-","_") # ハイフンをアンダーバーにしたやつ | |
Part.insert(target_dir + '/'+file ,"doc1") | |
Gui.SendMsgToActiveView("ViewFit") | |
__objs__=[] | |
for item in FreeCAD.getDocument("doc1").Objects: | |
__objs__.append(item) | |
Mesh.export(__objs__, save_dir + '/' + file_base_name + '.stl') | |
del __objs__ | |
for item in FreeCAD.getDocument("doc1").Objects: | |
App.getDocument("doc1").removeObject(item.Name) | |
# ドキュメント閉じる | |
App.closeDocument("doc1") | |
App.setActiveDocument("") | |
App.ActiveDocument=None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment