mjmiddle
Ansys Employee

 

 

 

Within Mechcanical you can do:

analysis = ExtAPI.DataModel.Project.Model.Analyses[0]    # 1st analysis
from Ansys.ACT.Automation.Mechanical import NastranExportOptions
nas = NastranExportOptions()
nas.NastranFilename = r"D:\Myfile.nas"
analysis.ExportNastranFile(nas)

If you have multiple analyses in the same Mechanical session, then use a python loop instead of using the first index.

If you have multiple unlinked systems in the workbench project schematic, you’ll need to loop through them and send commands to Mechanical:

loop = 1
for system in GetAllSystems():
    cmdMech = '''
analysis = ExtAPI.DataModel.Project.Model.Analyses[0]    # 1st analysis
from Ansys.ACT.Automation.Mechanical import NastranExportOptions
nas = NastranExportOptions()
nas.NastranFilename = r"D:\\Myfile''' + str(loop) + '''.nas"
analysis.ExportNastranFile(nas)
'''
    setup = system.GetContainer(ComponentName="Setup")
    setup.Edit(Interactive=False)    # set Interactive=True for debugging
    setup.SendCommand(Language="Python", Command=cmdMech)
    setup.Exit()
    loop += 1