19 lines
4.3 KiB
JSON
19 lines
4.3 KiB
JSON
```json
|
|
{
|
|
"schemaVersion": "1.1",
|
|
"runId": "orch-1771289750-8a0c6163",
|
|
"agent": "webster",
|
|
"status": "complete",
|
|
"result": "## NXOpen Python: Symmetric Extrusion\n\nThis Python code snippet, designed for use within a Siemens NX environment, demonstrates how to perform a symmetric extrusion on a pre-existing sketch.\n\n### Python Code\n\n```python\nimport NXOpen\nimport NXOpen.Features\nimport NXOpen.GeometricUtilities\n\ndef main():\n # Get the current session and work part\n theSession = NXOpen.Session.GetSession()\n workPart = theSession.Parts.Work\n theUI = NXOpen.UI.GetUI()\n\n # Find the sketch by name\n sketchName = 'ISOGRID_RIB_sandbox_1'\n sketch = None\n for s in workPart.Sketches:\n if s.Name == sketchName:\n sketch = s\n break\n\n if sketch is None:\n theUI.NXMessageBox.Show(\"Error\", NXOpen.NXMessageBox.DialogType.Error, f\"Sketch '{sketchName}' not found.\")\n return\n\n # 1. Create an ExtrudeBuilder\n extrudeBuilder = workPart.Features.CreateExtrudeBuilder(NXOpen.Features.Feature.Null)\n\n # 2. Set the section for extrusion\n section = workPart.Sections.CreateSection(0.0095, 0.01, 0.5)\n extrudeBuilder.Section = section\n extrudeBuilder.AllowSelfIntersectingSection(True)\n\n # Define the extrusion direction (using sketch normal)\n direction = NXOpen.Vector3d(0.0, 0.0, 1.0) # Default Z-axis\n if sketch.Normal is not None:\n direction = sketch.Normal\n extrudeBuilder.Direction = direction\n\n # Add the sketch curves to the section\n scRule = workPart.ScRuleFactory.CreateRuleSketch(sketch)\n rules = [scRule]\n extrudeBuilder.Section.AddFromRule(scRule)\n\n # 3. Set symmetric extrusion limits\n # The key to a symmetric extrusion is setting both the start and end distance.\n extrudeBuilder.Limits.StartExtend.Value.RightHandSide = \"10\"\n extrudeBuilder.Limits.EndExtend.Value.RightHandSide = \"10\"\n # A symmetric extrusion is implicitly created by having non-zero start and end values.\n # For clarity, one could express the start as a negative value in some contexts,\n # but setting both end values achieves the symmetric result relative to the sketch plane.\n\n # Set boolean operation type (e.g., Unite, Subtract, Intersect)\n extrudeBuilder.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Unite\n\n # 4. Commit the feature\n feature = extrudeBuilder.Commit()\n\n # 5. Clean up the builder\n extrudeBuilder.Destroy()\n\nif __name__ == '__main__':\n main()\n\n```\n\n### Explanation\n\n1. **`CreateExtrudeBuilder`**: This function from the `workPart.Features` collection instantiates a builder object, which is used to define all the parameters of the extrusion feature before it is created.\n\n2. **`Section`**: The `extrudeBuilder.Section` property is assigned a new `Section` object. This section acts as a container for the geometry that will be extruded. The sketch `ISOGRID_RIB_sandbox_1` is added to this section using a `ScRuleFactory` (Smart Collector Rule Factory) which is the standard way to select entire sketches.\n\n3. **`Limits`**: This is the most critical part for a symmetric extrusion. The `extrudeBuilder.Limits` object has `StartExtend` and `EndExtend` properties. By setting the `Value` of both to \"10\", we instruct NX to extrude 10mm in one direction from the sketch plane and 10mm in the opposite direction, resulting in a total extrusion depth of 20mm, centered on the sketch.\n\n4. **`Commit`**: This method finalizes the builder's parameters and creates the actual `Extrude` feature in the model history.\n\n5. **`Destroy`**: After the feature is created, the builder object is no longer needed and is destroyed to free up resources.",
|
|
"deliverable": {
|
|
"type": "code",
|
|
"title": "NXOpen Python Snippet for Symmetric Extrusion",
|
|
"path": null,
|
|
"summary": "A Python script using the nxopen module to perform a 10mm symmetric extrusion on a specified sketch."
|
|
},
|
|
"artifacts": [],
|
|
"confidence": "high",
|
|
"notes": "The provided code assumes it is run within an active NX session where a part is loaded and contains a sketch with the specified name. The boolean operation is set to 'Unite' by default, which may need to be changed depending on the desired interaction with existing bodies.",
|
|
"timestamp": "2026-02-17T00:55:54.015Z"
|
|
}
|
|
``` |