Open
Description
Describe the bug
A bug occurs using the Windows OS in the function write_stl_file
from the pythonocc library. At the moment no issues related with this bug are opened in the Github page of pythonocc-core library. Additionally, the same method write_stl_file
is also used in Propeller.generate_stl
with no errors in this case.
To Reproduce
pytest tests/test_propeller
Output
================================== FAILURES ===================================
_______________ TestPropeller.test_generate_obj_blades_and_stem _______________
self = <tests.test_propeller.TestPropeller testMethod=test_generate_obj_blades_and_stem>
def test_generate_obj_blades_and_stem(self):
sh = Shaft("tests/test_datasets/shaft.iges")
prop = create_sample_blade_NACApptc()
prop = Propeller(sh, prop, 4)
> prop.generate_obj("tests/test_datasets/propeller_and_shaft.obj", region_selector='blades_and_stem')
tests\test_propeller.py:192:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
bladex\propeller.py:105: in generate_obj
write_stl_file(self.shaft_solid, "/tmp/temp_shaft.stl")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
a_shape = <class 'TopoDS_Solid'>, filename = '/tmp/temp_shaft.stl'
mode = 'ascii', linear_deflection = 0.9, angular_deflection = 0.5
def write_stl_file(a_shape, filename, mode="ascii", linear_deflection=0.9, angular_deflection=0.5):
""" export the shape to a STL file
Be careful, the shape first need to be explicitely meshed using BRepMesh_IncrementalMesh
a_shape: the topods_shape to export
filename: the filename
mode: optional, "ascii" by default. Can either be "binary"
linear_deflection: optional, default to 0.001. Lower, more occurate mesh
angular_deflection: optional, default to 0.5. Lower, more accurate_mesh
"""
if a_shape.IsNull():
raise AssertionError("Shape is null.")
if mode not in ["ascii", "binary"]:
raise AssertionError("mode should be either ascii or binary")
if os.path.isfile(filename):
print("Warning: %s file already exists and will be replaced" % filename)
# first mesh the shape
mesh = BRepMesh_IncrementalMesh(a_shape, linear_deflection, False, angular_deflection, True)
#mesh.SetDeflection(0.05)
mesh.Perform()
if not mesh.IsDone():
raise AssertionError("Mesh is not done.")
stl_exporter = StlAPI_Writer()
if mode == "ascii":
stl_exporter.SetASCIIMode(True)
else: # binary, just set the ASCII flag to False
stl_exporter.SetASCIIMode(False)
stl_exporter.Write(a_shape, filename)
if not os.path.isfile(filename):
> raise IOError("File not written to disk.")
E OSError: File not written to disk.
C:\Miniconda\envs\__setup_conda\lib\site-packages\OCC\Extend\DataExchange.py:353: OSError
__________________ TestPropeller.test_generate_obj_by_coords __________________
self = <tests.test_propeller.TestPropeller testMethod=test_generate_obj_by_coords>
def test_generate_obj_by_coords(self):
sh = Shaft("tests/test_datasets/shaft.iges")
prop = create_sample_blade_NACApptc()
prop = Propeller(sh, prop, 4)
> prop.generate_obj("tests/test_datasets/propeller_and_shaft.obj", region_selector='by_coords')
tests\test_propeller.py:163:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
bladex\propeller.py:[105](https://github.com/mathLab/BladeX/actions/runs/3046074863/jobs/4908427376#step:7:106): in generate_obj
write_stl_file(self.shaft_solid, "/tmp/temp_shaft.stl")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
a_shape = <class 'TopoDS_Solid'>, filename = '/tmp/temp_shaft.stl'
mode = 'ascii', linear_deflection = 0.9, angular_deflection = 0.5
def write_stl_file(a_shape, filename, mode="ascii", linear_deflection=0.9, angular_deflection=0.5):
""" export the shape to a STL file
Be careful, the shape first need to be explicitely meshed using BRepMesh_IncrementalMesh
a_shape: the topods_shape to export
filename: the filename
mode: optional, "ascii" by default. Can either be "binary"
linear_deflection: optional, default to 0.001. Lower, more occurate mesh
angular_deflection: optional, default to 0.5. Lower, more accurate_mesh
"""
if a_shape.IsNull():
raise AssertionError("Shape is null.")
if mode not in ["ascii", "binary"]:
raise AssertionError("mode should be either ascii or binary")
if os.path.isfile(filename):
print("Warning: %s file already exists and will be replaced" % filename)
# first mesh the shape
mesh = BRepMesh_IncrementalMesh(a_shape, linear_deflection, False, angular_deflection, True)
#mesh.SetDeflection(0.05)
mesh.Perform()
if not mesh.IsDone():
raise AssertionError("Mesh is not done.")
stl_exporter = StlAPI_Writer()
if mode == "ascii":
stl_exporter.SetASCIIMode(True)
else: # binary, just set the ASCII flag to False
stl_exporter.SetASCIIMode(False)
stl_exporter.Write(a_shape, filename)
if not os.path.isfile(filename):
> raise IOError("File not written to disk.")
E OSError: File not written to disk.
C:\Miniconda\envs\__setup_conda\lib\site-packages\OCC\Extend\DataExchange.py:353: OSError
Additional context
No errors using MacOS or Linux.