Hands-On Guide to Modifying 3D Models: Fillet, Chamfer, Partition, Shell, and Scale Techniques
Introduction
In this guide, we will explore practical techniques for modifying 3D models using Altair Inspire's Python API. We'll focus on five key operations: Partition, Fillet, Chamfer, Shell, and Scale. Each operation plays a crucial role in modifying and adapting your 3D designs.
Before applying any geometric operations like partitioning, it's important to set up parameters that will drive your model. Altair Inspire offers the capability to introduce variables into your model, providing flexible and precise control over dimensions and other aspects of your design.
Adding Variables
from hwx import inspire #if you don't have a model you can open one from Tutorial path. #inspire.openTutorialFile("Structures/base.x_t") # Get the active model from Inspire model = inspire.getModel() # Add new variables to the model model.variables.add("partitionThickness", type="length", expression='3 cm') model.variables.add("scaleFactor", type="unitless", expression=10) model.variables.add("draftAngle", type="angle", expression='30 deg')
Here, we define three variables:
- partitionThickness: Controls the thickness of partitions.
- scaleFactor: Used to scale features uniformly.
- draftAngle: Defines the angle for draft features.
In Inspire, you can pass values directly as strings (e.g., '1 cm', '5 inch', '7 ft', '10 mm') or use previously defined variables like partitionThickness. You can also use float or integer values, which default to meters.
1. Partition
Definition: Divide a solid part into design and non-design regions by selecting a hole, pocket, or face to offset.
You can perform partitioning in several ways using Inspire's API.
1 a. Partitioning Using Features
You can partition features in your model by specifying their type and parameters. Here's how to apply partitions to cylindrical features:
# Option 1: Partition cylindrical features features = model.getFeatures(type='FeatureCylindrical') # Apply partition with defined thickness for feature in features: feature.partition(thickness="partitionThickness", reverseDirection=False)
In this method, we retrieve cylindrical features and apply the partition operation using the partitionThickness variable. The reverseDirection argument controls whether the partitioning direction is reversed.
1 b. Using a List of Features
You can also create partitions using a list of features, which allows for batch processing:
# Option 2: Create a list of features for partitioning features = model.getFeatures(type='FeatureCylindrical') listOfFeatureList = [[i] for i in features] # Partition using a thickness value and reverse direction inspire.geometry.partition(listOfFeatureList, thickness=0.03, reverseDirection=True)
1 c. Partitioning Based on Size Range
To partition features based on size constraints, use the following approach:
# Option 3: Partition based on size constraints inspire.geometry.partition(model, thickness="partitionThickness", minSize=0, maxSize=1, reverseDirection=False)
1 d. Editing Partition Construction Features
Once you've created partitions, you might need to modify their properties. Editing partition construction features allows you to adjust parameters such as thickness or direction even after the initial partitioning.
Here's how to edit an existing partition feature:
# Retrieve the most recent partition construction feature partitionCF = model.construction[-1] # Edit the partition thickness and direction partitionCF.edit(partitionOptions=['3 mm', False]) # If needed, retrieve and further modify a specific partition feature partitionCF = model.construction.getCF('Partition 1') partitionCF.edit(partitionOptions=['partitionThickness', True])
This approach provides flexibility in adjusting partitions to meet evolving design requirements
1 e. Updating Variables
You can dynamically update the variables to adjust your partitions:
# Update the partition thickness variable model.variables.update("partitionThickness", 'Length', "5 cm")
By updating partitionThickness, you can modify the partition thickness across the entire model.
2. Fillet (Edge Fillet)
Definition: Round edges to create fillets with a constant or variable radius.
2 a. Retrieve and Apply Fillet to Features
Next, retrieve the features in your model that you want to apply the fillet to. In this example, we apply the fillet to circular features.
# Get circular features from the model features = model.getFeatures(type=inspire.FeatureCircular) # Apply the fillet operation using the defined radius for feature in features: inspire.geometry.edgeFillet(feature, radius='filletRadius')
#Retrieving edge features features =model.getFeatures(type= 'FeatureLinear') # Applying fillet on four edge feature. inspire.geometry.edgeFillet(features[:4], radius='30 cm') # #Retrieving edge features features = model.getFeatures(type=inspire.FeatureLinear) # Tangent Propagation: Edges that are connected and tangent to each other will be included in the fillet operation. inspire.geometry.edgeFillet(features[9], radius='3 cm',tangentPropagation=True, continuity='CURVATURE') # continuity can be TANGENT or CURVATURE.
2 b. Retrieve the Existing Fillet CF by name
Access the specific fillet construction feature you want to modify. You can retrieve it by its name.
# Retrieve the fillet construction feature filletCF = model.construction.getCF('Fillet 1')
2 c. Modify the Fillet Parameters
Update the radius or other properties of the fillet feature as needed. Use the edit method to apply changes.
# Editing existing CF filletCF=model.construction.getCF('Fillet 1') with filletCF.edit(): filletCF.radius = '4 cm' filletCF.continuity='TANGENT'
3. Chamfer
Create beveled edges.
There are two methods to create chamfer,
- Chamfering by Angle - needs one angle and one distance
- Chamfering by Distance - needs two distance
Retrieve the features in your model that you want to apply the chamfer to. In this example, we apply the chamfer to linear features.
# Creating variables model.variables.add("chamferAngle", 'angle', "45 deg") model.variables.add("chamferDist", 'length', 0.03) #Retrieving edge features features =model.getFeatures(type= 'FeatureLinear') # Applying fillet on four edge feature. inspire.geometry.edgeFillet(features[:4], radius='30 cm') # #Retrieving edge features features = model.getFeatures(type=inspire.FeatureLinear) inspire.geometry.chamferByAngle(features[9], angle= 'chamferAngle', dist='chamferDist') inspire.geometry.chamferByDistance(features[10], dist1= 'chamferDist', dist2='chamferDist') # Editing the Chamfer construction feature to redefine the the angle and distance value. chamferCF = model.construction.getCF('Chamfer 1') with chamferCF.edit(): model.variables.add("angle", type="angle", expression=60) model.variables.add("distance", type="length", expression=0.05) chamferCF.angleAndDistance=["angle", "distance"]
4. Shell
Definition: Remove material and create thin walls to generate a shelled part.
from hwx import inspire model = inspire.getModel() parts=model.parts featPlanar=model.parts[0].getFeatures(type='FeaturePlanar')[5] featPlanar.shell(thickness=.5) print("Shell is created on base part with the thickness of 0.5mm") inspire.orientView(direction="isometric") # Editing the Shellconstruction feature to redefine the thickness value. shellCF= model.construction.getCF('Shell 1') with shellCF.edit(): # creating a variable for scale factor model.variables.add('thickness','length','10 cm') shellCF.thickness= 'thickness'
5. Scale
Definition: Resize parts in your model, which is useful when working with an imported model that is associated with a different default unit system.
from hwx import inspire model=inspire.getModel() part=model.parts[0] part.scale(2.0) print("Part is scaled by factor 2") inspire.fitView() # Editing the scale construction feature to redefine the scale value. scaleCF= model.construction.getCF('Scale 1') with scaleCF.edit(): # creating a variable for scale factor model.variables.add('scaleFactor','unitless',10) scaleCF.value = 'scaleFactor'