84 lines
2.6 KiB
Python
84 lines
2.6 KiB
Python
|
|
"""
|
||
|
|
NX CAD Hooks
|
||
|
|
============
|
||
|
|
|
||
|
|
Direct manipulation of NX CAD parts via NX Open Python API.
|
||
|
|
|
||
|
|
This submodule contains hooks for CAD-level operations on NX parts:
|
||
|
|
geometry, expressions, features, and part management.
|
||
|
|
|
||
|
|
Modules
|
||
|
|
-------
|
||
|
|
part_manager
|
||
|
|
Open, close, save, and query NX part files.
|
||
|
|
|
||
|
|
Functions:
|
||
|
|
- open_part(path) -> Open an NX part file
|
||
|
|
- close_part(path) -> Close an open part
|
||
|
|
- save_part(path) -> Save a part
|
||
|
|
- save_part_as(path, new_path) -> Save with new name
|
||
|
|
- get_part_info(path) -> Get part metadata
|
||
|
|
|
||
|
|
expression_manager
|
||
|
|
Get and set NX expressions (design parameters).
|
||
|
|
|
||
|
|
Functions:
|
||
|
|
- get_expressions(path) -> Get all expressions
|
||
|
|
- get_expression(path, name) -> Get single expression
|
||
|
|
- set_expression(path, name, value) -> Set single expression
|
||
|
|
- set_expressions(path, dict) -> Set multiple expressions
|
||
|
|
|
||
|
|
geometry_query
|
||
|
|
Query geometric properties (mass, volume, area, bodies).
|
||
|
|
|
||
|
|
Functions:
|
||
|
|
- get_mass_properties(path) -> Get mass, volume, area, centroid
|
||
|
|
- get_bodies(path) -> Get body count and types
|
||
|
|
- get_volume(path) -> Get total volume
|
||
|
|
- get_surface_area(path) -> Get total surface area
|
||
|
|
- get_material(path) -> Get material name
|
||
|
|
|
||
|
|
feature_manager
|
||
|
|
Suppress and unsuppress features for design exploration.
|
||
|
|
|
||
|
|
Functions:
|
||
|
|
- get_features(path) -> List all features
|
||
|
|
- get_feature_status(path, name) -> Check if suppressed
|
||
|
|
- suppress_feature(path, name) -> Suppress a feature
|
||
|
|
- unsuppress_feature(path, name) -> Unsuppress a feature
|
||
|
|
- suppress_features(path, names) -> Suppress multiple
|
||
|
|
- unsuppress_features(path, names) -> Unsuppress multiple
|
||
|
|
|
||
|
|
Example
|
||
|
|
-------
|
||
|
|
>>> from optimization_engine.hooks.nx_cad import geometry_query
|
||
|
|
>>> result = geometry_query.get_mass_properties("C:/model.prt")
|
||
|
|
>>> if result["success"]:
|
||
|
|
... print(f"Mass: {result['data']['mass']:.4f} kg")
|
||
|
|
... print(f"Material: {result['data']['material']}")
|
||
|
|
|
||
|
|
NX Open APIs Used
|
||
|
|
-----------------
|
||
|
|
- Session.Parts.OpenActiveDisplay() - Open parts
|
||
|
|
- Part.Close(), Part.Save(), Part.SaveAs() - Part operations
|
||
|
|
- Part.Expressions, ExpressionCollection.Edit() - Expressions
|
||
|
|
- MeasureManager.NewMassProperties() - Mass properties
|
||
|
|
- Part.Bodies - Body collection
|
||
|
|
- Feature.Suppress(), Feature.Unsuppress() - Feature control
|
||
|
|
- Session.UpdateManager.DoUpdate() - Model update
|
||
|
|
"""
|
||
|
|
|
||
|
|
from . import part_manager
|
||
|
|
from . import expression_manager
|
||
|
|
from . import geometry_query
|
||
|
|
from . import feature_manager
|
||
|
|
from . import model_introspection
|
||
|
|
|
||
|
|
__all__ = [
|
||
|
|
'part_manager',
|
||
|
|
'expression_manager',
|
||
|
|
'geometry_query',
|
||
|
|
'feature_manager',
|
||
|
|
'model_introspection',
|
||
|
|
]
|