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
-
@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
3 -
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)
0
Answers
-
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)
0 -
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
Jean0 -
@Landon Mitchell Kanner , I thought you had something like this... can you comment on this topic?
0 -
Thanks a lot, it's perfect!
1 -
Glad I could help! Still wondering why I went for a convulted solution in the first place
0 -
@Landon Mitchell Kanner , I thought you had something like this... can you comment on this topic?
0 -
@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?
1 -
@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.0