Facing issue with embedded instance of pyMechanical

Options
akshays
akshays Member, Employee Posts: 4
First Comment
✭✭✭
edited July 4 in Structures

Hello,

I am trying to export the Graph for the Chart object using Ansys Mechanical.
Following code works fine inside Ansys Mechanical scripting environment

SCRIPT:

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 workaround 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:

step_instruction: import the requried library and initialize the mechanical session

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))