Add NX diagnostic logging: OpenActiveDisplay result, load status, Parts.Open details

Need to see why Parts.Open returns None even from the master model folder.
Logs: basePart1 type/name/path, unloaded parts status, file existence checks.
This commit is contained in:
2026-02-11 15:16:26 +00:00
parent 3718a8d5c8
commit 55f0f917c7

View File

@@ -849,12 +849,33 @@ def solve_simple_workflow(
print(f"[JOURNAL] Opening simulation: {sim_file_path}")
# Open the .sim file
print(f"[JOURNAL] sim_file_path = {sim_file_path}")
print(f"[JOURNAL] File exists: {os.path.exists(sim_file_path)}")
basePart1, partLoadStatus1 = theSession.Parts.OpenActiveDisplay(
sim_file_path, NXOpen.DisplayPartOption.AllowAdditional
)
# Diagnostic: check load status
print(f"[JOURNAL] OpenActiveDisplay result: basePart1={basePart1}")
print(f"[JOURNAL] basePart1 type: {type(basePart1).__name__}" if basePart1 else "[JOURNAL] basePart1 is None!")
if basePart1:
print(f"[JOURNAL] basePart1.Name: {basePart1.Name}")
print(f"[JOURNAL] basePart1.FullPath: {basePart1.FullPath}")
try:
n_statuses = partLoadStatus1.NumberUnloadedParts
print(f"[JOURNAL] Unloaded parts: {n_statuses}")
for i in range(n_statuses):
name = partLoadStatus1.GetPartName(i)
status = partLoadStatus1.GetStatus(i)
status_desc = partLoadStatus1.GetStatusDescription(i)
print(f"[JOURNAL] Part[{i}]: {name} — status={status} ({status_desc})")
except Exception as e:
print(f"[JOURNAL] Could not read load status details: {e}")
partLoadStatus1.Dispose()
workSimPart = theSession.Parts.BaseWork
print(f"[JOURNAL] BaseWork: {workSimPart.Name if workSimPart else 'None'}")
print(f"[JOURNAL] Parts count: {sum(1 for _ in theSession.Parts)}")
# =========================================================================
# STEP 1: UPDATE EXPRESSIONS IN GEOMETRY PART (if any)
@@ -901,8 +922,21 @@ def solve_simple_workflow(
):
prt_path = os.path.join(working_dir, filename)
print(f"[JOURNAL] Loading geometry part: {filename}")
print(f"[JOURNAL] Full path: {prt_path}")
print(f"[JOURNAL] File exists: {os.path.exists(prt_path)}")
print(f"[JOURNAL] File size: {os.path.getsize(prt_path) if os.path.exists(prt_path) else 'N/A'}")
try:
loaded_part, partLoadStatus = theSession.Parts.Open(prt_path)
try:
n_unloaded = partLoadStatus.NumberUnloadedParts
if n_unloaded > 0:
print(f"[JOURNAL] Parts.Open unloaded parts: {n_unloaded}")
for i in range(n_unloaded):
pn = partLoadStatus.GetPartName(i)
ps = partLoadStatus.GetStatusDescription(i)
print(f"[JOURNAL] [{i}]: {pn}{ps}")
except:
pass
partLoadStatus.Dispose()
# Check if load actually succeeded (Parts.Open can return None)
if loaded_part is not None:
@@ -911,8 +945,14 @@ def solve_simple_workflow(
break
else:
print(f"[JOURNAL] WARNING: Parts.Open returned None for {filename}")
# Check if part got loaded anyway under a different reference
print(f"[JOURNAL] Parts after Open attempt: {sum(1 for _ in theSession.Parts)}")
for p in theSession.Parts:
print(f"[JOURNAL] - {p.Name} ({type(p).__name__})")
except Exception as e:
print(f"[JOURNAL] WARNING: Could not load {filename}: {e}")
import traceback
traceback.print_exc()
if geom_part:
try: