How write an expression with a variable
Hello everyone,
I am trying to define a user defined results to post-process my 2D FEA thermal simulation on Ansys Mechanical. For that, I have two temperature fields which are calculated and identified respectively as T1 and T2. Consequently, I can define my user defined results with the following expression :
DataModel.GetObjectsByName("Results")[0].Expression = r'abs((T2-T1)/0,1)'
It works very well so great !
However, I would like to be able to change the 0.1 at the denominator thus my question : how use a variable in an expression used in a script ?
In Python, I know that I can write the following :
DataModel.GetObjectsByName("Results")[0].Expression = f'abs((T2-T1)/{Valeur})'
Unfortunately, when I use the previous formulation, I have a mistake which appears and which says that it is not recognized by Mechanical...
Any idea how can I fix it ?
THANK YOU !
Pierre
Answers
-
You cannot use this syntax in IronPython. Try instead:
DataModel.GetObjectsByName("Results")[0].Expression = 'abs((T2-T1)/{})'.format(Valeur)
0 -
Dear Landon,
Thank you for your answer ! I am using CPython (necessary to use numpy...) and it seems that my previous syntax is working finally but only for interger values, see just after :Valeur = 3
DataModel.GetObjectsByName("Results")[0].Expression = f'abs((T2-T1)/{Valeur})'BUT
Valeur = 3,5
DataModel.GetObjectsByName("Results")[0].Expression = f'abs((T2-T1)/{Valeur})'It seems that a space is added just after the comma... I have tried to use fractions but the results is using a . without space and this seems to not be understood by Mechanical as my separator for decimal numbers is the comma... Argh !! Any idea how can I bypass this ?
Thank you !
Pierre0 -
@AKD-Scripting-Team Has anyone seen this issue when using comma as decimal denominator?
0