freecad嵌入工作台

1 Introduction导言

FreeCAD can be imported as a Python module in other programs or in a standalone Python console, together with all its modules and components. It’s even possible to import the FreeCAD user interface as a python module but with some restrictions indicated in Caveats.
导言
FreeCAD可以作为导入Python其他程序或独立的Python控制台中的模块及其所有模块和组件。甚至可以将FreeCAD用户界面作为python模块导入,但有一些限制警告。

2 Using FreeCAD without GUI

The first, direct, easy, and useful application you can make of this is to import FreeCAD documents into your program. In the following example, we’ll import the Part geometry of a FreeCAD document into blender. Here is the complete script. I hope you’ll be impressed by its simplicity:
在没有GUI的情况下使用FreeCAD
您可以使用的第一个直接,简单且有用的应用程序是将FreeCAD文档导入到您的程序中。在下面的示例中,我们将FreeCAD文档的零件几何导入到搅拌机。这里是完整的脚本。我希望你会对它的简单性印象深刻:

FREECADPATH = '/usr/lib/freecad-python3/lib/' # path to your FreeCAD.so or FreeCAD.pyd file,
# for Windows you must either use \\ or / in the path, using a single \ is problematic
# FREECADPATH = 'C:\\FreeCAD\\bin'
import Blender, sys
sys.path.append(FREECADPATH)
 
def import_fcstd(filename):
   try:
       import FreeCAD
   except ValueError:
       Blender.Draw.PupMenu('Error%t|FreeCAD library not found. Please check the FREECADPATH variable in the import script is correct')
   else:
       scene = Blender.Scene.GetCurrent()
       import Part
       doc = FreeCAD.open(filename)
       objects = doc.Objects
       for ob in objects:
           if ob.Type[:4] == 'Part':
               shape = ob.Shape
               if shape.Faces:
                   mesh = Blender.Mesh.New()
                   rawdata = shape.tessellate(1)
                   for v in rawdata[0]:
                       mesh.verts.append((v.x,v.y,v.z))
                

你可能感兴趣的:(软件开发,建模,python)