How to create custom buttons on WB Project page?

Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 454
100 Answers 250 Likes 100 Comments Second Anniversary
✭✭✭✭
edited December 2022 in General Language Questions

I want to create a set a of analysis systems on the WB project page and connect them automatically. Ideally I require a custom button on the WB project page, which when clicked calls a function where I can define my workflow.

Tagged:

Answers

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 454
    100 Answers 250 Likes 100 Comments Second Anniversary
    ✭✭✭✭
    Answer ✓

    You can create an ACT extension by using the following XML and Python code. This code will create a button on the WB project page which when clicked adds a static structural analysis system. The user can code a complex workflow within the callback.

    enter image description here

    XML:

    <extension version="1" name="CustomButtonWB" icon="images\tab.png">  
      <script src="main.py" />
      <interface context="Project">
        <images>images</images>
        <toolbar name="CustomButtonWB" caption="CustomButtonWB">
          <entry name="Custom Button WB" caption="Custom Button WB" icon="ansys">
            <callbacks>
              <onclick>add_static_structural</onclick>
            </callbacks>
          </entry>
        </toolbar>
      </interface>
    </extension>
    

    Python:

    def add_static_structural(entity):
        ExtAPI.Log.WriteMessage("Button clicked...")
        template1 = GetTemplate(TemplateName="Static Structural", Solver="ANSYS")
        system1 = template1.CreateSystem()
    
  • M
    M Member, Employee Posts: 239
    50 Answers 100 Comments 100 Likes Second Anniversary
    ✭✭✭✭
    Answer ✓

    Being lazy, I adapted Ayush's solution to clean out my WB so if I have a lot of systems I don't have to click through and clear generated results for each.

    XML:

    <extension version="1" name="wbCleaner" icon="images\tab.png">  
      <script src="main.py" />
      <interface context="Project">
        <images>images</images>
        <toolbar name="wbCleaner" caption="wbCleaner">
          <entry name="WB Cleaner" caption="WB Cleaner" icon="shiva">
            <callbacks>
              <onclick>cleanWB</onclick>
            </callbacks>
          </entry>
        </toolbar>
      </interface>
    </extension>
    

    py

    def cleanWB(entity):
        ExtAPI.Log.WriteMessage("Cleaning up your Workbench Schematic, please wait...")
        for system in GetAllSystems():
            try:
                modelComponent1 = system.GetComponent(Name="Model")
                ExtAPI.Log.WriteMessage("Cleaning up " + system.Name.ToString())
                modelComponent1.Clean()
            except: # some systems can not be updated, geometry for example
                pass