简体   繁体   中英

Convert .stl file to .step file using python

I am trying to find a way to convert a .step file to .stl, so any headsup will be a lot helpful. And can anyone tell from where to start? what do i have to look for?

You need a library to tessellate STEP geometry with a chordal error/deviation. Once you have triangles from BRep/Surfaces they can be easily exported in STL file format .

STEP file format could include assembly tree/scene graph as well, this complicates things a little bit.

If you were using the GUI, you'd go to the Part workbench, select your mesh and then use the menu item "Part->Create Shape from Mesh...". This creates the shape but does not make a solid which is probably what you want. So you'd select then new shape, and do "Part->Convert to Solid".

You said you wanted to do this with python so if you look in the python console you'll see that FreeCAD did something like below. That should be enough to get you started.

### Begin command Std_Workbench
Gui.activateWorkbench("MeshWorkbench")
### End command Std_Workbench
### Begin command Std_Workbench
Gui.activateWorkbench("PartWorkbench")
### End command Std_Workbench
### Begin command Part_ShapeFromMesh
import Part
App.getDocument('Drilling_1').addObject('Part::Feature', 'CutMaterial001')
__shape__ = Part.Shape()
__shape__.makeShapeFromMesh(FreeCAD.getDocument('Drilling_1').getObject('CutMaterial').Mesh.Topology, 0.100000, False)
FreeCAD.getDocument('Drilling_1').getObject('CutMaterial001').Shape = __shape__
FreeCAD.getDocument('Drilling_1').getObject('CutMaterial001').purgeTouched()
del __shape__
### End command Part_ShapeFromMesh
Gui.Selection.clearSelection()
Gui.Selection.addSelection('Drilling_1','CutMaterial001')
### Begin command Part_MakeSolid
import Part
__s__=App.ActiveDocument.CutMaterial001.Shape.Faces
__s__=Part.Solid(Part.Shell(__s__))
__o__=App.ActiveDocument.addObject("Part::Feature","CutMaterial001_solid")
__o__.Label="CutMaterial001 (Solid)"
__o__.Shape=__s__
del __s__, __o__
### End command Part_MakeSolid

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM