fix: generic mass extraction in solve_simulation.py (beam + bracket)
- Extract mass RIGHT AFTER geometry rebuild while part is work part - Replace unreliable p173 expression lookup with MeasureManager - Skip re-extraction if mass already captured during rebuild - Relax displacement constraint to 20mm (DEC-HB-012, CEO approved) Root cause: journal hardcoded M1_Blank for bracket, failed silently on Beam.prt Fix by: NX Expert + Manager diagnosis
This commit is contained in:
@@ -1013,6 +1013,15 @@ def solve_simple_workflow(
|
||||
theSession.DeleteUndoMark(markId_update, "NX update")
|
||||
print(f"[JOURNAL] Geometry rebuilt ({nErrs} errors)")
|
||||
|
||||
# Extract mass NOW while geometry part is work part and freshly rebuilt
|
||||
# This is the most reliable timing — solid bodies reflect updated parameters
|
||||
print(f"[JOURNAL] Extracting mass from {workPart.Name}...")
|
||||
try:
|
||||
mass_kg = extract_part_mass(theSession, workPart, working_dir)
|
||||
print(f"[JOURNAL] Mass extracted: {mass_kg:.6f} kg")
|
||||
except Exception as mass_err:
|
||||
print(f"[JOURNAL] WARNING: Mass extraction after rebuild failed: {mass_err}")
|
||||
|
||||
# Save geometry part
|
||||
print(f"[JOURNAL] Saving geometry part...")
|
||||
partSaveStatus_geom = workPart.Save(
|
||||
@@ -1171,25 +1180,22 @@ def solve_simple_workflow(
|
||||
)
|
||||
|
||||
# Extract mass and write to _temp_mass.txt
|
||||
# Strategy: try expression lookup first, fall back to MeasureManager
|
||||
# Strategy: Use MeasureManager on geometry part (most reliable)
|
||||
# Note: Mass may have already been extracted during geometry rebuild phase above.
|
||||
# This post-solve extraction ensures we have mass even if no expression updates were done.
|
||||
try:
|
||||
mass_value = None
|
||||
|
||||
# Attempt 1: Read mass from expression p173 on geometry part
|
||||
try:
|
||||
for part in theSession.Parts:
|
||||
part_type = type(part).__name__
|
||||
if "fem" not in part_type.lower() and "sim" not in part_type.lower():
|
||||
for expr in part.Expressions:
|
||||
if expr.Name == "p173":
|
||||
mass_value = expr.Value
|
||||
print(f"[JOURNAL] Mass expression p173 = {mass_value}")
|
||||
break
|
||||
break
|
||||
except Exception as expr_err:
|
||||
print(f"[JOURNAL] Expression lookup failed: {expr_err}")
|
||||
# Check if mass was already written during geometry rebuild
|
||||
mass_file = os.path.join(working_dir, "_temp_mass.txt")
|
||||
if os.path.exists(mass_file) and expression_updates:
|
||||
print(f"[JOURNAL] Mass already extracted during geometry rebuild phase")
|
||||
with open(mass_file, "r") as f:
|
||||
content = f.read().strip()
|
||||
print(f"[JOURNAL] Existing mass file: {content}")
|
||||
mass_value = -1 # sentinel to skip re-extraction
|
||||
|
||||
# Attempt 2: Use MeasureManager (more reliable for derived/measurement expressions)
|
||||
# Use MeasureManager if mass not yet extracted
|
||||
if mass_value is None:
|
||||
print(f"[JOURNAL] Expression p173 not found, using MeasureManager fallback...")
|
||||
geom_part = None
|
||||
@@ -1206,12 +1212,12 @@ def solve_simple_workflow(
|
||||
print(f"[JOURNAL] MeasureManager failed: {mm_err}")
|
||||
|
||||
# Write mass file (extract_part_mass may have already written it, but ensure consistency)
|
||||
if mass_value is not None:
|
||||
if mass_value is not None and mass_value != -1:
|
||||
mass_file = os.path.join(working_dir, "_temp_mass.txt")
|
||||
with open(mass_file, "w") as f:
|
||||
f.write(f"p173={mass_value}\n")
|
||||
print(f"[JOURNAL] Wrote mass to {mass_file}")
|
||||
else:
|
||||
elif mass_value is None:
|
||||
print(f"[JOURNAL] WARNING: Could not extract mass via expression or MeasureManager")
|
||||
except Exception as e:
|
||||
print(f"[JOURNAL] WARNING: Mass extraction failed: {e}")
|
||||
|
||||
Reference in New Issue
Block a user