Add command snippet and import file - From WB project schematic
Pernelle Marone-Hitz
Member, Moderator, Employee Posts: 871
✭✭✭✭
A post already exists about adding a command snippet in the Mechanical tree and importing a specific text file in this command snippet:
How can the same be achieved but from the project page?
Tagged:
0
Answers
-
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)
1