A post already exists about adding a command snippet in the Mechanical tree and importing a specific text file in this command snippet:
With ACT, how can I add a command snippet in the Mechanical tree and import a specific text file in this command snippet?
How can the same be achieved but from the project page?
The following code can be adapted:
import os model1 = system1.GetContainer(ComponentName="Model") # system1 refers to the first analysis component system installDir = ExtAPI.ExtensionManager.GetExtensionByName("MyExtension").InstallDir commandFile = os.path.join(installDir,'MyCommandSnippet.txt') commandFileString = "r\'" + str(commandFile) + "\' " mechScriptCmds=""" analysis = ExtAPI.DataModel.Project.Model.Analyses[0] snippet = analysis.AddCommandSnippet() snippet.ImportTextFile(%s) """ % (commandFileString) model1.SendCommand(Language="Python", Command=mechScriptCmds)