fix: Update intellisense test to prevent execution errors

Modified test_nxopen_intellisense.py to be intellisense-only test file.
NXOpen modules can only run inside NX session, not standalone.

Changes:
- Added clear warning that file should NOT be executed
- Added sys.exit(0) to prevent import errors
- Commented out all NXOpen imports by default
- Added instructions for using file to test autocomplete in VSCode
- Clarified this is for intellisense testing only

Usage: Open file in VSCode and uncomment lines to test autocomplete.
Do NOT run: python test_nxopen_intellisense.py

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-17 08:57:08 -05:00
parent a2ca28a247
commit a8fbe652f5

View File

@@ -1,61 +1,79 @@
""" """
Test script to verify NXOpen Python intellisense is working with stub files. Test script to verify NXOpen Python intellisense is working with stub files.
This script is NOT meant to be executed - it's for testing IDE code completion. ⚠️ IMPORTANT: This file is NOT meant to be executed!
Open this file in VSCode and verify that: NXOpen modules can only run inside an NX session.
1. Import statements show autocomplete suggestions This file is for testing VSCode intellisense/autocomplete only.
2. NXOpen classes show available methods/properties
3. Method parameters show type hints How to use:
4. Hovering over objects shows documentation 1. Open this file in VSCode
2. Test autocomplete by typing the examples below
3. Verify you see suggestions, type hints, and documentation
Setup Required: Setup Required:
- VSCode with Pylance extension installed - VSCode with Pylance extension installed
- .vscode/settings.json configured with stub path: - .vscode/settings.json configured with stub path:
"python.analysis.stubPath": "C:\\Program Files\\Siemens\\Simcenter3D_2412\\ugopen\\pythonStubs" "python.analysis.stubPath": "C:\\Program Files\\Siemens\\NX2412\\UGOPEN\\pythonStubs"
- Python 3.11 environment (atomizer)
DO NOT RUN: python test_nxopen_intellisense.py
(NXOpen requires NX to be running)
""" """
import sys
print("⚠️ This file is for intellisense testing only!")
print("⚠️ NXOpen modules require NX to be running.")
print("⚠️ Use this file in VSCode to test autocomplete, not execution.")
print("\nTo test intellisense:")
print("1. Open this file in VSCode")
print("2. Type 'import NXOpen.' and see autocomplete suggestions")
print("3. Uncomment the test code below and test autocomplete")
sys.exit(0)
# ============================================================================
# INTELLISENSE TEST CODE (Uncomment to test autocomplete in VSCode)
# ============================================================================
# Test 1: Import autocomplete # Test 1: Import autocomplete
# Type "import NXOpen." and verify you see module suggestions: # Type "import NXOpen." and verify you see module suggestions:
# NXOpen.Part, NXOpen.Session, NXOpen.CAE, NXOpen.Assemblies, etc. # NXOpen.Part, NXOpen.Session, NXOpen.CAE, NXOpen.Assemblies, etc.
import NXOpen
import NXOpen.Part # import NXOpen
import NXOpen.Session # import NXOpen.Part
import NXOpen.CAE # import NXOpen.Session
import NXOpen.Assemblies # import NXOpen.CAE
# import NXOpen.Assemblies
# Test 2: Session object autocomplete # Test 2: Session object autocomplete
# Type "session." and verify you see methods like GetSession(), Parts, etc. # Type "session." and verify you see methods like GetSession(), Parts, etc.
session = NXOpen.Session.GetSession() # session = NXOpen.Session.GetSession()
# Test 3: Part methods autocomplete # Test 3: Part methods autocomplete
# Type "part." and verify you see methods # Type "work_part." and verify you see methods
work_part = session.Parts.Work # work_part = session.Parts.Work
# Test 4: Expression methods autocomplete # Test 4: Expression methods autocomplete
# Type "expression." and verify you see methods like FindObject, CreateExpression, etc. # Type "expressions." and verify you see methods like FindObject, CreateExpression, etc.
if work_part: # if work_part:
expressions = work_part.Expressions # expressions = work_part.Expressions
# Type "expressions." and verify methods appear: # # Type "expressions." and verify methods appear:
# expressions.FindObject, CreateExpression, EditWithUnits, etc. # # expressions.FindObject, CreateExpression, EditWithUnits, etc.
# Test 5: Parameter type hints # # Test 5: Parameter type hints
# Hover over CreateExpression and verify you see parameter types # # Hover over CreateExpression and verify you see parameter types
# expression = expressions.CreateExpression("test", "1.0") # # expression = expressions.CreateExpression("test", "1.0")
# Test 6: CAE autocomplete # Test 6: CAE autocomplete
# Type "fem_part." and verify CAE-specific methods appear # Type "fem_part." and verify CAE-specific methods appear
fem_part = NXOpen.CAE.FemPart # fem_part = NXOpen.CAE.FemPart
# Type "fem_part." to see: BaseFemPart, FemModel, etc. # Type "fem_part." to see: BaseFemPart, FemModel, etc.
# Test 7: Assembly autocomplete # Test 7: Assembly autocomplete
# Type "assemblies." and verify assembly methods appear # Type "assemblies." and verify assembly methods appear
assemblies = work_part.ComponentAssembly if work_part else None # work_part = None # Would come from session
# assemblies = work_part.ComponentAssembly if work_part else None
# Type "assemblies." to see: AddComponent, CreateComponent, etc. # Type "assemblies." to see: AddComponent, CreateComponent, etc.
# Test 8: Documentation tooltips # Test 8: Documentation tooltips
# Hover over any NXOpen class/method and verify documentation appears # Hover over any NXOpen class/method and verify documentation appears
# Example: Hover over "GetSession()" above - should show docstring # Example: Hover over "GetSession()" - should show docstring
print("Intellisense test file - Do not execute!")
print("Open in VSCode and test autocomplete functionality")
print("If you see type hints and autocomplete suggestions, intellisense is working!")