Parametric Modeling in Altair Inspire: Extruding A Fully Constrained Sketch
Introduction to Parametric Modeling
Parametric modeling allows designers to define relationships between different elements of a model through variables, constraints, and dimensions. This approach allows the user to change the dimensions of one element, and automatically adjust other elements that depend on it. The beauty of this method is that it provides flexibility for quick iterations and design changes without manual adjustments.
In this example, we will create a flange and add circular holes around its annular region, all controlled by parametric variables. Finally, we will position grounded fasteners in the aligned holes between two flanges.
We start by importing the necessary libraries. The math library will help in calculating positions using trigonometry, and inspire is the core library from Altair for handling sketch, geometry and model-related operations.
import math from hwx import inspire model = inspire.getModel()
Here, we define key dimensions of the flange, including its outer diameter, inner diameter, hole size, and the number of holes to be created in the annular region. These dimensions will be used in our parametric model.
# Define the dimensions of the flange outer_dia = 3.0 # outer diameter in meters inner_dia = 1.5 # inner diameter in meters hole_dia = 0.1 # diameter of the circular holes in meters at Annulus num_holes = 6 # number of holes
Step 1: Creating the First Flange Sketch
# Create the first flange sketch sketch1 = inspire.Sketch() # Draw the outer circle of the first flange outer_circle_center = (0, 0) outer_circle_radius = outer_dia / 2 #getting the sketch origin point origin = sketch1.origin() #Creating a circle using center and radius g1 = sketch1.addCircleCenterRadius(center=outer_circle_center, radius=outer_circle_radius) #Diameter controlled by parametric variable #Creating a dimension for g1 circle object c1 = sketch1.addDimension(dimension=sketch1.CONSTRAINT_DIAMETER_VERTICAL, value=outer_dia, item1=g1) #Adding concentric constraint between origin and g1 circle object sketch1.addConstraint(constraint=sketch1.CONSTRAINT_CONCENTRIC, item2=origin, item1=g1) # Creating a variable model.variables.add(name='outer_dia', type='l', expression=outer_dia) # Adding the variable to the created dimension on c1 circle object sketch1.setDimensionVariable(c1, "outer_dia") # Draw the inner circle of the first flange inner_circle_radius = inner_dia / 2 g2 = sketch1.addCircleCenterRadius(center=outer_circle_center, radius=inner_circle_radius) #Diameter controlled by parametric variable #Creating a dimension object for g2 circle c2 = sketch1.addDimension(dimension=sketch1.CONSTRAINT_DIAMETER_VERTICAL, value=inner_dia, item1=g2) #Adding concentric constraint between origin and g2 circle object sketch1.addConstraint(constraint=sketch1.CONSTRAINT_CONCENTRIC, item2=origin, item1=g2) # Creating a variable model.variables.add(name='inner_dia', type='l', expression=inner_dia) # set the Dimension Variable inner_dia on c2 dimension object sketch1.setDimensionVariable(c2, "inner_dia")
step 2: Creating annular hole and adding dimensions and constraints to it.
# Define positions for the circular holes on the annulus hole_radius = hole_dia / 2 model.variables.add(name='hole_dia', type='l', expression="(outer_dia - inner_dia) / 8") # Calculate the position for the holes on the annular region angle = 0 hole_x = (outer_circle_radius + inner_circle_radius) / 2 * math.cos(angle) hole_y = (outer_circle_radius + inner_circle_radius) / 2 * math.sin(angle) hole_positions = (hole_x, hole_y) #Creating a circle at the annular region g3 = sketch1.addCircleCenterRadius(center=hole_positions, radius=hole_radius) #Creating a dimension object for g3 circle and settomg the Dimension Variable hole_dia on c3 dimension object c3 = sketch1.addDimension(dimension=sketch1.CONSTRAINT_DIAMETER_VERTICAL, value=(outer_dia - inner_dia) / 4, item1=g3) # Adding the variable to the created dimension object c3 sketch1.setDimensionVariable(c3, "hole_dia") # creating a variable to constraint hole position model.variables.add(name='holeDistance', type='l', expression="( outer_dia/2+ inner_dia/2) / 2") # Add a dimension constraint between origin andf circle g3. c4 = sketch1.addDimension(dimension=sketch1.CONSTRAINT_DISTANCE_ALIGNED, item1=origin, item2=g3, value= hole_x) # Adding the variable to c4 dimension sketch1.setDimensionVariable(c4, "holeDistance") # Align the the circle center and origin horizontally sketch1.addDimension(dimension=sketch1.CONSTRAINT_HORIZONTAL_POINTS, item1=origin, item2=g3)
step 3: Creating pattern along the annular area
#Creating unitless variable 'num_holes' model.variables.add(name='num_holes', type='unitless', expression=num_holes) # Sketch circular pattern take angle as radian radians = math.radians(360) # Sketch - circular patterning the holes pattern = sketch1.circularPattern(entities=g3, point=origin, copy=num_holes, angle=radians, symmetry=False, createDimension=True, equalSpacing=True) pattern.copy = 'num_holes'
step 4: Realizing the sketch object.
sketchpart1 = sketch1.realize()
The sketch is extruded to create a 3D flange part. The thickness of the flange is defined as a parametric variable thickness.
When a sketch is realized, it transforms into a sketch part that contains features such as points, lines, curves and areas, which define the shape and topology of the sketch part. To convert this 2D sketch into a 3D part, we extrude the area feature from the realized sketch part.
We can retrieve the features of the sketch part, such as points, lines, and areas, by calling the getFeatures method on the realized sketch part. This method returns a list of features, enabling us to interact with the individual features. However, it’s important to note that point features cannot be extruded.
step 5: Creating a parametric extrude
# finding the largest area feature from the realized sketch part. largestfeature = max(sketchpart1.getFeatures(type = 'FeatureArea'), key=lambda f: f.area, default=None) thickness = 0.05 model.variables.add(name='thickness', type='l', expression=thickness) flange1 = inspire.geometry.extrude(features=largestfeature, direction='SINGLE', resultType='New_PART', extrudeTo1='thickness')
step 6: Creating second flange and moving it on top of flange 1.
#Creating another flange flange2 = inspire.geometry.extrude(features=largestfeature, direction='SINGLE', resultType='New_PART', extrudeTo1='thickness') #moving the second flange on top of first flange flange2.translate(x=0, y=0, z=thickness)
Step 7: Adding Grounded Fasteners to aligned holes
model = inspire.getModel() holes = model.holes #Creating a loadcase object for fasteners loadcaseSupports = inspire.LoadCase(name="Grounded Fasteners") for aligned_holes in model.holes.aligned: # We only add fasteners on the annular area ie; hole radius lesser than 0.5*inner_dia if aligned_holes[0][0].radius < 0.5*inner_dia: #creating fasteners. inspire.Fastener(aligned_holes, color="green", type='Screw', loadCase=loadcaseSupports) #allowed Fasteners types are Nut and Bolt, Grounded Bolt, Screw, Grounded Screw
inspire.fitView() Adjust the viewport to automatically fit the entire model within the view. This ensures that the full geometry of the model is visible on the screen after any modifications, such as creating or moving parts. It enhances the user experience by centering and scaling the view to the model's dimensions, making it easier to inspect and interact with the model.
# fit the view to the model inspire.fitView()
Step 8 : Updating Parametric Variables in an Existing Model
from hwx import inspire model = inspire.getModel() # Update the parametric variable 'outer_dia' to a new value model.variables.update(name='outer_dia', type='length', expression='6 m') #Forcing the the recompute model.construction.rollTo(0) model.construction.rollTo(-1) # Update the 'inner_dia' variable based on the new outer_dia value model.variables.update(name='inner_dia', type='length', expression='outer_dia/2') inspire.fitView()
step 9: How to create Joint
#Creating a loadcase object for Joint loadcaseSupports = inspire.LoadCase(name="Grounded Joint") for aligned_holes in model.holes.aligned: # We only add Jointon the annular area ie; hole radius lesser than 0.5*inner_dia if aligned_holes[0][0].radius < 0.5*inner_dia: #creating grounded Joint. joint = inspire.Joint(aligned_holes,type ='Grounded Sliding Pin', color="green") joint.type = 'Pin' #Allowed types are Pin, Grounded Pin, Sliding Pin, Grounded Sliding Pin, Ball and Socket
Comments
-
I appreciate your post, but it should be accompanied by images of the results of each part of code.
0