How to rename a Static Structural Analysis in WB based on its name in the Mechanical?

Dominique_Cracovia
Dominique_Cracovia Member Posts: 2
Name Dropper First Comment
**

Let's say I have three analyses connected together sharing the same model. In Ansys Mechanical I changed manually the names to "Static A" "Static B" and "Static C".

How to automatically update these names in Workbench to not have the usual "Copy of Copy of Copy"? Is it possible to connect Workbench and Mechanical with some scripting?

Thanks!
Best Regards,
Dominique

Answers

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 291
    25 Answers 100 Comments 25 Likes First Anniversary
    ✭✭✭✭
    edited July 9

    I wrote a blog on this topic here. Here is the relevant portion:

    If we want to make modifications to the Project Page, we need to interact with the Project Page on a separate thread from Mechanical. Here is an example to change the name of a system in the Project Page from within Mechanical:

    import System
    from System.Threading import *
    
    def RunWBJN(cmds):
      def Internal_RunWBJN():
        import wbjn
        wbjn.ExecuteCommand(ExtAPI,cmds)
      thread = System.Threading.Thread(System.Threading.ThreadStart(Internal_RunWBJN))
      thread.Start()
    
    project_cmds = '''
    system1 = GetAllSystems()[0]
    system1.DisplayText = "my name"
    '''
    
    RunWBJN(project_cmds)
    
  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 871
    100 Answers 500 Comments 250 Likes First Anniversary
    ✭✭✭✭
    edited July 10

    In addition to the commands shared by @Landon Mitchell Kanner , here's how in Mechanical you can loop on all the analyses and rename them:

    for i,analysis in enumerate (ExtAPI.DataModel.Project.Model.Analyses):
        analysis.Name = "My renamed analysis number " + str(i) 
    
  • Dominique_Cracovia
    Dominique_Cracovia Member Posts: 2
    Name Dropper First Comment
    **
    edited July 10

    Thank you @Landon Mitchell Kanner. It partially solved my issue meaning I can match now "Results File Directory" with my "Static A" analysis. Thanks a lot!

    However I have a situation where my 'System ID' and my 'Results ID' / 'Directory Name' don't match and I cannot access 'SYSTEM ID' of a Static Structural Object from the Mechanical.

    I couldn't find anything simple like "ExtAPI.DataModel.AnalysisList[0].[GET_SYSTEM_ID]" or GetSystem("search by Results ID 'SYS-84'")

    I guess I'll have to reverse my approach and send the data from WB to Mechanical instead.

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 291
    25 Answers 100 Comments 25 Likes First Anniversary
    ✭✭✭✭
    edited July 10

    Here is one workaround, but it assumes that analysis blocks have unique display names:

    def GetProjectSystemID(sysname):
        import wbjn
        global cmdStat
        cmds = """
    
    def GetSystemNameByDisplayText(SchematicName):
        AllSys=GetAllSystems()
        for sys in AllSys:
            if sys.DisplayText==SchematicName:
                return sys.Name
        return None
    
    name = GetSystemNameByDisplayText("%s")
    returnValue(name)
        """%(sysname)
        cmdStat=wbjn.ExecuteCommand(ExtAPI, cmds)
        return cmdStat
    
    SysID= GetProjectSystemID(ExtAPI.DataModel.AnalysisList[0].SystemCaption)
    print SysID