AnsysLink/test/test_mechdb_content.py

81 lines
2.9 KiB
Python

#!/usr/bin/env python3
"""
Test to verify .mechdb file contains mesh data
"""
import os
import glob
def analyze_mechdb_files():
"""Analyze found .mechdb files"""
print("Analyzing ANSYS .mechdb Files")
print("=" * 40)
# Find all .mechdb files
temp_dir = r"C:\Users\Tellme\AppData\Local\Temp\ANSYS.Tellme.1"
mechdb_files = []
if os.path.exists(temp_dir):
for root, dirs, files in os.walk(temp_dir):
for file in files:
if file.endswith('.mechdb'):
file_path = os.path.join(root, file)
size = os.path.getsize(file_path)
mtime = os.path.getmtime(file_path)
mechdb_files.append((file_path, size, mtime))
if not mechdb_files:
print("No .mechdb files found")
return
# Sort by modification time (newest first)
mechdb_files.sort(key=lambda x: x[2], reverse=True)
print(f"Found {len(mechdb_files)} .mechdb files:")
for i, (file_path, size, mtime) in enumerate(mechdb_files):
import datetime
mod_time = datetime.datetime.fromtimestamp(mtime)
print(f"\n{i+1}. {os.path.basename(file_path)}")
print(f" Path: {file_path}")
print(f" Size: {size:,} bytes ({size/1024/1024:.1f} MB)")
print(f" Modified: {mod_time}")
# Try to get basic file info
try:
with open(file_path, 'rb') as f:
# Read first 100 bytes to check file signature
header = f.read(100)
print(f" Header (first 20 bytes): {header[:20]}")
# Check if it looks like a valid ANSYS file
if b'ANSYS' in header or b'Mechanical' in header:
print(" ✓ Appears to be a valid ANSYS file")
else:
print(" ? File format unclear")
except Exception as e:
print(f" Error reading file: {e}")
# Provide information about what these files contain
print(f"\n" + "=" * 40)
print("About .mechdb files:")
print("- These are ANSYS Mechanical database files")
print("- They contain the complete project data including:")
print(" * Geometry")
print(" * Mesh data (nodes, elements)")
print(" * Material properties")
print(" * Boundary conditions")
print(" * Analysis settings")
print(" * Results (if analysis was run)")
print("- They can be opened in ANSYS Mechanical Workbench")
print("- The mesh data is stored in binary format within these files")
# Check if we can find the most recent one
if mechdb_files:
newest_file = mechdb_files[0][0]
print(f"\nMost recent file: {newest_file}")
print("This likely contains the mesh from our latest test!")
if __name__ == "__main__":
analyze_mechdb_files()