In Mechanical how to rename analysis based on names in Workbench ?

Hi,

In Workbench, I renamed my analysis.

In Mechanical, I have to rename all the analysis.

Is there a way with a Python script (or other) to automaticly rename analysis in Mechanical, based on names in Workbench ?

Thanks,
Jean

Best Answers

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

    @Jean , just realized there's actually a simpler way to do that. Below code should be executed from Mechanical.

    analyses = ExtAPI.DataModel.AnalysisList
    for an in analyses:
        an.Name = an.SystemCaption
    
  • Erik Kostson
    Erik Kostson Member, Moderator, Employee Posts: 335
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited January 28 Answer ✓

    Below is an example that changes the System name in the WB Project (Static Structural say), based on the Mechanical analysis name (say Static Structural (A5)). Change the GetALLSystems to say GetSystem(Name="SYS") and SYS as needed.

    import System
    from System.Threading import *
    analysis=ExtAPI.DataModel.Project.Model.Analyses[0]
    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 = "%s"
    '''%analysis.Name
    
    RunWBJN(project_cmds)
    

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 913
    100 Answers 500 Comments 250 Likes Second Anniversary
    ✭✭✭✭

    Hi,
    I reused this post: https://discuss.ansys.com/discussion/2478/how-do-i-communicate-with-the-project-page-from-within-mechanical to come up with the following code, to be executed from Mechanical, and which will rename the analyses both at the Project Schematic level and in Mechanical.
    Note - there is no direct link in this code between the component in the project schematic and the Mechanical analysis, it is assumed the analyses systems will be looped in the same order. Please verify it works correctly on your model.

    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 = '''
    systems = GetAllSystems()
    for i, sys in enumerate(systems):
        sys.DisplayText = "Test_"+str(i)
    '''
    RunWBJN(project_cmds)
    
    analyses = ExtAPI.DataModel.AnalysisList
    for i,an in enumerate(analyses):
        an.Name = "Test_"+str(i)
    
  • Jean
    Jean Member Posts: 34
    10 Comments 5 Likes First Anniversary Name Dropper
    **

    Hi,
    Thanks for your answer.

    Unfortunately, it's not what I expected.
    In this code, names in Workbench are replaced by "test_i".
    (Since there is no link between Workbench and Mechanical, I get some problem when the project is more "complex", as shown in images below (test_5 in Workbench is test_0 in Mechanical))

    My goal is :
    (i) get names in Workbench (I don't want to rename system, but getting names I already gave) ;
    (ii) rename system in Mechanical with name from Workbench.

    Thanks
    Jean

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 404
    100 Likes 25 Answers 100 Comments Second Anniversary
    ✭✭✭✭

    @Landon Mitchell Kanner , I thought you had something like this... can you comment on this topic?

  • Jean
    Jean Member Posts: 34
    10 Comments 5 Likes First Anniversary Name Dropper
    **

    Thanks a lot, it's perfect!

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 913
    100 Answers 500 Comments 250 Likes Second Anniversary
    ✭✭✭✭

    Glad I could help! Still wondering why I went for a convulted solution in the first place ;)

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee, GitHub-issue-creator Posts: 353
    50 Answers 100 Likes 100 Comments Second Anniversary
    ✭✭✭✭

    @Landon Mitchell Kanner , I thought you had something like this... can you comment on this topic?

    See https://discuss.ansys.com/discussion/4676/can-i-update-generate-etc-an-entire-model-except-for-the-analyses

  • Francesco Paccagnella
    Francesco Paccagnella Member Posts: 1
    Name Dropper First Comment
    **

    @Pernelle Marone-Hitz said:
    @Jean , just realized there's actually a simpler way to do that. Below code should be executed from Mechanical.

    analyses = ExtAPI.DataModel.AnalysisList
    for an in analyses:
        an.Name = an.SystemCaption
    

    Is there a way to do the opposite, renaming the WB system to match the analysis name in Mechanical? This is useful as load cases are defined in Mechanical and it will benefit the title in the legend. Any help will be highly appreciated.

    NOTE. I had an ACT done by a channel partner support a while ago but it is not working with the new releases. Is there a way to access the code used in the ACT?

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 913
    100 Answers 500 Comments 250 Likes Second Anniversary
    ✭✭✭✭

    @Francesco Paccagnella This post should help:
    https://discuss.ansys.com/discussion/3475/how-to-rename-a-static-structural-analysis-in-wb-based-on-its-name-in-the-mechanical
    As for your question on the source code, if the ACT was shared with you through a wbex file you will not be able to get the source code. If it was shared as a scripted extension, then the source code is available.