Add command snippet and import file - From WB project schematic
Options
![Pernelle Marone-Hitz](https://us.v-cdn.net/6037473/uploads/userpics/4AG2SAGAOHUA/nTB4DQJCWAJV4.jpg)
Pernelle Marone-Hitz
Member, Moderator, Employee Posts: 831
![Ansys Employee](https://us.v-cdn.net/6037473/uploads/badges/RVRDV39KPJ91.png)
![Solution Developer Community of Practice Member](https://us.v-cdn.net/6037473/uploads/badges/274G8C56SBE6.png)
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