@@ -84,7 +84,6 @@ def convert_script(
84
84
cleanup_output = True ,
85
85
header = True ,
86
86
print_com = True ,
87
- only_commands = False ,
88
87
):
89
88
"""Converts an ANSYS input file to a python PyMAPDL script.
90
89
@@ -145,12 +144,6 @@ def convert_script(
145
144
Print command ``/COM`` arguments to python console.
146
145
Defaults to ``True``.
147
146
148
- only_commands : bool, optional
149
- If ``True``, it converts only the commands, meaning that header
150
- (``header=False``), imports (``add_imports=False``),
151
- and exit commands are NOT included (``auto_exit=False``).
152
- Overrides ``header``, ``add_imports`` and ``auto_exit``.
153
-
154
147
Returns
155
148
-------
156
149
list
@@ -197,7 +190,6 @@ def convert_script(
197
190
cleanup_output = cleanup_output ,
198
191
header = header ,
199
192
print_com = print_com ,
200
- only_commands = only_commands ,
201
193
)
202
194
203
195
translator .save (filename_out )
@@ -218,7 +210,6 @@ def convert_apdl_block(
218
210
cleanup_output = True ,
219
211
header = True ,
220
212
print_com = True ,
221
- only_commands = False ,
222
213
):
223
214
"""Converts an ANSYS input string to a python PyMAPDL string.
224
215
@@ -282,12 +273,6 @@ def convert_apdl_block(
282
273
Print command ``/COM`` arguments to python console.
283
274
Defaults to ``True``.
284
275
285
- only_commands : bool, optional
286
- If ``True``, it converts only the commands, meaning that header
287
- (``header=False``), imports (``add_imports=False``),
288
- and exit commands are NOT included (``auto_exit=False``).
289
- Overrides ``header``, ``add_imports`` and ``auto_exit``.
290
-
291
276
Returns
292
277
-------
293
278
list
@@ -323,7 +308,6 @@ def convert_apdl_block(
323
308
cleanup_output = cleanup_output ,
324
309
header = header ,
325
310
print_com = print_com ,
326
- only_commands = only_commands ,
327
311
)
328
312
329
313
if isinstance (apdl_strings , str ):
@@ -345,14 +329,8 @@ def _convert(
345
329
cleanup_output = True ,
346
330
header = True ,
347
331
print_com = True ,
348
- only_commands = False ,
349
332
):
350
333
351
- if only_commands :
352
- auto_exit = False
353
- add_imports = False
354
- header = False
355
-
356
334
translator = FileTranslator (
357
335
loglevel ,
358
336
line_ending ,
@@ -608,40 +586,36 @@ def translate_line(self, line):
608
586
# Cleaning ending empty arguments.
609
587
# Because of an extra comma added to toffst command when generating ds.dat.
610
588
line_ = line .split ("," )[::- 1 ] # inverting order
611
-
612
589
for ind , each in enumerate (line_ ):
613
- if each . strip (): # strip to remove spaces in empty arguments
590
+ if each :
614
591
break
615
-
616
- line = "," .join (line_ [ind :][::- 1 ])
592
+ else :
593
+ line_ .pop (ind )
594
+ line = "," .join (line_ [::- 1 ])
617
595
618
596
# remove trailing comma
619
597
line = line [:- 1 ] if line [- 1 ] == "," else line
620
- line_upper = line .upper ()
621
598
622
- cmd_caps = line .split ("," )[0 ].upper ()
623
- cmd_caps_short = cmd_caps [:4 ]
599
+ cmd_ = line .split ("," )[0 ].upper ()
624
600
625
- items = line .split ("," )
626
-
627
- if cmd_caps_short in ["SOLV" , "LSSO" ] and self ._comment_solve :
601
+ if cmd_ [:4 ] in ["SOLV" , "LSSO" ] and self ._comment_solve :
628
602
self .store_command (
629
603
"com" , ["The following line has been commented due to `comment_solve`:" ]
630
604
)
631
605
self .store_command ("com" , [line ])
632
606
return
633
607
634
- if cmd_caps_short == "/COM" :
608
+ if cmd_ [: 4 ] == "/COM" :
635
609
# It is a comment
636
610
self .store_command ("com" , [line [5 :]])
637
611
return
638
612
639
- if cmd_caps == "*DO" :
613
+ if cmd_ == "*DO" :
640
614
self .start_non_interactive ()
641
615
self .store_run_command (line )
642
616
return
643
617
644
- if cmd_caps in ["*ENDDO" , "*ENDIF" ]:
618
+ if cmd_ in ["*ENDDO" , "*ENDIF" ]:
645
619
self .store_run_command (line )
646
620
self .end_non_interactive ()
647
621
return
@@ -657,13 +631,13 @@ def translate_line(self, line):
657
631
self .end_non_interactive ()
658
632
return
659
633
660
- if cmd_caps == "/VERIFY" :
634
+ if cmd_ == "/VERIFY" :
661
635
self .store_run_command ("FINISH" )
662
636
self .store_run_command (line )
663
637
self .store_run_command ("/PREP7" )
664
638
return
665
639
666
- if cmd_caps_short == "*REP" :
640
+ if line [: 4 ]. upper () == "*REP" :
667
641
if not self .non_interactive :
668
642
prev_cmd = self .lines .pop (- 1 )
669
643
self .start_non_interactive ()
@@ -677,40 +651,33 @@ def translate_line(self, line):
677
651
self .end_non_interactive ()
678
652
return
679
653
680
- if cmd_caps_short in COMMANDS_TO_NOT_BE_CONVERTED :
654
+ if line [: 4 ]. upper () in COMMANDS_TO_NOT_BE_CONVERTED :
681
655
self .store_run_command (line )
682
656
return
683
657
684
- if cmd_caps_short == "/TIT" : # /TITLE
658
+ if line [: 4 ]. upper () == "/TIT" : # /TITLE
685
659
parameters = line .split ("," )[1 :]
686
660
return self .store_command ("title" , ["" .join (parameters ).strip ()])
687
661
688
- if cmd_caps_short == "*GET" :
662
+ if line [: 4 ]. upper () == "*GET" :
689
663
if self .non_interactive : # gives error
690
664
self .store_run_command (line )
691
665
return
692
666
else :
693
667
parameters = line .split ("," )[1 :]
694
668
return self .store_command ("get" , parameters )
695
669
696
- if cmd_caps_short == "/NOP" :
670
+ if line [: 4 ]. upper () == "/NOP" :
697
671
self .comment = (
698
672
"It is not recommended to use '/NOPR' in a normal PyMAPDL session."
699
673
)
700
674
self .store_under_scored_run_command (line )
701
675
return
702
676
703
- if cmd_caps_short == "*CRE" : # creating a function
704
- if self .macros_as_functions :
705
- self .start_function (items [1 ].strip ())
706
- return
707
- else :
708
- self .start_non_interactive ()
709
-
710
- if cmd_caps == "/PREP7" :
677
+ if line [:6 ].upper () == "/PREP7" :
711
678
return self .store_command ("prep7" , [])
712
679
713
- if "*END" in line_upper :
680
+ if "*END" in line :
714
681
if self .macros_as_functions :
715
682
self .store_empty_line ()
716
683
self .store_empty_line ()
@@ -726,7 +693,7 @@ def translate_line(self, line):
726
693
return
727
694
728
695
# check for if statement
729
- if cmd_caps [:3 ] == "*IF" or "*IF" in line_upper :
696
+ if line [:3 ]. upper () == "*IF" or "*IF" in line . upper () :
730
697
self .start_non_interactive ()
731
698
self .store_run_command (line )
732
699
return
@@ -745,14 +712,16 @@ def translate_line(self, line):
745
712
): # To escape cmds that require (XX) but they are not in block
746
713
self .end_non_interactive ()
747
714
return
748
- elif cmd_caps_short == "*USE" and self .macros_as_functions :
715
+ elif line [:4 ] == "*USE" and self .macros_as_functions :
716
+ items = line .split ("," )
749
717
func_name = items [1 ].strip ()
750
718
if func_name in self ._functions :
751
719
args = ", " .join (items [2 :])
752
720
self .lines .append (f"{ func_name } ({ args } )" )
753
721
return
754
722
755
723
# check if a line is setting a variable
724
+ items = line .split ("," )
756
725
if "=" in items [0 ]: # line sets a variable:
757
726
self .store_run_command (line )
758
727
return
@@ -763,67 +732,54 @@ def translate_line(self, line):
763
732
self .store_empty_line ()
764
733
return
765
734
766
- if line == "-1" or line_upper == "END PREAD" : # End of block commands
735
+ if line == "-1" or line == "END PREAD" : # End of block commands
767
736
self .store_run_command (line )
768
737
self ._in_block = False
769
738
self .end_non_interactive ()
770
739
return
771
740
772
741
# check valid command
773
- if (
774
- self ._pymapdl_command (command ) not in self ._valid_commands
775
- or cmd_caps_short in self ._non_interactive_commands
776
- ):
777
- if cmd_caps_short in self ._non_interactive_commands :
778
- if cmd_caps_short in self ._block_commands :
742
+ if command not in self ._valid_commands :
743
+ cmd = line [:4 ].upper ()
744
+ if cmd == "*CRE" : # creating a function
745
+ if self .macros_as_functions :
746
+ self .start_function (items [1 ].strip ())
747
+ return
748
+ else :
749
+ self .start_non_interactive ()
750
+
751
+ elif cmd in self ._non_interactive_commands :
752
+ if cmd in self ._block_commands :
779
753
self ._in_block = True
780
754
self ._block_count = 0
781
755
self ._block_count_target = 0
782
756
783
- elif cmd_caps_short in self ._enum_block_commands :
757
+ elif cmd in self ._enum_block_commands :
784
758
self ._in_block = True
785
759
self ._block_count = 0
786
- if cmd_caps_short == "CMBL" : # In cmblock
760
+ if cmd == "CMBL" : # In cmblock
787
761
# CMBLOCK,Cname,Entity,NUMITEMS,,,,,KOPT
788
762
numitems = int (line .split ("," )[3 ])
789
763
_block_count_target = (
790
764
numitems // 8 + 1 if numitems % 8 != 0 else numitems // 8
791
765
)
792
766
self ._block_count_target = (
793
767
_block_count_target + 2
794
- ) # because the cmd_caps_short line and option line.
768
+ ) # because the cmd line and option line.
795
769
796
- self ._block_current_cmd = cmd_caps_short
770
+ self ._block_current_cmd = cmd
797
771
self .start_non_interactive ()
798
772
799
- if self ._in_block and cmd_caps_short not in self ._non_interactive_commands :
773
+ if self ._in_block and cmd not in self ._non_interactive_commands :
800
774
self .store_run_command (original_line )
801
775
else :
802
776
self .store_run_command (line )
803
777
804
778
elif self .use_function_names :
805
- if command [0 ] == "/" :
806
- slash_command = f"slash{ command [1 :]} "
807
- if slash_command in dir (Commands ):
808
- command = slash_command
809
- else :
810
- command = command [1 :]
811
- elif command [0 ] == "*" :
812
- star_command = f"star{ command [1 :]} "
813
- if star_command in dir (Commands ):
814
- command = star_command
815
- else :
816
- command = command [1 :]
817
-
818
779
self .store_command (command , parameters )
819
780
else :
820
781
self .store_run_command (line )
821
782
822
- def _pymapdl_command (self , command ):
823
- if command [0 ] in ["/" , "*" ]:
824
- command = command [1 :]
825
- return command
826
-
827
783
def start_function (self , func_name ):
828
784
self ._functions .append (func_name )
829
785
self .store_empty_line ()
0 commit comments