Creating 3D Implicit Primitives with Altair Inspire: A Python Approach
Create an Implicit Primitive
Create simple geometric shapes that can be used for repetitive tasks or combined into more complex shapes. Implicit primitives include a cuboid, cylinder, and sphere.
Implicit Primitive Shapes are,
- Cuboid
- Cylinder
- Sphere
- Torus
- Cone
- Pipe
- Capsule
- Pellet
Each primitive can be controlled through parameters such as position and dimensions. Let's dive into how to create these primitives and their parametric counterparts.
Create Implicit Cuboid
from hwx import inspire model = inspire.newModel() # Creating Implicit blank part. implicitPart = inspire.Implicit() implicitPart.name = "Implicit Part1" inspire.fitView() print("New Implicit part added in the model: ", model.parts[0]) # Creating Cuboid primitive in implicit part. cuboid = implicitPart.createCuboid(x="100 mm", uniform=True) inspire.fitView() print("New Cuboid has been added in Implicit Part1.") # Updating Implicit Cuboid. with implicitPart.edit(): cuboid.y = "200 mm" inspire.fitView() print("Implicit Cuboid has been updated with new values.")
Create parametric Implicit Cuboid
A cuboid (or rectangular box) can be defined with x, y, and z dimensions. You can set these dimensions directly or through parametric variables.
from hwx import inspire model = inspire.newModel() # Creating Implicit blank part. implicitPart = inspire.Implicit() implicitPart.name = "Implicit Part1" inspire.fitView() print("New Implicit part added in the model: ", model.parts[0]) # creating variable to make parametric implicit Cuboid . model.variables.add("length", type="length", expression="200 mm") model.variables.add("width", type="length", expression="200 mm") model.variables.add("height", type="length", expression="300 mm") model.variables.add("posX", type="length", expression='0.05 m') model.variables.add("posY", type="length", expression='0.05 m') model.variables.add("posZ", type="length", expression='0.05 m') # Creating parametric Cuboid primitive in implicit part. cuboid = implicitPart.createCuboid(x="length", y="width", z="height", uniform=False, originX="posX", originY="posY", originZ="posZ") inspire.fitView() print("New Cuboid has been added in Implicit Part1.") # Modify the parametric variable to change the cuboid shape model.variables.update("length", type="length", expression="100 mm") #similarly other variables of the Cuboid primitive can be changed. model.variables.update("height", type="length", expression="100 mm") #similarly position variables of the Cuboid primitive can be changed. model.variables.update("posY", type="length", expression="100 mm")
Here, the cuboid dimensions are driven by variables, which can be updated to modify the cuboid shape without editing the geometry directly.
Create Implicit Cylinder
A cylinder is defined by its radius and height.
from hwx import inspire model = inspire.newModel() # Creating Implicit blank part. implicitPart = inspire.Implicit() implicitPart.name = "Implicit Part1" inspire.fitView() print("New Implicit part added in the model: ", model.parts[0]) # Creating Cylinder primitive in implicit part. cylinder = implicitPart.createCylinder(radius="200 mm", height="500 mm") inspire.fitView() print("New Cylinder has been added in Implicit Part1.") # Updating Implicit Cylinder. with implicitPart.edit(): cylinder.height = "800 mm" inspire.fitView() print("Implicit Cylinder has been updated with new values.")
Create parametric Implicit Cylinder
Similarly, we can control the cylinder’s radius and height through variables.
from hwx import inspire model = inspire.newModel() # Creating Implicit blank part. implicitPart = inspire.Implicit() implicitPart.name = "Implicit Part1" inspire.fitView() print("New Implicit part added in the model: ", model.parts[0]) # creating variable to make parametric implicit Cylinder. model.variables.add("radius", type="length", expression="200 mm") model.variables.add("height", type="length", expression="500 mm") model.variables.add("posX", type="length", expression='0.05 m') model.variables.add("posY", type="length", expression='0.05 m') model.variables.add("posZ", type="length", expression='0.05 m') # Creating parametric Cylinder primitive in implicit part. cylinder = implicitPart.createCylinder(radius="radius", height="height", originX="posX", originY="posY", originZ="posZ") inspire.fitView() print("New Cylinder has been added in Implicit Part1.") # Modify the parametric variable to change the cylinder shape model.variables.update("height", type="length", expression="100 mm") #similarly other variables of the cylinder primitive can be changed. model.variables.update("radius", type="length", expression="100 mm") #similarly position variables of the cylinder primitive can be changed. model.variables.update("posZ", type="length", expression="100 mm")
Create Implicit Sphere
A sphere is defined by its radius.
from hwx import inspire model = inspire.newModel() # Creating Implicit blank part. implicitPart = inspire.Implicit() implicitPart.name = "Implicit Part1" inspire.fitView() print("New Implicit part added in the model: ", model.parts[0]) # Creating Sphere primitive in implicit part. sphere = implicitPart.createSphere(radius="200 mm") inspire.fitView() print("New Sphere has been added in Implicit Part1.") # Updating Implicit Sphere. with implicitPart.edit(): sphere.radius = "500 mm" # Updating Implicit Sphere with variables. model.variables.add("radius", type="length", expression="800 mm") with implicitPart.edit(): sphere.radius = "radius" inspire.fitView() print("Implicit Sphere has been updated with new values.")
Create parametric Implicit Sphere
We can also control the radius of a sphere through parametric variables.
from hwx import inspire model = inspire.newModel() # Creating Implicit blank part. implicitPart = inspire.Implicit() implicitPart.name = "Implicit Part1" inspire.fitView() print("New Implicit part added in the model: ", model.parts[0]) # creating variable to make parametric implicit Sphere. model.variables.add("radius", type="length", expression="200 mm") model.variables.add("posX", type="length", expression='0.05 m') model.variables.add("posY", type="length", expression='0.05 m') model.variables.add("posZ", type="length", expression='0.05 m') # Creating parametric Sphere primitive in implicit part. sphere = implicitPart.createSphere(radius="radius",originX="posX", originY="posY", originZ="posZ") inspire.fitView() print("New Sphere has been added in Implicit Part1.") # Modify the parametric variable to change the cylinder shape #variable of the sphere primitive can be changed. model.variables.update("radius", type="length", expression="100 mm") #similarly position variables of the cylinder primitive can be changed. model.variables.update("posZ", type="length", expression="100 mm")
Create Implicit Torus
A torus (doughnut-shaped object) requires inner and outer radius definitions.
from hwx import inspire model = inspire.newModel() # Creating Implicit blank part. implicitPart = inspire.Implicit() implicitPart.name = "Implicit Part1" inspire.fitView() print("New Implicit part added in the model: ", model.parts[0]) # Creating Torus primitive in implicit part. torus = implicitPart.createTorus(innerRadius="300 mm", outerRadius="500 mm") inspire.fitView() print("New Torus has been added in Implicit Part1.") # Updating Implicit Torus. with implicitPart.edit(): torus.innerRadius = "200 mm" inspire.fitView() print("Implicit Torus has been updated with new values.")
Create parametric Implicit Torus
Using variables for the inner and outer radii allows for dynamic torus creation.
from hwx import inspire model = inspire.newModel() # Creating Implicit blank part. implicitPart = inspire.Implicit() implicitPart.name = "Implicit Part1" inspire.fitView() print("New Implicit part added in the model: ", model.parts[0]) # creating variable to make parametric implicit Torus. model.variables.add("innerRadius", type="length", expression="200 mm") model.variables.add("outerRadius", type="length", expression= "500 Mm") model.variables.add("posX", type="length", expression='0.05 m') model.variables.add("posY", type="length", expression='0.05 m') model.variables.add("posZ", type="length", expression='0.05 m') # Creating parametric Torus primitive in implicit part. torus = implicitPart.createTorus(innerRadius="innerRadius", outerRadius="outerRadius", originX="posX", originY="posY", originZ="posZ") inspire.fitView() print("New Torus has been added in Implicit Part1.") # Modify the parametric variable to change the Torus shape model.variables.update("innerRadius", type="length", expression="100 mm") #similarly other variables of the Torus primitive can be changed. model.variables.update("outerRadius", type="length", expression="600 mm") #similarly position variables of the Torus primitive can be changed. model.variables.update("posZ", type="length", expression="100 mm")
Create Implicit Cone
A cone is defined by its base radius and height.
from hwx import inspire model = inspire.newModel() # Creating Implicit blank part. implicitPart = inspire.Implicit() implicitPart.name = "Implicit Part1" inspire.fitView() print("New Implicit part added in the model: ", model.parts[0]) # Creating Cone primitive in implicit part. cone = implicitPart.createCone(radius="200 mm", height="500 mm") inspire.fitView() print("New Cone has been added in Implicit Part1.") # Updating Implicit Cone. with implicitPart.edit(): cone.height = "800 mm" inspire.fitView() print("Implicit Cone has been updated with new values.")
Create parametric Implicit Cone
We can define the cone’s radius and height using variables.
from hwx import inspire model = inspire.newModel() # Creating Implicit blank part. implicitPart = inspire.Implicit() implicitPart.name = "Implicit Part1" inspire.fitView() print("New Implicit part added in the model: ", model.parts[0]) # creating variable to make parametric implicit Cone. model.variables.add("radius", type="length", expression="200 mm") model.variables.add("height", type="length", expression= "500 Mm") model.variables.add("posX", type="length", expression='0.05 m') model.variables.add("posY", type="length", expression='0.05 m') model.variables.add("posZ", type="length", expression='0.05 m') # Creating parametric Cone primitive in implicit part. cone = implicitPart.createCone(radius="200 mm", height="500 mm", originX="posX", originY="posY", originZ="posZ") inspire.fitView() print("New Cone has been added in Implicit Part1.") # Modify the parametric variable to change the Cone shape model.variables.update("radius", type="length", expression="100 mm") #similarly other variables of the Cone primitive can be changed. model.variables.update("height", type="length", expression="600 mm") #similarly position variables of the Cone primitive can be changed. model.variables.update("posX", type="length", expression="100 mm")
Create Implicit Pipe
A pipe is defined by its inner and outer radius, and height.
from hwx import inspire model = inspire.newModel() # Creating Implicit blank part. implicitPart = inspire.Implicit() implicitPart.name = "Implicit Part1" inspire.fitView() print("New Implicit part added in the model: ", model.parts[0]) # Creating Pipe primitive in implicit part. pipe = implicitPart.createPipe(innerRadius="300 mm", outerRadius="500 mm", height= "800 mm") inspire.fitView() print("New Pipe has been added in Implicit Part1.") # Updating Implicit Pipe. with implicitPart.edit(): pipe.innerRadius = "200 mm" inspire.fitView() print("Implicit Pipe has been updated with new values.")
Create parametric Implicit Pipe
The pipe’s dimensions can be defined through parametric variables.
from hwx import inspire model = inspire.newModel() # Creating Implicit blank part. implicitPart = inspire.Implicit() implicitPart.name = "Implicit Part1" inspire.fitView() print("New Implicit part added in the model: ", model.parts[0]) # creating variable to make parametric implicit Pipe. model.variables.add("innerRadius", type="length", expression="300 mm") model.variables.add("outerRadius", type="length", expression="500 mm") model.variables.add("height", type="length", expression= "5 m") model.variables.add("posX", type="length", expression='0.05 m') model.variables.add("posY", type="length", expression='0.05 m') model.variables.add("posZ", type="length", expression='0.05 m') # Creating parametric Pipe primitive in implicit part. pipe = implicitPart.createPipe(innerRadius="innerRadius", outerRadius="outerRadius", height= "height") inspire.fitView() print("New Pipe has been added in Implicit Part1.") # Modify the parametric variable to change the Pipe shape model.variables.update("innerRadius", type="length", expression="500 mm") #similarly other variables of the Pipe primitive can be changed. model.variables.update("outerRadius", type="length", expression="600 mm") #similarly position variables of the Pipe primitive can be changed. model.variables.update("posX", type="length", expression="100 mm")
Create implicit Capsule
from hwx import inspire model = inspire.newModel() # Creating Implicit blank part. implicitPart = inspire.Implicit() implicitPart.name = "Implicit Part1" inspire.fitView() print("New Implicit part added in the model: ", model.parts[0]) # Creating Capsule primitive in implicit part. capsule = implicitPart.createCapsule(length="200 mm", thickness="50 mm") inspire.fitView() print("New Capsule has been added in Implicit Part1.")
Create parametric Implicit Capsule
from hwx import inspire model = inspire.newModel() # Creating Implicit blank part. implicitPart = inspire.Implicit() implicitPart.name = "Implicit Part1" inspire.fitView() print("New Implicit part added in the model: ", model.parts[0]) # creating variable to make parametric implicit Capsule . model.variables.add("Length", type="length", expression='0.02 m') model.variables.add("Thickness", type="length", expression='0.005') model.variables.add("posX", type="length", expression='0.05 m') model.variables.add("posY", type="length", expression='0.05 m') model.variables.add("posZ", type="length", expression='0.05 m') # Creating parametric Capsule primitive in implicit part. capsule = implicitPart.createCapsule(length="Length", thickness="Thickness", originX="posX", originY="posY", originZ="posZ") inspire.fitView() print("New Capsule has been added in Implicit Part1.") # Modify the parametric variable to change the Capsule shape model.variables.update("Length", type="length", expression="50 mm") #similarly other variables of the Capsule primitive can be changed. model.variables.update("Thickness", type="length", expression="20 mm") #similarly position variables of the Capsule primitive can be changed. model.variables.update("posX", type="length", expression="100 mm")
Create Implicit Pellet
from hwx import inspire model = inspire.newModel() # Creating Implicit blank part. implicitPart = inspire.Implicit() implicitPart.name = "Implicit Part1" inspire.fitView() print("New Implicit part added in the model: ", model.parts[0]) # Creating Pallet primitive in implicit part. pellet = implicitPart.createPellet(radius="500 mm", thickness="200 mm") inspire.fitView() print("New Pellet has been added in Implicit Part1.") # Updating Implicit Pellet. with implicitPart.edit(): pellet.radius = "600 mm" inspire.fitView() print("Implicit Pellet has been updated with new values.")
Create parametric Implicit Pellet
from hwx import inspire model = inspire.newModel() # Creating Implicit blank part. implicitPart = inspire.Implicit() implicitPart.name = "Implicit Part1" inspire.fitView() print("New Implicit part added in the model: ", model.parts[0]) # creating variable to make parametric implicit pellet. model.variables.add("Radius", type="length", expression='0.05 m') model.variables.add("Thickness", type="length", expression='0.05') model.variables.add("posX", type="length", expression='0.05 m') model.variables.add("posY", type="length", expression='0.05 m') model.variables.add("posZ", type="length", expression='0.05 m') # Creating Pellet primitive in implicit part with parametric variables pellet = implicitPart.createPellet(radius="Radius", thickness="Thickness", originX='posX', originY='posY', originZ='posZ') inspire.fitView() print("New Pellet has been added in Implicit Part1.") # Modify the parametric variable to change the Pellet shape model.variables.update("Radius", type="length", expression="50 mm") #similarly other variables of the Pellet primitive can be changed. model.variables.update("Thickness", type="length", expression="20 mm") #similarly position variables of the Pellet primitive can be changed. model.variables.update("posX", type="length", expression="100 mm")
In each of the above examples, we’ve demonstrated how to create both simple and parametric implicit primitives. By leveraging parametric modeling, we gain the flexibility to adjust these primitives based on different design needs without manually redefining geometry. This approach is essential for building robust and adaptable models in Altair Inspire.