119 lines
4.1 KiB
Python
119 lines
4.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test PyMechanical API to understand the correct usage
|
|
"""
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Add project root to path
|
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
|
|
def explore_pymechanical_api():
|
|
"""Explore PyMechanical API structure"""
|
|
print("Exploring PyMechanical API...")
|
|
|
|
try:
|
|
import ansys.mechanical.core as pymechanical
|
|
print(f"✓ PyMechanical version: {pymechanical.__version__}")
|
|
|
|
# Try to launch mechanical
|
|
print("\nAttempting to launch Mechanical...")
|
|
|
|
try:
|
|
# Try different launch methods
|
|
mechanical = pymechanical.launch_mechanical(
|
|
batch=True,
|
|
cleanup_on_exit=True
|
|
)
|
|
|
|
print(f"✓ Mechanical launched: {type(mechanical)}")
|
|
|
|
# Explore the mechanical object
|
|
print(f"\nMechanical object attributes:")
|
|
attrs = [attr for attr in dir(mechanical) if not attr.startswith('_')]
|
|
for attr in attrs[:20]: # Show first 20 attributes
|
|
try:
|
|
value = getattr(mechanical, attr)
|
|
print(f" {attr}: {type(value)}")
|
|
except Exception as e:
|
|
print(f" {attr}: Error accessing - {str(e)}")
|
|
|
|
# Try to access common properties
|
|
print(f"\nTesting common properties:")
|
|
|
|
# Test different ways to access model
|
|
test_properties = [
|
|
'model',
|
|
'Model',
|
|
'app',
|
|
'application',
|
|
'project',
|
|
'Project'
|
|
]
|
|
|
|
for prop in test_properties:
|
|
try:
|
|
value = getattr(mechanical, prop, None)
|
|
if value is not None:
|
|
print(f" ✓ {prop}: {type(value)}")
|
|
|
|
# If we found a model-like object, explore it
|
|
if 'model' in prop.lower():
|
|
model_attrs = [attr for attr in dir(value) if not attr.startswith('_')][:10]
|
|
print(f" Model attributes: {model_attrs}")
|
|
else:
|
|
print(f" ✗ {prop}: Not found")
|
|
except Exception as e:
|
|
print(f" ✗ {prop}: Error - {str(e)}")
|
|
|
|
# Try to close the session
|
|
print(f"\nClosing session...")
|
|
try:
|
|
mechanical.exit()
|
|
print("✓ Session closed successfully")
|
|
except Exception as e:
|
|
print(f"✗ Error closing session: {str(e)}")
|
|
|
|
except Exception as e:
|
|
print(f"✗ Failed to launch Mechanical: {str(e)}")
|
|
print("This could be due to:")
|
|
print("- ANSYS license not available")
|
|
print("- ANSYS not properly installed")
|
|
print("- Environment variables not set")
|
|
|
|
except ImportError as e:
|
|
print(f"✗ PyMechanical not available: {str(e)}")
|
|
|
|
def test_environment_setup():
|
|
"""Test ANSYS environment setup"""
|
|
print("\n" + "="*50)
|
|
print("Testing ANSYS Environment Setup...")
|
|
|
|
import os
|
|
|
|
# Set up environment variables
|
|
ansys_root = r'C:\Program Files\ANSYS Inc\v241'
|
|
|
|
print(f"Setting ANSYS environment variables...")
|
|
os.environ['AWP_ROOT241'] = ansys_root
|
|
os.environ['ANSYS_ROOT'] = ansys_root
|
|
|
|
print(f"AWP_ROOT241: {os.environ.get('AWP_ROOT241')}")
|
|
print(f"ANSYS_ROOT: {os.environ.get('ANSYS_ROOT')}")
|
|
|
|
# Check if ANSYS executable exists
|
|
mechanical_exe = r'C:\Program Files\ANSYS Inc\v241\aisol\bin\winx64\AnsysWBU.exe'
|
|
if os.path.exists(mechanical_exe):
|
|
print(f"✓ ANSYS Mechanical executable found: {mechanical_exe}")
|
|
else:
|
|
print(f"✗ ANSYS Mechanical executable not found: {mechanical_exe}")
|
|
|
|
if __name__ == '__main__':
|
|
print("PyMechanical API Exploration")
|
|
print("=" * 60)
|
|
|
|
test_environment_setup()
|
|
explore_pymechanical_api()
|
|
|
|
print("\n" + "="*60)
|
|
print("API exploration completed!") |