How to get the PyMechanical app.print_tree() into logger info.?

Hi team, Im trying to get the app.print_tree() tree data into the logger. Below is the script for you reference:
`import os
import logging
os.environ['PYTHONIOENCODING'] = 'utf8'
from ansys.mechanical.core import App
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setLevel(logging.DEBUG)
logger.addHandler(stream_handler)
from ansys.mechanical.core import App
app = App()
app =App(version=242)
ansys_tree = ansys_app.print_tree()
logger.debug(f"Ansys Tree Structure:\n{ansys_tree }")
`
But Im unable to get the tree.
I need your assistance here..!!
Comments
-
@Naveen Kumar Begari said:
Hi team, Im trying to get the app.print_tree() tree data into the logger. Below is the script for you reference:`import os
import loggingos.environ['PYTHONIOENCODING'] = 'utf8'
from ansys.mechanical.core import App
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setLevel(logging.DEBUG)
logger.addHandler(stream_handler)
from ansys.mechanical.core import App
app = App()
app =App(version=242)
ansys_tree = ansys_app.print_tree()
logger.debug(f"Ansys Tree Structure:\n{ansys_tree }")
`But Im unable to get the tree.
I need your assistance here..!!
Take this as reference:
`import os
import loggingos.environ['PYTHONIOENCODING'] = 'utf8'
from ansys.mechanical.core import App
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setLevel(logging.DEBUG)
logger.addHandler(stream_handler)
from ansys.mechanical.core import App
app = App()
app =App(version=242)
ansys_tree = app.print_tree()
logger.debug(f"Ansys Tree Structure:\n{ansys_tree }")
`0 -
Hi @Naveen Kumar Begari . In your code,
ansys_tree
is not a string. There is probably a more elegant solution, but here's one workaround:tempfile = r'D:\temp.txt' import sys from ansys.mechanical.core import App app = App() original_stdout = sys.stdout with open(tempfile, 'w', encoding="utf-8") as file: sys.stdout = file app.print_tree() sys.stdout = original_stdout with open(tempfile, encoding="utf-8") as file: ansys_tree = file.read()
0 -
Hello @Landon Mitchell Kanner, Thank you so much for your response.
But,
when I execute these lines:```python
ansys_app = App(version=242)
ansys_app.update_globals(globals())
ansys_tree = ansys_app.print_tree()
tempfile = 'simulation_logs.txt'
original_stdout = sys.stdout
with open(tempfile, 'a', encoding="utf-8") as file:
sys.stdout = file
ansys_app.print_tree()
sys.stdout = original_stdout
with open(tempfile, encoding="utf-8") as file:
ansys_trees = file.read()So in .txt file it was reading perfect but in webapp it was showing different.
0 -
For you reference:
ansys_app = App(version=242) ansys_app.update_globals(globals()) ansys_tree = ansys_app.print_tree() tempfile = 'simulation_logs.txt' original_stdout = sys.stdout with open(tempfile, 'a', encoding="utf-8") as file: sys.stdout = file ansys_app.print_tree() sys.stdout = original_stdout with open(tempfile, encoding="utf-8") as file: ansys_trees = file.read()
0 -
What is your ultimate goal?
0 -
@Landon Mitchell Kanner it's working fine, thanks for your support.
0 -
@Landon Mitchell Kanner said:
What is your ultimate goal?from log file I need to show on the WebApp.
0 -
@Landon Mitchell Kanner, While performing the analysis (specifically when the solver is triggered), the logger keeps disconnecting.
Is there a way to keep it active on the web app?
0 -
While performing the analysis (specifically when the solver is triggered), the logger keeps disconnecting.
Is there a way to keep it active on the web app?
I am not very familiar with the
logging
module, which is part of Python and not developed by Ansys. What are you using to create a web app? I suggest you post a new question with enough details to reproduce the issue.0 -
@Landon Mitchell Kanner said:
While performing the analysis (specifically when the solver is triggered), the logger keeps disconnecting.
Is there a way to keep it active on the web app?
I am not very familiar with the
logging
module, which is part of Python and not developed by Ansys. What are you using to create a web app? I suggest you post a new question with enough details to reproduce the issue.Hi @Landon Mitchell Kanner, I'm using Dash technology for webapp development.
Sure, I will post0