Documentation: - Add docs/06_PHYSICS/ with Zernike fundamentals and OPD method docs - Add docs/guides/CMA-ES_EXPLAINED.md optimization guide - Update CLAUDE.md and ATOMIZER_CONTEXT.md with current architecture - Update OP_01_CREATE_STUDY protocol Planning: - Add DYNAMIC_RESPONSE plans for random vibration/PSD support - Add OPTIMIZATION_ENGINE_MIGRATION_PLAN for code reorganization Insights System: - Update design_space, modal_analysis, stress_field, thermal_field insights - Improve error handling and data validation NX Journals: - Add analyze_wfe_zernike.py for Zernike WFE analysis - Add capture_study_images.py for automated screenshots - Add extract_expressions.py and introspect_part.py utilities - Add user_generated_journals/journal_top_view_image_taking.py Tests & Tools: - Add comprehensive Zernike OPD test suite - Add audit_v10 tests for WFE validation - Add tools for Pareto graphs and mirror data extraction - Add migrate_studies_to_topics.py utility Knowledge Base: - Initialize LAC (Learning Atomizer Core) with failure/success patterns Dashboard: - Update Setup.tsx and launch_dashboard.py - Add restart-dev.bat helper script 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
97 lines
3.2 KiB
Python
97 lines
3.2 KiB
Python
"""
|
|
Standalone expression extractor - opens part and extracts all expressions
|
|
Run with: ugraf.exe -run extract_expressions_standalone.py
|
|
"""
|
|
import NXOpen
|
|
import os
|
|
import json
|
|
|
|
def main():
|
|
session = NXOpen.Session.GetSession()
|
|
|
|
part_path = r"C:\Users\antoi\Atomizer\studies\m1_mirror_cost_reduction\1_setup\model\M1_Blank.prt"
|
|
output_json = r"C:\Users\antoi\Atomizer\_expressions_output.json"
|
|
output_txt = r"C:\Users\antoi\Atomizer\_expressions_output.txt"
|
|
|
|
results = {'expressions': [], 'success': False, 'part': part_path}
|
|
output_lines = []
|
|
|
|
try:
|
|
# Set load options
|
|
working_dir = os.path.dirname(part_path)
|
|
session.Parts.LoadOptions.ComponentLoadMethod = NXOpen.LoadOptions.LoadMethod.FromDirectory
|
|
session.Parts.LoadOptions.SetSearchDirectories([working_dir], [True])
|
|
|
|
# Open the part
|
|
output_lines.append(f"Opening: {part_path}")
|
|
basePart, loadStatus = session.Parts.OpenActiveDisplay(
|
|
part_path,
|
|
NXOpen.DisplayPartOption.AllowAdditional
|
|
)
|
|
loadStatus.Dispose()
|
|
|
|
workPart = session.Parts.Work
|
|
output_lines.append(f"Loaded: {workPart.Name}")
|
|
output_lines.append("")
|
|
output_lines.append("=" * 60)
|
|
output_lines.append("EXPRESSIONS IN M1_Blank.prt")
|
|
output_lines.append("=" * 60)
|
|
|
|
# Extract expressions
|
|
for expr in workPart.Expressions:
|
|
try:
|
|
name = expr.Name
|
|
|
|
# Skip internal expressions (p0, p1, p123, etc.)
|
|
if name.startswith('p') and len(name) > 1:
|
|
rest = name[1:]
|
|
# Check if rest is numeric (possibly with dots for decimals)
|
|
if rest.replace('.', '').replace('_', '').isdigit():
|
|
continue
|
|
|
|
value = expr.Value
|
|
units = expr.Units.Name if expr.Units else ''
|
|
rhs = expr.RightHandSide if hasattr(expr, 'RightHandSide') else ''
|
|
|
|
results['expressions'].append({
|
|
'name': name,
|
|
'value': value,
|
|
'units': units,
|
|
'formula': rhs
|
|
})
|
|
|
|
units_str = f" [{units}]" if units else ""
|
|
output_lines.append(f"{name}: {value}{units_str}")
|
|
|
|
except Exception as e:
|
|
output_lines.append(f"Error reading expression: {e}")
|
|
|
|
results['success'] = True
|
|
results['count'] = len(results['expressions'])
|
|
output_lines.append("")
|
|
output_lines.append(f"Total user expressions: {results['count']}")
|
|
|
|
except Exception as e:
|
|
import traceback
|
|
results['error'] = str(e)
|
|
results['traceback'] = traceback.format_exc()
|
|
output_lines.append(f"ERROR: {e}")
|
|
output_lines.append(traceback.format_exc())
|
|
|
|
# Write outputs
|
|
with open(output_json, 'w') as f:
|
|
json.dump(results, f, indent=2)
|
|
|
|
with open(output_txt, 'w') as f:
|
|
f.write('\n'.join(output_lines))
|
|
|
|
# Exit NX
|
|
try:
|
|
session.Parts.Work.Close(NXOpen.BasePart.CloseWholeTree.FalseValue,
|
|
NXOpen.BasePart.CloseModified.CloseModified, None)
|
|
except:
|
|
pass
|
|
|
|
if __name__ == '__main__':
|
|
main()
|