# import sys
# import json
import FreeCAD
import FreeCADGui
import Part
import Import
import ImportGui
import TechDraw
import TechDrawGui
# import Draft
# import importDXF
# import importSVG
# import importDXF
# import Mesh
# import PartDesign
# 显示FreeCAD界面
# FreeCADGui.showMainWindow()
# doc = FreeCAD.activeDocument()
def import_fcstd(inputfile, outputfile):
doc = FreeCAD.open(inputfile)
# Part.show()
FreeCAD.ActiveDocument.recompute()
# 另存为
# FreeCAD.ActiveDocument.saveAs("D:\\112233.FCStd")
__objs__ = []
objects = doc.Objects
for ob in objects:
# print(ob.Name+','+ob.TypeId)
if ob.Name[:4] == 'Body' or ob.Name[:4] == 'Part':
__objs__.append(ob)
if hasattr(ob, 'Shape'):
ob.Shape.tessellate(0.5)
TechDraw.writeDXFPage(doc.getObject('Page'), outputfile+'.dxf')
# TechDraw.writeDXFPage(FreeCAD.getDocument('_1').getObject('Page'),outputfile+'2.dxf')
TechDrawGui.exportPageAsSvg(doc.getObject('Page'),outputfile+'.svg')
ImportGui.export(__objs__, outputfile+'.glb')
del __objs__
# 在对os进行调取的时候,返回三个参数
# for循环自动完成递归枚举
# 三个参数:分别返回
# 1.父目录(当前路径)parent
# 2.父目录下的所有文件夹名字 dirnames
# 3.父目录下的所有文件名字 filenames
base = 'D:\\testfcconvertall'
base_str = ''
if len(base)==0:
base_str = '.'
else:
base_str = "".join(base)
for parent,dirnames,filenames in os.walk(base_str):
# 很多时候需要忽略一些特定目录
# 忽略 "someenv" and "__pycache__" 目录中
dirnames[:] = [d for d in dirnames if d not in ['someenv','__pycache__']]
# 这里完成了对dirnames的筛选,也就是说在接下来的for循环中,
# someenv和__pycache__将不会被walk
# 然后,选中所有以".md"结尾的文件
filenames[:] = [f for f in filenames if f.endswith('.FCStd')]
for filename in filenames:
#输出找到的文件目录
# print("the full name of the file is :",
# os.path.join(parent,filename))
base_name=os.path.splitext(filename)[0]
import_fcstd(os.path.join(parent,filename),os.path.join(parent,base_name))
# import_fcstd(os.path.join(parent,filename),os.path.join(parent,base_name)+'.glb')
# import_fcstd(os.path.join(parent,filename),os.path.join(parent,base_name)+'.gltf')
# TechDraw.writeDXFPage(FreeCAD.getDocument('_1').getObject('Page'),u'D:/testfcconvertall/Page.dxf')
# FreeCAD.ActiveDocument.recompute()
# doc = FreeCAD.open("D:/testfcconvertall/1.fcstd")
# TechDraw.writeDXFPage(doc.Page, u"D:/testfcconvertall/1.dxf")
# >>> ### Begin command TechDraw_ExportPageDXF
# >>> import TechDraw
# >>> TechDraw.writeDXFPage(App.getDocument('_1').getObject('Page'),u'D:/testfcconvertall/Page.dxf')
# >>> App.ActiveDocument.recompute()
# >>> ### End command TechDraw_ExportPageDXF
# importSVG.export([NewPart], outputfile , nospline=False, lwPoly=False)
# Note that the FreeCADGui module must be active to use this function.
# Gui.runCommand('TechDraw_ExportPageSVG',0)
# Import.export(__objs__, u'D:/Page.glb')
# https://github.com/FreeCAD/FreeCAD/issues/8610,,legacy=True不带颜色!
作者:秦晓川 创建时间:2024-02-08 09:34
最后编辑:秦晓川 更新时间:2024-11-14 14:45
最后编辑:秦晓川 更新时间:2024-11-14 14:45