err StepFile :lndefined Parsing: Line 2:Incorrect symtax: uexpected TYPE, expecting STEP“
Opened this issue · 0 comments
"""
from OCC.Core.STEPControl import STEPControl_Reader
from OCC.Core.IFSelect import IFSelect_RetDone
from OCC.Core.TopoDS import TopoDS_Shell, TopoDS_Solid, topods, TopoDS_Wire, TopoDS_Face
from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopAbs import TopAbs_SHELL, TopAbs_SOLID, TopAbs_WIRE, TopAbs_FACE
from OCC.Core.BRep import BRep_Builder
from OCC.Core.BRepCheck import BRepCheck_Analyzer
from OCC.Core.BRepClass3d import BRepClass3d_SolidClassifier
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeSolid, BRepBuilderAPI_MakeFace
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakePrism, BRepPrimAPI_MakeBox
from OCC.Core.gp import gp_Pnt, gp_Vec, gp_Dir
from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Fuse
from OCC.Core.BRepExtrema import BRepExtrema_DistShapeShape
from OCC.Core.Bnd import Bnd_Box
from OCC.Core.BRepBndLib import brepbndlib
from OCC.Core.GProp import GProp_GProps
from OCC.Core.BRepGProp import brepgprop
import os
import sys
if getattr(sys, 'frozen', False):
base_dir = sys._MEIPASS
os.environ["CSF_StexDefaults"] = os.path.join(base_dir, "OCC", "Data", "step")
def read_stp_file(file_path):
step_reader = STEPControl_Reader()
read_status = step_reader.ReadFile(file_path)
if read_status != IFSelect_RetDone:
print(f"file read fail, status code: {read_status}")
# print(f"error message: {step_reader.ErrorStatus()}")
return None
transfer_success = step_reader.TransferRoots()
root_count = step_reader.NbRootsForTransfer()
print(f"\n=== Transfer Log ===")
print(f"Roots Found: {root_count}")
print(f"Transfer Success: {transfer_success}")
if not transfer_success:
print("warning")
print(f"transmission failed: {step_reader.ErrorStatus()}")
return None
if read_status == IFSelect_RetDone and transfer_success:
print("STP file read success")
return step_reader.OneShape()
print("STP file read fail")
return None
if name == "main":
file_path = "D:/Code/text/pythonProject1/model/Part6.stp"
read_stp_file(file_path)
input('enter finished')
"""
I want to create an application that reads STP files. First, write Python code and run it locally. Then save it as an exe file through pyinstaller-F -- onefile text1.py, and an error occurs when executing the exe file: err StepFile :lndefined Parsing: Line 2:Incorrect symtax: uexpected TYPE, expecting STEP“,read_status = step_reader.ReadFile(file_path) The output is 3. Given that the file path is an absolute path, the first two lines of the STP file are ISO-10303-21;
HEADER;。 Identify the cause of the error and provide a solution.