130 lines
3.9 KiB
Python
130 lines
3.9 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Debug PyMechanical script execution
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from backend.pymechanical.session_manager import ANSYSSessionManager
|
|
import logging
|
|
|
|
# Configure logging
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(levelname)s:%(name)s:%(message)s'
|
|
)
|
|
|
|
def test_pymechanical_execution():
|
|
"""Test PyMechanical script execution"""
|
|
print("PyMechanical Script Execution Debug")
|
|
print("=" * 50)
|
|
|
|
session_manager = None
|
|
try:
|
|
# Initialize ANSYS session
|
|
session_manager = ANSYSSessionManager(simulation_mode=False)
|
|
session_manager.start_session()
|
|
print("✓ ANSYS session started")
|
|
|
|
# Test very simple script first
|
|
print("\n1. Testing simple print script...")
|
|
simple_script = '''
|
|
print("Hello from PyMechanical!")
|
|
print("Script is executing")
|
|
'''
|
|
|
|
result = session_manager.mechanical.run_python_script(simple_script)
|
|
print(f"Simple script result: '{result}'")
|
|
print(f"Result type: {type(result)}")
|
|
print(f"Result length: {len(result) if result else 0}")
|
|
|
|
# Test model access
|
|
print("\n2. Testing model access...")
|
|
model_script = '''
|
|
try:
|
|
print("Accessing Model object...")
|
|
model = Model
|
|
print("Model object: " + str(model))
|
|
print("Model type: " + str(type(model)))
|
|
except Exception as e:
|
|
print("Error accessing Model: " + str(e))
|
|
'''
|
|
|
|
result2 = session_manager.mechanical.run_python_script(model_script)
|
|
print(f"Model script result: '{result2}'")
|
|
|
|
# Test geometry access
|
|
print("\n3. Testing geometry access...")
|
|
geometry_script = '''
|
|
try:
|
|
print("Accessing geometry...")
|
|
geometry = Model.Geometry
|
|
print("Geometry object: " + str(geometry))
|
|
|
|
bodies = geometry.GetChildren(Ansys.Mechanical.DataModel.Enums.DataModelObjectCategory.Body, True)
|
|
print("Bodies count: " + str(len(bodies)))
|
|
|
|
if len(bodies) > 0:
|
|
print("First body: " + str(bodies[0]))
|
|
|
|
except Exception as e:
|
|
print("Error accessing geometry: " + str(e))
|
|
import traceback
|
|
traceback.print_exc()
|
|
'''
|
|
|
|
# Import geometry first
|
|
geometry_file = "resource\\blade.step"
|
|
print(f"\nImporting geometry from {geometry_file}...")
|
|
if session_manager.import_geometry(geometry_file):
|
|
print("✓ Geometry imported successfully")
|
|
|
|
result3 = session_manager.mechanical.run_python_script(geometry_script)
|
|
print(f"Geometry script result: '{result3}'")
|
|
else:
|
|
print("✗ Geometry import failed")
|
|
|
|
# Test mesh object access
|
|
print("\n4. Testing mesh object access...")
|
|
mesh_script = '''
|
|
try:
|
|
print("Accessing mesh object...")
|
|
mesh = Model.Mesh
|
|
print("Mesh object: " + str(mesh))
|
|
print("Mesh type: " + str(type(mesh)))
|
|
|
|
# Try to get mesh properties
|
|
try:
|
|
print("Checking mesh properties...")
|
|
if hasattr(mesh, 'ElementSize'):
|
|
print("Has ElementSize property")
|
|
else:
|
|
print("No ElementSize property")
|
|
|
|
except Exception as prop_error:
|
|
print("Error checking properties: " + str(prop_error))
|
|
|
|
except Exception as e:
|
|
print("Error accessing mesh: " + str(e))
|
|
import traceback
|
|
traceback.print_exc()
|
|
'''
|
|
|
|
result4 = session_manager.mechanical.run_python_script(mesh_script)
|
|
print(f"Mesh script result: '{result4}'")
|
|
|
|
print("\n✓ PyMechanical debug test completed")
|
|
|
|
except Exception as e:
|
|
print(f"\n✗ PyMechanical debug test failed: {str(e)}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
finally:
|
|
if session_manager:
|
|
session_manager.close_session()
|
|
|
|
if __name__ == "__main__":
|
|
test_pymechanical_execution() |