tpaviot / pythonocc-core

Python package for 3D geometry CAD/BIM/CAM
GNU Lesser General Public License v3.0
1.39k stars 380 forks source link

how to read a step file and convert it to stl file? #788

Closed BoshraKrout closed 4 years ago

BoshraKrout commented 4 years ago

i've been trying this code to read a step file and convert it to stl file but it's crashing at print('here1')

from OCC.Core.STEPControl import STEPControl_Reader
from OCC.Core.StlAPI import StlAPI_Writer

input_file  = 'ap242.stp'   # input STEP (AP203/AP214 file)

print('here')
step_reader = STEPControl_Reader()
step_reader.ReadFile( input_file )
print('here1')
step_reader.TransferRoot(1)
print('here2')
myshape = step_reader.Shape()
print("File readed")

stl_writer = StlAPI_Writer()
stl_writer.SetASCIIMode(True)
stl_writer.Write(myshape, 'ap242.stl')
print("Written")`
tpaviot commented 4 years ago

can u please upload the step file as well

BoshraKrout commented 4 years ago

ap242.zip

tpaviot commented 4 years ago

it seems your STEP file can't be read:

from OCC.Core.STEPControl import STEPControl_Reader

input_file  = 'ap242.stp' 

step_reader = STEPControl_Reader()
status = step_reader.ReadFile(input_file)

# status should be either
# IFSelect_RetVoid = 0,
# IFSelect_RetDone = 1
# IFSelect_RetError = 2
# IFSelect_RetFail = 3
# IFSelect_RetStop = 4
print(status)

It outputs 3, that is to say IFSelect_RetFail. It comes either from the STEP file itself (no compliant with the standard) or from the OCCT kernel and this should be reported upstream.

tpaviot commented 4 years ago

In both cases, it does not come from the python wrapper, I close the issue please report any feedback anyway

BoshraKrout commented 4 years ago

the issue was from the STEP file it self, it worked when i changed it. thanx