Skip to content

Commit c997976

Browse files
author
plu
committed
use _find_correct_result rather than using .path
1 parent acaec43 commit c997976

File tree

1 file changed

+56
-23
lines changed

1 file changed

+56
-23
lines changed

src/ansys/speos/core/workflow/open_result.py

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,17 @@ def open_result_in_viewer(
167167
dpf_instance.OpenFile(file_path)
168168
dpf_instance.Show(1)
169169

170-
def export_xmp_vtp(file_path: Union[str, Path]) -> Path:
170+
def export_xmp_vtp(
171+
simulation_feature: Union[SimulationDirect, SimulationInverse],
172+
result_name: Union[str, Path],
173+
) -> Path:
171174
"""Export an XMP result into vtp file.
172175
173176
Parameters
174177
----------
175-
file_path: Union[str, Path]
178+
simulation_feature : ansys.speos.core.simulation.Simulation
179+
The simulation feature.
180+
result_name: Union[str, Path]
176181
file path of an XMP result.
177182
178183
Returns
@@ -183,8 +188,19 @@ def export_xmp_vtp(file_path: Union[str, Path]) -> Path:
183188
"""
184189
import pyvista as pv
185190

186-
if not str(file_path).lower().endswith("xmp"):
187-
raise ValueError("Please specify a .xmp file.")
191+
result_name = Path(result_name)
192+
if not str(result_name).lower().endswith(".xmp"):
193+
result_name = result_name.with_name(result_name.name + ".xmp")
194+
file_path = _find_correct_result(simulation_feature, str(result_name))
195+
196+
if file_path == "":
197+
raise ValueError(
198+
"No result corresponding to "
199+
+ str(result_name)
200+
+ " is found in "
201+
+ simulation_feature._name
202+
)
203+
188204
file_path = Path(file_path)
189205
dpf_instance = CreateObject("XMPViewer.Application")
190206
dpf_instance.OpenFile(str(file_path))
@@ -247,14 +263,20 @@ def export_xmp_vtp(file_path: Union[str, Path]) -> Path:
247263
vtp_meshes.save(str(file_path.with_suffix(".vtp")))
248264
return file_path.with_suffix(".vtp")
249265

250-
def export_xm3_vtp(geo_faces: List[face_pb2.Face], file_path: Union[str, Path]) -> Path:
266+
def export_xm3_vtp(
267+
simulation_feature: Union[SimulationDirect, SimulationInverse],
268+
geo_faces: List[face_pb2.Face],
269+
result_name: Union[str, Path],
270+
) -> Path:
251271
"""Export an XMP result into vtp file.
252272
253273
Parameters
254274
----------
275+
simulation_feature : ansys.speos.core.simulation.Simulation
276+
The simulation feature.
255277
geo_faces: List[face_pb2.Face]
256278
list of face geometries.
257-
file_path: Union[str, Path]
279+
result_name: Union[str, Path]
258280
file path of an XMP result.
259281
260282
Returns
@@ -265,8 +287,18 @@ def export_xm3_vtp(geo_faces: List[face_pb2.Face], file_path: Union[str, Path])
265287
"""
266288
import pyvista as pv
267289

268-
if not str(file_path).lower().endswith("xm3"):
269-
raise ValueError("Please specify a .xm3 file.")
290+
result_name = Path(result_name)
291+
if not str(result_name).lower().endswith(".xm3"):
292+
result_name = result_name.with_name(result_name.name + ".xm3")
293+
file_path = _find_correct_result(simulation_feature, str(result_name))
294+
295+
if file_path == "":
296+
raise ValueError(
297+
"No result corresponding to "
298+
+ str(result_name)
299+
+ " is found in "
300+
+ simulation_feature._name
301+
)
270302

271303
file_path = Path(file_path)
272304
dpf_instance = CreateObject("Xm3Viewer.Application")
@@ -278,6 +310,22 @@ def export_xm3_vtp(geo_faces: List[face_pb2.Face], file_path: Union[str, Path])
278310
xm3_data = []
279311
content = file.readlines()
280312
header = content[0].strip().split("\t")
313+
illuminance_indices = [
314+
i for i, header_item in enumerate(header) if header_item == "Illuminance"
315+
]
316+
irradiance_indices = [
317+
i for i, header_item in enumerate(header) if header_item == "Irradiance"
318+
]
319+
reflection_indices = [
320+
i for i, header_item in enumerate(header) if "Reflection" in header_item
321+
]
322+
transmission_indices = [
323+
i for i, header_item in enumerate(header) if "Transmission" in header_item
324+
]
325+
absorption_indices = [
326+
i for i, header_item in enumerate(header) if "Absorption" in header_item
327+
]
328+
281329
skip_line = 1
282330
try:
283331
float(float(content[1].strip().split()[0]))
@@ -286,21 +334,6 @@ def export_xm3_vtp(geo_faces: List[face_pb2.Face], file_path: Union[str, Path])
286334
skip_line = 2 # separated layer
287335
for line in content[skip_line:]:
288336
line_content = line.strip().split("\t")
289-
illuminance_indices = [
290-
i for i, header_item in enumerate(header) if header_item == "Illuminance"
291-
]
292-
irradiance_indices = [
293-
i for i, header_item in enumerate(header) if header_item == "Irradiance"
294-
]
295-
reflection_indices = [
296-
i for i, header_item in enumerate(header) if "Reflection" in header_item
297-
]
298-
transmission_indices = [
299-
i for i, header_item in enumerate(header) if "Transmission" in header_item
300-
]
301-
absorption_indices = [
302-
i for i, header_item in enumerate(header) if "Absorption" in header_item
303-
]
304337
xm3_data.append(
305338
_Speos3dData(
306339
x=float(line_content[0]),

0 commit comments

Comments
 (0)