29
29
from google .protobuf .empty_pb2 import Empty
30
30
import numpy as np
31
31
from pint import Quantity , UndefinedUnitError
32
+ import semver
32
33
33
34
from ansys .api .dbu .v0 .dbumodels_pb2 import EntityIdentifier , PartExportFormat
34
- from ansys .api .dbu .v0 .designs_pb2 import InsertRequest , NewRequest , SaveAsRequest
35
+ from ansys .api .dbu .v0 .designs_pb2 import (
36
+ DownloadExportFileRequest ,
37
+ InsertRequest ,
38
+ NewRequest ,
39
+ SaveAsRequest ,
40
+ )
35
41
from ansys .api .dbu .v0 .designs_pb2_grpc import DesignsStub
36
42
from ansys .api .dbu .v0 .drivingdimensions_pb2 import GetAllRequest , UpdateRequest
37
43
from ansys .api .dbu .v0 .drivingdimensions_pb2_grpc import DrivingDimensionsStub
84
90
class DesignFileFormat (Enum ):
85
91
"""Provides supported file formats that can be downloaded for designs."""
86
92
87
- SCDOCX = "SCDOCX" , None
93
+ SCDOCX = "SCDOCX" , PartExportFormat . PARTEXPORTFORMAT_SCDOCX
88
94
PARASOLID_TEXT = "PARASOLID_TEXT" , PartExportFormat .PARTEXPORTFORMAT_PARASOLID_TEXT
89
95
PARASOLID_BIN = "PARASOLID_BIN" , PartExportFormat .PARTEXPORTFORMAT_PARASOLID_BINARY
90
96
FMD = "FMD" , PartExportFormat .PARTEXPORTFORMAT_FMD
91
97
STEP = "STEP" , PartExportFormat .PARTEXPORTFORMAT_STEP
92
98
IGES = "IGES" , PartExportFormat .PARTEXPORTFORMAT_IGES
93
99
PMDB = "PMDB" , PartExportFormat .PARTEXPORTFORMAT_PMDB
100
+ STRIDE = "STRIDE" , PartExportFormat .PARTEXPORTFORMAT_STRIDE
101
+ DISCO = "DISCO" , PartExportFormat .PARTEXPORTFORMAT_DISCO
94
102
INVALID = "INVALID" , None
95
103
96
104
@@ -294,6 +302,44 @@ def download(
294
302
# Create the parent directory
295
303
file_location .parent .mkdir (parents = True , exist_ok = True )
296
304
305
+ # Process response
306
+ self ._grpc_client .log .debug (f"Requesting design download in { format .value [0 ]} format." )
307
+ if self ._modeler .client .backend_version < semver .Version (25 , 2 , 0 ):
308
+ received_bytes = self .__export_and_download_legacy (format = format )
309
+ else :
310
+ received_bytes = self .__export_and_download (format = format )
311
+
312
+ # Write to file
313
+ downloaded_file = Path (file_location ).open (mode = "wb" )
314
+ downloaded_file .write (received_bytes )
315
+ downloaded_file .close ()
316
+
317
+ self ._grpc_client .log .debug (
318
+ f"Design is successfully downloaded at location { file_location } ."
319
+ )
320
+
321
+ @protect_grpc
322
+ @check_input_types
323
+ @ensure_design_is_active
324
+ def __export_and_download_legacy (
325
+ self ,
326
+ format : DesignFileFormat = DesignFileFormat .SCDOCX ,
327
+ ) -> bytes :
328
+ """Export and download the design from the server.
329
+
330
+ This is a legacy method, which used in versions
331
+ up to Ansys 25.1.1 products.
332
+
333
+ Parameters
334
+ ----------
335
+ format : DesignFileFormat, default: DesignFileFormat.SCDOCX
336
+ Format for the file to save to.
337
+
338
+ Returns
339
+ -------
340
+ bytes
341
+ The raw data from the exported and downloaded file.
342
+ """
297
343
# Process response
298
344
self ._grpc_client .log .debug (f"Requesting design download in { format .value [0 ]} format." )
299
345
received_bytes = bytes ()
@@ -316,14 +362,53 @@ def download(
316
362
)
317
363
return
318
364
319
- # Write to file
320
- downloaded_file = Path (file_location ).open (mode = "wb" )
321
- downloaded_file .write (received_bytes )
322
- downloaded_file .close ()
365
+ return received_bytes
323
366
324
- self ._grpc_client .log .debug (
325
- f"Design is successfully downloaded at location { file_location } ."
326
- )
367
+ @protect_grpc
368
+ @check_input_types
369
+ @ensure_design_is_active
370
+ def __export_and_download (
371
+ self ,
372
+ format : DesignFileFormat = DesignFileFormat .SCDOCX ,
373
+ ) -> bytes :
374
+ """Export and download the design from the server.
375
+
376
+ Parameters
377
+ ----------
378
+ format : DesignFileFormat, default: DesignFileFormat.SCDOCX
379
+ Format for the file to save to.
380
+
381
+ Returns
382
+ -------
383
+ bytes
384
+ The raw data from the exported and downloaded file.
385
+ """
386
+ # Process response
387
+ self ._grpc_client .log .debug (f"Requesting design download in { format .value [0 ]} format." )
388
+ received_bytes = bytes ()
389
+
390
+ if format in [
391
+ DesignFileFormat .PARASOLID_TEXT ,
392
+ DesignFileFormat .PARASOLID_BIN ,
393
+ DesignFileFormat .FMD ,
394
+ DesignFileFormat .STEP ,
395
+ DesignFileFormat .IGES ,
396
+ DesignFileFormat .PMDB ,
397
+ DesignFileFormat .DISCO ,
398
+ DesignFileFormat .SCDOCX ,
399
+ DesignFileFormat .STRIDE ,
400
+ ]:
401
+ response = self ._design_stub .DownloadExportFile (
402
+ DownloadExportFileRequest (format = format .value [1 ])
403
+ )
404
+ received_bytes += response .data
405
+ else :
406
+ self ._grpc_client .log .warning (
407
+ f"{ format .value [0 ]} format requested is not supported. Ignoring download request."
408
+ )
409
+ return
410
+
411
+ return received_bytes
327
412
328
413
def __build_export_file_location (self , location : Path | str | None , ext : str ) -> Path :
329
414
"""Build the file location for export functions.
@@ -366,6 +451,52 @@ def export_to_scdocx(self, location: Path | str | None = None) -> Path:
366
451
# Return the file location
367
452
return file_location
368
453
454
+ def export_to_disco (self , location : Path | str | None = None ) -> Path :
455
+ """Export the design to an dsco file.
456
+
457
+ Parameters
458
+ ----------
459
+ location : ~pathlib.Path | str, optional
460
+ Location on disk to save the file to. If None, the file will be saved
461
+ in the current working directory.
462
+
463
+ Returns
464
+ -------
465
+ ~pathlib.Path
466
+ The path to the saved file.
467
+ """
468
+ # Define the file location
469
+ file_location = self .__build_export_file_location (location , "dsco" )
470
+
471
+ # Export the design to an dsco file
472
+ self .download (file_location , DesignFileFormat .DISCO )
473
+
474
+ # Return the file location
475
+ return file_location
476
+
477
+ def export_to_stride (self , location : Path | str | None = None ) -> Path :
478
+ """Export the design to an stride file.
479
+
480
+ Parameters
481
+ ----------
482
+ location : ~pathlib.Path | str, optional
483
+ Location on disk to save the file to. If None, the file will be saved
484
+ in the current working directory.
485
+
486
+ Returns
487
+ -------
488
+ ~pathlib.Path
489
+ The path to the saved file.
490
+ """
491
+ # Define the file location
492
+ file_location = self .__build_export_file_location (location , "stride" )
493
+
494
+ # Export the design to an stride file
495
+ self .download (file_location , DesignFileFormat .STRIDE )
496
+
497
+ # Return the file location
498
+ return file_location
499
+
369
500
def export_to_parasolid_text (self , location : Path | str | None = None ) -> Path :
370
501
"""Export the design to a Parasolid text file.
371
502
@@ -381,7 +512,11 @@ def export_to_parasolid_text(self, location: Path | str | None = None) -> Path:
381
512
The path to the saved file.
382
513
"""
383
514
# Determine the extension based on the backend type
384
- ext = "x_t" if self ._grpc_client .backend_type == BackendType .LINUX_SERVICE else "xmt_txt"
515
+ ext = (
516
+ "x_t"
517
+ if self ._grpc_client .backend_type in (BackendType .LINUX_SERVICE , BackendType .CORE_LINUX )
518
+ else "xmt_txt"
519
+ )
385
520
386
521
# Define the file location
387
522
file_location = self .__build_export_file_location (location , ext )
@@ -407,7 +542,11 @@ def export_to_parasolid_bin(self, location: Path | str | None = None) -> Path:
407
542
The path to the saved file.
408
543
"""
409
544
# Determine the extension based on the backend type
410
- ext = "x_b" if self ._grpc_client .backend_type == BackendType .LINUX_SERVICE else "xmt_bin"
545
+ ext = (
546
+ "x_b"
547
+ if self ._grpc_client .backend_type in (BackendType .LINUX_SERVICE , BackendType .CORE_LINUX )
548
+ else "xmt_bin"
549
+ )
411
550
412
551
# Define the file location
413
552
file_location = self .__build_export_file_location (location , ext )
0 commit comments