Got error when importing wires from .STEP and exporting a face with no GUI

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
mnpica
Posts: 1
Joined: Fri Jul 31, 2020 2:45 am

Got error when importing wires from .STEP and exporting a face with no GUI

Post by mnpica »

I'm trying to import wires and BSplines from .STEP file to create a face object and export face object to .STEP file.

Image

If I run script with GUI ,everything is fine.

Trying to run in console with FreeCAD 0.17, Libs: 0.17R13541 (Git),I got "Unknown C++ exception" error.

Code: Select all

  File "E:/workspace/testing/FreeCad/importFace.py", line 24, in export_step
    Draft.makeSketch(activeDoc.getObject(name), addTo=baseSketch)
  File "E:\workspace\testing\FreeCAD-0.17.13541.9948ee4-WIN-x64-portable\Mod\Draft\Draft.py", line 2834, in makeSketch
    nobj.addGeometry(DraftGeomUtils.orientEdge(newedge,norm,make_arc=True))
  File "E:\workspace\testing\FreeCAD-0.17.13541.9948ee4-WIN-x64-portable\Mod\Draft\DraftGeomUtils.py", line 572, in orientEdge
    edge.rotate(base, axis, angle)
Base.FreeCADError: Unknown C++ exception
I found this post https://forum.freecadweb.org/viewtopic.php?t=29436 ,edited DraftGeomUtils.py at line 566.

Code: Select all

    if angle:
        if axis == Vector (0.0, 0.0, 0.0):
            axis = Vector (0.0, 0.0, 1.0)
        edge.rotate(base, axis, angle)
And I got another error "Exception (Fri Jul 31 10:58:13 2020): Wire is not closed. "

If I run script with 0.18 version, there is no Unknown C++ exception but still exception.

Thank you for your time.

Code: Select all

import sys
import os

thisDir= r"E:\workspace\testing"
sys.path.append(os.path.join(thisDir, "FreeCAD-0.17.13541.9948ee4-WIN-x64-portable", "bin"))

import FreeCAD
import Import
import Draft
import Sketcher
import Part


def export_step(stepFilePath, exportStepFilePath):
    App.newDocument("doc")
    Import.insert(stepFilePath, "doc")
    activeDoc=FreeCAD.ActiveDocument
    names = [obj.Name for obj in activeDoc.Objects]
    baseSketch=activeDoc.addObject('Sketcher::SketchObject', 'SketchCombine')
    for name in names:
        Draft.makeSketch(activeDoc.getObject(name), addTo=baseSketch)
    activeDoc.recompute()
    activeDoc.addObject("Part::Face", "Face").Sources = (baseSketch,)
    activeDoc.recompute()
    __objs__ = []
    __objs__.append(activeDoc.getObject("Face"))
    Import.export(__objs__, exportStepFilePath)

    # del __objs__
    # FreeCAD.closeDocument(activeDoc.Name)
    print("Done. File has been export to {}".format(exportStepFilePath))

if __name__=='__main__':

    stepFilePath = r"E:/workspace/testing/test.step"
    exportStepFilePath = stepFilePath[:-5] + '-face.step'
    export_step(stepFilePath, exportStepFilePath)
Attachments
test.step
(193.79 KiB) Downloaded 15 times
Post Reply