feat: Add SIM file introspection journal and enhanced file-type specific UI
- Create introspect_sim.py NX journal to extract solutions, BCs from SIM files - Update introspect_sim_file() to optionally call NX journal for full introspection - Add FEM mesh section (nodes, elements, materials, properties) to IntrospectionPanel - Add SIM solutions and boundary conditions sections to IntrospectionPanel - Show introspection method and NX errors in panel
This commit is contained in:
@@ -5357,19 +5357,89 @@ def introspect_fem_file(fem_path: Path) -> dict:
|
||||
return result
|
||||
|
||||
|
||||
def introspect_sim_file(sim_path: Path) -> dict:
|
||||
def introspect_sim_file(sim_path: Path, use_nx: bool = True) -> dict:
|
||||
"""
|
||||
Introspect a .sim file - extract solution info.
|
||||
|
||||
Note: .sim is a binary NX format, so we extract what we can from associated files.
|
||||
Args:
|
||||
sim_path: Path to the .sim file
|
||||
use_nx: If True, use NX journal for full introspection (requires NX license)
|
||||
If False, use file-based heuristics only
|
||||
|
||||
Note: .sim is a binary NX format. Full introspection requires NX Open.
|
||||
"""
|
||||
result = {
|
||||
"file_type": "sim",
|
||||
"file_name": sim_path.name,
|
||||
"success": True,
|
||||
"note": "SIM files are binary NX format. Use NX introspection for full details.",
|
||||
}
|
||||
|
||||
# Try NX journal introspection if requested
|
||||
if use_nx:
|
||||
try:
|
||||
import subprocess
|
||||
import json
|
||||
|
||||
# Find NX installation
|
||||
nx_paths = [
|
||||
Path("C:/Program Files/Siemens/DesigncenterNX2512/NXBIN/run_journal.exe"),
|
||||
Path("C:/Program Files/Siemens/NX2412/NXBIN/run_journal.exe"),
|
||||
Path("C:/Program Files/Siemens/Simcenter3D_2412/NXBIN/run_journal.exe"),
|
||||
]
|
||||
journal_runner = None
|
||||
for p in nx_paths:
|
||||
if p.exists():
|
||||
journal_runner = p
|
||||
break
|
||||
|
||||
if journal_runner:
|
||||
journal_path = (
|
||||
Path(__file__).parent.parent.parent.parent.parent
|
||||
/ "nx_journals"
|
||||
/ "introspect_sim.py"
|
||||
)
|
||||
if not journal_path.exists():
|
||||
# Try alternate path
|
||||
journal_path = Path("C:/Users/antoi/Atomizer/nx_journals/introspect_sim.py")
|
||||
|
||||
if journal_path.exists():
|
||||
cmd = [
|
||||
str(journal_runner),
|
||||
str(journal_path),
|
||||
str(sim_path),
|
||||
str(sim_path.parent),
|
||||
]
|
||||
|
||||
# Run NX journal with timeout
|
||||
proc = subprocess.run(
|
||||
cmd, capture_output=True, text=True, timeout=120, cwd=str(sim_path.parent)
|
||||
)
|
||||
|
||||
# Check for output file
|
||||
output_file = sim_path.parent / "_introspection_sim.json"
|
||||
if output_file.exists():
|
||||
with open(output_file, "r") as f:
|
||||
nx_result = json.load(f)
|
||||
result.update(nx_result)
|
||||
result["introspection_method"] = "nx_journal"
|
||||
return result
|
||||
else:
|
||||
result["nx_error"] = "Journal completed but no output file"
|
||||
result["nx_stdout"] = proc.stdout[-2000:] if proc.stdout else None
|
||||
result["nx_stderr"] = proc.stderr[-2000:] if proc.stderr else None
|
||||
else:
|
||||
result["nx_error"] = f"Journal not found: {journal_path}"
|
||||
else:
|
||||
result["nx_error"] = "NX installation not found"
|
||||
except subprocess.TimeoutExpired:
|
||||
result["nx_error"] = "NX journal timed out (120s)"
|
||||
except Exception as e:
|
||||
result["nx_error"] = f"NX introspection failed: {str(e)}"
|
||||
|
||||
# Fallback: file-based heuristics
|
||||
result["introspection_method"] = "file_heuristics"
|
||||
result["note"] = "SIM files are binary NX format. NX introspection unavailable."
|
||||
|
||||
# Check for associated .dat file that might have been exported
|
||||
dat_file = sim_path.parent / (sim_path.stem + ".dat")
|
||||
if not dat_file.exists():
|
||||
@@ -5380,7 +5450,13 @@ def introspect_sim_file(sim_path: Path) -> dict:
|
||||
|
||||
if dat_file.exists():
|
||||
result["associated_dat"] = dat_file.name
|
||||
# Could parse the DAT file for solution info if needed
|
||||
|
||||
# Try to infer solver type from related files
|
||||
parent_dir = sim_path.parent
|
||||
if any(f.suffix.lower() == ".afm" for f in parent_dir.iterdir() if f.is_file()):
|
||||
result["inferred"] = {"assembly_fem": True, "solver": "nastran"}
|
||||
elif any(f.suffix.lower() == ".fem" for f in parent_dir.iterdir() if f.is_file()):
|
||||
result["inferred"] = {"assembly_fem": False, "solver": "nastran"}
|
||||
|
||||
return result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user