Parametric Modeling in Altair Inspire: A Step-by-Step Guide

Karthi Kandasamy
Karthi Kandasamy
Altair Employee
edited September 16 in Altair HyperWorks

Preface: Understanding Parametric Modeling

Parametric modeling is a powerful CAD technique that enables designers to create models defined by parameters or constraints. These parameters—such as dimensions, distances, and angles—drive the geometry of the design. The beauty of parametric modeling lies in its flexibility: by modifying a parameter, the entire model updates automatically, ensuring faster iterations and seamless design adjustments.

This method is particularly valuable in engineering and manufacturing, where designs often undergo revisions and optimizations. Parametric models maintain consistency across the entire design, allowing changes to propagate without needing to rebuild the model from scratch. This results in greater efficiency, especially when working on complex systems where components need to align and interact perfectly.

 

Example: Creating a Parametric Sketch in Inspire

 

Let’s dive into an example of creating a parametric sketch in Inspire using Python scripting:

from hwx import inspire  # Get the active model from the inspire module model = inspire.getActiveModel()  # Create a new sketch in the 'Global Z' plane sketch = inspire.Sketch('Global Z')  # Points g1 = sketch.origin()  # Origin point of the sketch  g6 = sketch.addPoint(0.5, 0)  # Add point at (0.5, 0) g12 = sketch.addPoint(0.5, 0.4)  # Add point at (0.5, 0.4) g17 = sketch.addPoint(0, 0.4)  # Add point at (0, 0.4)  g31 = sketch.addPoint(0.1, 0.1)  # Add point at (0.1, 0.1) g35 = sketch.addPoint(0.1, 0.3)  # Add point at (0.1, 0.3) g39 = sketch.addPoint(0.4, 0.3)  # Add point at (0.4, 0.3) g43 = sketch.addPoint(0.4, 0.1)  # Add point at (0.4, 0.1)  # Geometry g7 = sketch.addLineSegment(g1, g6)  # Add line segment between g1 and g6 g13 = sketch.addLineSegment(g6, g12)  # Add line segment between g6 and g12 g18 = sketch.addLineSegment(g12, g17)  # Add line segment between g12 and g17 g23 = sketch.addLineSegment(g17, g1)  # Add line segment between g17 and g1  g30 = sketch.addCircleCenterRadius(g31, 0.0500000000)  # Add circle with center g31 and radius 0.05 g34 = sketch.addCircleCenterRadius(g35, 0.0500000000)  # Add circle with center g35 and radius 0.05 g38 = sketch.addCircleCenterRadius(g39, 0.0500000000)  # Add circle with center g39 and radius 0.05 g42 = sketch.addCircleCenterRadius(g43, 0.0500000000)  # Add circle with center g43 and radius 0.05

Defining Constraints and Variables

To make the sketch parametric, constraints are applied to the geometry. Constraints like horizontal, vertical, and perpendicular ensure that the geometry remains aligned and behaves predictably. Additionally, dimensions between points are set using variables, which can be easily modified.

# Constraints  c10 = sketch.addConstraint(sketch.CONSTRAINT_HORIZONTAL, g7)  # Make g7 horizontal c16 = sketch.addConstraint(sketch.CONSTRAINT_VERTICAL, g13)  # Make g13 vertical c21 = sketch.addConstraint(sketch.CONSTRAINT_HORIZONTAL, g18)  # Make g18 horizontal c27 = sketch.addConstraint(sketch.CONSTRAINT_PERPENDICULAR, g23, g18)  # Make g23 perpendicular to g18  # Adding horizontal dimension c28 = sketch.addDimension(sketch.CONSTRAINT_DISTANCE_HORIZONTAL, 0.5000000000, g1, g6, 0.2531323297, -0.1262448281) model.variables.add(name="L1", type="l", expression="0.5 m") sketch.setDimensionVariable(c28, "L1")  # Adding vertical dimension c29 = sketch.addDimension(sketch.CONSTRAINT_DISTANCE_VERTICAL, 0.4000000000, g6, g12, 0.8039846420, 0.2235822231) model.variables.add(name="L2", type="l", expression="0.5*L1") sketch.setDimensionVariable(c29, "L2")  # Adding alighed dimension  c70 = sketch.addDimension(sketch.CONSTRAINT_DISTANCE_ALIGNED, 0.1000000000, g30, g7, 1.0526938438, 0.3335237801) sketch.setDimensionVariable(c70, "L3") c71 = sketch.addDimension(sketch.CONSTRAINT_DISTANCE_ALIGNED, 0.1000000000, g30, g23, 0.4224123359, 0.4851704538) sketch.setDimensionVariable(c71, "L3")  c72 = sketch.addDimension(sketch.CONSTRAINT_DISTANCE_ALIGNED, 0.1000000000, g34, g18,0.7162277699, 0.0713013932) sketch.setDimensionVariable(c72, "L3") c73 = sketch.addDimension(sketch.CONSTRAINT_DISTANCE_ALIGNED, 0.1000000000, g34, g23,0.4162288308, -0.0681072623) sketch.setDimensionVariable(c73, "L3")  c74 = sketch.addDimension(sketch.CONSTRAINT_DISTANCE_ALIGNED, 0.1000000000, g38, g18, -0.3058076501, 0.1234299392) sketch.setDimensionVariable(c74, "L3") c75 = sketch.addDimension(sketch.CONSTRAINT_DISTANCE_ALIGNED, 0.1000000000, g38, g13, -0.2805332541, 0.2877138555) sketch.setDimensionVariable(c75, "L3")  c76 = sketch.addDimension(sketch.CONSTRAINT_DISTANCE_ALIGNED, 0.1000000000, g42, g7,0.5740590096, 0.2971917689) sketch.setDimensionVariable(c76, "L3") c77 = sketch.addDimension(sketch.CONSTRAINT_DISTANCE_ALIGNED, 0.1000000000, g42, g13, 0.5930148363, 0.1092130691) sketch.setDimensionVariable(c77, "L3") 

