Facing NamError Issue for MechanicalEnum object in PyMechanical
- Dominant language
- Python
- Stars
- 83
- Forks
- 37
- Avg merge
- 23h 48m
- Merged PRs (30d)
- 25
Description
Hello,
I am trying to export the Graph for the Chart object using Ansys Mechanical.
Following code works fine inside Ansys Mechanical scripting environment

`import os
graphRes = [1600,800]
var_output_path = r'D:\ACT\py_mech\' # Path to save the exported images
chart_obj = ExtAPI.DataModel.GetObjectsByName('Chart')[0]
Tree.Activate(chart_obj)
output_path = var_output_path + chart_obj.Name.replace(" ", "_") + '.png'
graph = ExtAPI.UserInterface.GetPane(MechanicalPanelEnum.Graph).ControlUnknown
graph.TitleClear()
graph.Legend.Alignment = 1
graph.WritePngFile(output_path,graphRes[0],graphRes[1],0)`
When I am trying the same workflow using pyMechanical, I am getting error as follows:
NameError: name 'MechanicalPanelEnum' is not defined
I have also tried importing **MechanicalPanelEnum ** in pyansys workflow but it didn't work:
from Ansys.ACT.Interfaces.Mechanical import MechanicalPanelEnum as mechpanel
Any suggestions or workarounds on this are appreciated
NOTE: Not using any virtual environment. Also I had to change addingconfig to Workbench since I am trying a thermal stress analysis and there is a known limitation which prevents using standard addin config.
My first block of script for pymech is as follows:
`from ansys.mechanical.core import App
from ansys.mechanical.core.embedding import AddinConfiguration
var_version = 251 # Set the version of Ansys Mechanical
var_config = AddinConfiguration("WorkBench")
var_config.no_act_addins = True
import ansys.mechanical.core as mech
app=mech.App(version=var_version, config=var_config)
globals().update(mech.global_variables(app, True))`
Contributor guide
Research direction
Start with the pyMechanical App setup using AddinConfiguration and mech.global_variables(app, True), then compare which Mechanical scripting names are available when MechanicalPanelEnum is referenced. Reproduce the graph export workflow and determine whether the enum and graph control are available in this configuration; done means the NameError is resolved or the limitation and workaround are documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100