Add command snippet and import file - From WB project schematic

Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 871
100 Answers 500 Comments 250 Likes First Anniversary
✭✭✭✭
edited June 2023 in Structures

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?

Tagged:

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 871
    100 Answers 500 Comments 250 Likes First Anniversary
    ✭✭✭✭
    Answer ✓

    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)