Leveraging Parametric Variables

In this example, the variables L1 and L2 are created to control the dimensions of the sketch. These variables allow the modeler to define the distances between key points parametrically. A more advanced use is seen with variable L3, which is defined as a function of L1 and L2.

# Diameter controlled by parametric variable c33 = sketch.addDimension(sketch.CONSTRAINT_DIAMETER_VERTICAL, 0.100000, g30, None, -0.2175943255, 0.1040733513) model.variables.add(name="L3", type="l", expression="0.1*L1") sketch.setDimensionVariable(c33, "L3")  c34 = sketch.addDimension(sketch.CONSTRAINT_DIAMETER_VERTICAL, 0.100000, g34, None, 0.2175943255, 0.1040733513) sketch.setDimensionVariable(c34, "L3")  c35 = sketch.addDimension(sketch.CONSTRAINT_DIAMETER_VERTICAL, 0.100000, g38, None, -0.2175943255, 0.1040733513) sketch.setDimensionVariable(c35, "L3")  c36 = sketch.addDimension(sketch.CONSTRAINT_DIAMETER_VERTICAL, 0.100000, g42, None, 0.2175943255, 0.1040733513) sketch.setDimensionVariable(c36, "L3")

Realizing the Sketch

The sketch is updated and realized to solidify the changes and create a fully functional parametric model. The realize method finalizes the sketch and commits the parametric constraints.

# Update and realize the sketch sketch.update() sketchPart = sketch.realize()  # Note the state of the sketch construction in the history inspire.History.noteState("sketch constructed") 

Extruding the Sketch

Now that the sketch is realized, it’s time to extrude it into a 3D shape. The pushPull or extrude functions can be used to transform the 2D sketch into a 3D model, with the largest area feature being extruded based on the L3 variable.

# Get the area features from the realized sketch part featsArea = sketchPart.getFeatures(type='FeatureArea')  # Find the largest area feature largestAreaFeature = [i for i in featsArea if max([i.area for i in featsArea]) == i.area][0]  # Perform a push-pull operation on the largest area feature #option-1 : Converting 2D sketch to 3D   part = inspire.geometry.pushPull(largestAreaFeature,'L3')  #option-2 : Converting 2D sketch to 3D # Instead of pushPull API we can use extrude function too.  # Perform extrusion on the largest area feature using the 'extrude' function #part = inspire.geometry.extrude(features=largestAreaFeature, direction='SINGLE', resultType='NEW_PART', extrudeTo1='L3')

Parametrically Driving the Model with Variables

One of the most powerful aspects of parametric modeling is the ability to dynamically control and modify the geometry by updating the associated variables. By simply changing a variable, you can reshape the entire model without having to manually adjust its geometry.

For example, to update the length of a sketch driven by the variable L1, you can use the following command:

# Update the variable L1 to a new value model.variables.update("L1", 'Length', "200 cm")  #fits the model to the screen inspire.fitView() 

Conclusion

This example illustrates the power of parametric modeling within Inspire. By defining dimensions and constraints with variables, the model becomes flexible, enabling rapid adjustments to the design. This approach significantly speeds up the design process and ensures consistency across the model, as changes are easily propagated through the design.

Happy Scripting!