Another way is to send commands from workbench that work with the native design point update process. You need to use an ACT extension. The XML can look like this:
And the main.py could look like this:
setup_handled = False
def write_my_data(task):
global setup_handled
if not task.Name == “Setup”: return
if setup_handled == True: return # callback is done many times for each task. Need to block all but one attempt
dir = GetUserFilesDirectory()
dir = dir.replace(“\\”,”/”)
cmdprefix = ”’ExtAPI.ExtensionManager.GetExtensionByName(“My Extension”).ScriptScope.”'
# when this function is called automatically during DP updates, through workflow callback, Mechanical will not have an extension loaded.
dp = Parameters.GetActiveDesignPoint()
for system in GetAllSystems():
comp = sys.GetComponent(Name=’Setup’)
cmdMech = cmdprefix + “write_nastran(\”” + dir + “\”,” + dp.Name + “,\”” + comp.DirectoryName + “\”)”
setup = system.GetContainer(ComponentName=”Setup”)
setup.Edit(Interactive=False)
setup.SendCommand(Language=”Python”, Command=cmdMech)
setup.Exit()
setup_handled = True
def dp_after_change():
global setup_handled
setup_handled = False
def write_nastran(dir, dp, solDir):
# executed within Mechanical
import os
for analysis in ExtAPI.DataModel.Project.Model.Analyses:
path = analysis.WorkingDir # solution directory
d = os.path.dirname(path)
d2 = os.path.dirname(d) # need to do dirname() twice since the path ends in a backslash
sysDir = os.path.basename(d2)
if solDir == sysDir:
from Ansys.ACT.Automation.Mechanical import NastranExportOptions
nas = NastranExportOptions()
nas.NastranFilename = dir + “/” + “dp” + str(dp) + “_” + solDir + “.txt”
analysis.ExportNastranFile(nas)
break