Building a Parametric Model with Sketches, Geometry, Variables, and Dimensioning in Altair Inspire
Building a Parametric Model with Sketches, Geometry, Variables, and Dimensioning in Altair Inspire.
To make a sketch entity parametric in Altair Inspire, you need to add dimensions to the sketch and assign model variables to those dimensions. This allows the entity to be driven by variables, enabling flexible adjustments. Below is a code snippet demonstrating how to create a parametric rectangular sketch by adding dimensions and assigning variables:
How to Create a rectangular cross sections using Sketch APIs
#Rectangular section. from hwx import inspire # Create a new model model = inspire.newModel() # How to query an existing model model = inspire.getModel() # Create a new sketch in the 'Global Z' plane sketch = inspire.Sketch('Global Z') # Create a new sketch in the 'Global Y' plane #sketch = inspire.Sketch('Global Y') # Create a new sketch in the 'Global X' plane #sketch = inspire.Sketch('Global X') # Define the dimensions in meters (8mm = 0.008m, 4mm = 0.004m) width = 0.008 # 8 mm height = 0.004 # 4 mm # Add rectangle for the cross-section rectangleFeatures = sketch.addRectangle2Vertex((0, 0), (width, height)) #How to make rectangular sketch into parametric sketch # get the lines features from the rectangular object. lineslist = rectangleFeatures[-1] #Add dimensions to the first line c1 = sketch.addDimension(dimension=sketch.CONSTRAINT_DISTANCE_HORIZONTAL,item1=lineslist[0],value=0.008) #create model variables model.variables.add("width", type="length", expression=0.008) #Add variables to the dimensions sketch.setDimensionVariable(c1, "width ") #create model variables model.variables.add("height", type="length", expression=0.004) #Add dimensions to the second line c2=sketch.addDimension(dimension=sketch.CONSTRAINT_DISTANCE_HORIZONTAL,item1=lineslist[1],value=0.004) #Add variables to the dimensions sketch.setDimensionVariable(c2, "height ") sketchpart = sketch.realize() # Realize the sketch
Once the sketch object is realized, it returns a sketchPart that contains essential features like points, lines, curves, and areas, which define the shape of the sketch. To convert the 2D sketch into a 3D model, these features must be retrieved from the sketchPart and used in geometry functions, such as extrude, pushPull, sweep, or pipe, etc. to generate the final 3D shape.
#how to retrieve area feature from a sketch part. #getFeatures returns you list of area feature. areaFeature = sketchpart .getFeatures('FeatureArea') # finding the largest area feature from the realized sketch part. largestfeature = max(sketchpart.getFeatures(type = 'FeatureArea'), key=lambda f: f.area, default=None) # finding the largest area feature from the realized sketch part. smallestfeature = min(sketchpart.getFeatures(type = 'FeatureArea'), key=lambda f: f.area, default=None) #create model variables model.variables.add("depth", type="length", expression=0.06) # How to extrude or pushpull this area feature # We can add model variables directly the geometry function part = inspire.geometry.extrude(features=smallestfeature ,direction= "SINGLE", resultType="NEW_PART", extrudeTo1='depth') # How to extrude or pushpull this area feature #part = inspire.geometry.pushPull(feature=smallestfeature , depth='depth')
How to Create a circular cross sections using Sketch APIs
# Circular section from hwx import inspire # Create a new model model = inspire.newModel() # How to query an existing model model = inspire.getModel() # Create a new sketch in the 'Global Z' plane sketch = inspire.Sketch('Global Z') # Create a new sketch in the 'Global Y' plane #sketch = inspire.Sketch('Global Y') # Create a new sketch in the 'Global X' plane #sketch = inspire.Sketch('Global X') # Define the dimensions in meters (10 mm diameter) diameter= 0.010 # 10 mm radius = diameter/2 center = (0,0) # Add rectangle for the cross-section circularfeats= sketch.addCircleCenterRadius(center , radius ) #adding dimention tho the circle sketch c3 = sketch.addDimension(dimension=sketch.CONSTRAINT_DIAMETER_VERTICAL, value=diameter, item1=circularfeats) #adding variable to the model model.variables.add(name='diameter', type='l', expression=diameter) # Adding the variable to the created dimension object c3 sketch.setDimensionVariable(c3, "diameter") # creating a variable to constraint hole position sketchpart = sketch.realize() # Realize the sketch #how to retrieve area feature from a sketch part. #getFeatures returns you list of area feature. areaFeature = sketchpart .getFeatures('FeatureArea') # finding the largest area feature from the realized sketch part. largestfeature = max(sketchpart.getFeatures(type = 'FeatureArea'), key=lambda f: f.area, default=None) # finding the largest area feature from the realized sketch part. smallestfeature = min(sketchpart.getFeatures(type = 'FeatureArea'), key=lambda f: f.area, default=None) # How to extrude or pushpull this area feature part = inspire.geometry.extrude(features=largestfeature ,direction= "SINGLE", resultType="NEW_PART", extrudeTo1=0.04) # How to extrude or pushpull this area feature #part = inspire.geometry.pushPull(feature=largestfeature, depth=0.04) # How to find a smallest area feature on a extruded part smallestPartAreafeature = min(part.getFeatures(type = 'FeatureArea'), key=lambda f: f.area, default=None) # How to find a smallest Circular feature on a extruded part smallestPartCircularfeature = min(part.getFeatures(type = 'FeatureCircular'), key=lambda f: f.length, default=None) # How to find a largest Circular curve feature on a extruded part largestPartCircularfeature = max(part.getFeatures(type = 'FeatureCircular'), key=lambda f: f.length, default=None)
How add support and force boundary condition to part's area feature
Whenever a boundary condition is created then it should be added to a loadcase so that it can be used in while analysis the effect of loads and support.
#How to apply support or constraint on the smallest area feature smallestPartAreafeature = min(part.getFeatures(type = 'FeatureArea'), key=lambda f: f.area, default=None) support = inspire.Constraint(smallestPartAreafeature , loadCase='current') #How to apply Force on one of the area feature Areafeature = part.getFeatures(type = 'FeatureArea') #Creating a force on with the direction of -Y and magnitude of -10 N inspire.Force(Areafeature [-1], magnitude=-10.0, loadCase='current', direction=[0,-1,0]) inspire.fitView()