Primitives (hwx.inspire.Primitives)#
- class Primitives#
Bases:
object
Utilites to create parts with primitive shapes.
The supported primitive shapes are block, cone, polygon, ellipsoid, prism, sphere, torus and etc.
Method Table# Name
Description
createCurves
(self, points, **kwds)Creates a list of SplineCurve parts that connect the points.
createEmptyPart
(self, **kwds)Creates an empty part.
createPointPart
(self, **kwds)Creates a point part.
createPolylines
(self, points, **kwds)Creates a list of Polyline parts that connect the points.
createSheetCircle
(self, radius=1, **kwds)Creates a circle centered at the origin in the XY plane.
createSheetPolygon
(self, radius=1, nsides=3, **kwds)Creates a regular polygon centered at the origin in the XY-plane.
createSheetRectangle
(self, x=1, y=1, **kwds)Creates a rectangle centered at the origin.
createSolidBlock
(self, x=1, y=1, z=1, **kwds)Creates a solid block with the center of the base at the origin.
createSolidCone
(self, radius=1, height=1, semiangle=0, **kwds)Creates a solid cone with the base centered at the origin in the XY
createSolidCylinder
(self, radius=1, height=1, **kwds)Creates a solid cylinder with the base centered at the origin in the XY
createSolidEllipsoid
(self, xRadius=1, yRadius=0.5, zRadius=0.25, **kwds)Creates a solid ellipsoid centered at the origin.
createSolidPrism
(self, radius=1, height=1, nsides=20, blendradius=0, **kwds)Creates a solid prism with the base centered at the origin in the XY
createSolidSphere
(self, radius=1, **kwds)Creates a solid sphere with centre at origin.
createSolidTorus
(self, majorRadius=1, minorRadius=0.5, **kwds)Creates a solid torus centered at the origin, located in the XY-plane
importPart
(self, fileName, **kwds)- createEmptyPart(**kwds)#
Creates an empty part.
- Parameters:
**kwds – Part attributes like name, location, color…
- Returns:
Part
# Import the 'inspire' module from the 'hwx' package from hwx import inspire model = inspire.newModel() emptyPart = model.createEmptyPart(location=(0,2,5)) inspire.fitView() print("New part added in the model: ",model.parts[0]) print("Empty part location: ", emptyPart.location)
- createPointPart(**kwds)#
Creates a point part.
- Parameters:
**kwds – Part attributes like name, location, color…
- Returns:
Part
# Import the 'inspire' module from the 'hwx' package from hwx import inspire model = inspire.newModel() pointPart = model.createPointPart(mass = 0.2) inspire.fitView() print("Point part mass: ", pointPart.mass)
- createPolylines(points, **kwds)#
Creates a list of Polyline parts that connect the points.
If the points don’t have intersections, creates one Polyline part. Otherwise, creates one Polyline part for each section.
- Parameters:
points (list[math.Point]) – List of points to create the Polyline part.
**kwds – Part attributes like name, location, color…
- Returns:
List of created parts.
- Return type:
list[Part]
# Import the 'inspire' module from the 'hwx' package from hwx import inspire model = inspire.newModel() path = [(0, 0, 0), (0, 0, 4)] polyLine = model.createPolylines(path)[0] inspire.fitView() print("Features in Polyline: ", polyLine.features)
- createCurves(points, **kwds)#
Creates a list of SplineCurve parts that connect the points.
If the points don’t have intersections, creates one SplineCurve part. Otherwise, creates one SplineCurve part for each section.
- Parameters:
points (list[math.Point]) – List of points used to create the SplineCurve part.
**kwds – Part attributes like name, location, color…
- Returns:
List of created parts.
- Return type:
list [Part]
# Import the 'inspire' module from the 'hwx' package from hwx import inspire model = inspire.newModel() path = [(0, 0, 0), (0, 0, 4)] curve = model.createCurves(path)[0] inspire.fitView() print("Features in Curve: ", curve.features)
- createSolidBlock(x=1, y=1, z=1, **kwds)#
Creates a solid block with the center of the base at the origin.
By default, the solid block is positioned such that its bottom face lies on the XY plane, with the Z-dimension extending upwards. If stacking or precise placement is needed, use the location argument to adjust its placement along the Z-axis.
- Parameters:
x (float | str) – The length. Can be a float, a string with units (e.g., ‘10 cm’), or a variable name.
y (float | str) – The width. Can be a float, a string with units, (e.g., ‘10 ft’), or a variable name.
z (float | str) – The height. Can be a float, a string with units,(e.g., ‘10 in’), or a variable name.
**kwds – Part attributes like name, location, color…
- Returns:
The created solid block.
- Return type:
# Import the 'inspire' module from the 'hwx' package from hwx import inspire # Retrieve the current model model = inspire.getModel() # To get a new modeling session # inspire.newModel() # Adding a model variable with a name 'length'. model.variables.add ('depth',type='Length',expression= '4 m') block = model.createSolidBlock(x=2.0, y='3 m', z='depth', color="YELLOW", location = (0,0,0) , name = 'Part 1') inspire.orientView(direction="iso")
- createSolidCylinder(radius=1, height=1, **kwds)#
Creates a solid cylinder with the base centered at the origin in the XY plane and the height extending along the z-axis.
By default, the solid cylinder is positioned such that its bottom face lies on the XY plane, with the Z-dimension extending upwards. If stacking or precise placement is needed, use the location argument to adjust its placement along the Z-axis.
- Parameters:
radius (float | str) – The radius in the XY-plane. Can be a float, a string with units (e.g., ‘10 cm’), or
name. (a variable) –
height (float | str) – The height along z-axis. Can be a float, a string with units (e.g., ‘10 ft’), or
name. –
**kwds – Part attributes like name, location, color…
- Returns:
The created solid cylinder.
- Return type:
from hwx import inspire # Import the 'inspire' module from the 'hwx' package model = inspire.getModel() # Retrieve the current model # To get a new modeling session #inspire.newModel() # Adding a model variable with a name 'height'. model.variables.add ('height',type='Length',expression= '4 m') # usage of model variable makes the createSolidCylinder operation parametric. block = model.createSolidCylinder(radius=2.0, height='height', color="RED", location = (0,0,0) , name = 'Cylinder 1') inspire.orientView(direction="iso")
- createSolidPrism(radius=1, height=1, nsides=20, blendradius=0, **kwds)#
Creates a solid prism with the base centered at the origin in the XY plane and the height extending along the z-axis.
By default, the solid prism is positioned such that its bottom face lies on the XY plane, with the Z-dimension extending upwards. If stacking or precise placement is needed, use the location argument to adjust its placement along the Z-axis.
- Parameters:
radius (float | str) – The radius in the XY-plane. Can be a float, a string with units (e.g., ‘10 cm’), or
name. (a variable) –
height (float | str) – The height along z-axis. Can be a float, a string with units (e.g., ‘10 cm’), or
name. –
nsides (int | str) – The number of facets. Must be > 2. Can be an integer, a string without units (e.g., ‘10’), or a variable name.
blendradius (float | str) – The radius used to round the corners. Can be a float, a string with units (e.g., ‘10 cm’), or
name. –
**kwds – Part attributes like name, location, color, material…
- Returns:
The created solid prism.
- Return type:
from hwx import inspire # Import the 'inspire' module from the 'hwx' package model = inspire.getModel() # Retrieve the current model # To get a new modeling session #inspire.newModel() # Adding a model variable with a name 'radius'. model.variables.add ('radius',type='Length',expression= '4 m') # Adding a model variable with a name 'numberOfSides'. model.variables.add ('numberOfSides',type='Unitless',expression= 6) block = model.createSolidPrism(radius= 'radius', height= '4 ft', nsides ='numberOfSides', color="RED", location = (0,0,0) , material = "Plastic (ABS)") inspire.orientView(direction="iso")
- createSolidCone(radius=1, height=1, semiangle=0, **kwds)#
Creates a solid cone with the base centered at the origin in the XY plane and the height extending along the z-axis.
By default, the solid cone is positioned such that its bottom face lies on the XY plane, with the Z-dimension extending upwards. If stacking or precise placement is needed, use the location argument to adjust its placement along the Z-axis.
- Parameters:
radius (float | str) – The radius in the XY-plane. Can be a float, a string with units (e.g., ‘10 cm’), or
name. (a variable) –
height (float | str) – The height along z-axis. Can be a float, a string with units (e.g., ‘10 cm’), or
name. –
semiangle (float | str) – The angle the cone makes with the z-axis. Must be 0 < semiangle < pi/2. Can be a float,
units (a string with) –
**kwds – Part attributes like name, location, color…
- Returns:
The created solid Cone.
- Return type:
from hwx import inspire # Import the 'inspire' module from the 'hwx' package model = inspire.getModel() # Retrieve the current model # To get a new modeling session #inspire.newModel() # Adding a model variable with a name 'radius'. model.variables.add ('radius',type='Length',expression= '4 m') # Adding a model variable with a name 'semiangle'. model.variables.add ('semiangle',type='angle',expression= '45 deg') block = model.createSolidCone(radius= 'radius', height= '4 in', semiangle ='semiangle' , color="RED", location = (0,0,0) , material = "Plastic (ABS)") inspire.orientView(direction="iso")
- createSolidSphere(radius=1, **kwds)#
Creates a solid sphere with centre at origin.
- Parameters:
radius (float | str) – Radius of the sphere. Can be a float, a string with units (e.g., ‘10 cm’), or
name. (a variable) –
**kwds – Part attributes like name, location, color, material…
- Returns:
The created solid Sphere.
- Return type:
from hwx import inspire # Import the 'inspire' module from the 'hwx' package model = inspire.getModel() # Retrieve the current model # To get a new modeling session #inspire.newModel() # Adding a model variable with a name 'radius'. model.variables.add ('radius',type='Length',expression= '4 m') sphere = model.createSolidSphere(radius= 'radius', material = "nylon", color = "YELLOW", location = (0,0,0)) inspire.orientView(direction="iso")
- createSolidTorus(majorRadius=1, minorRadius=0.5, **kwds)#
Creates a solid torus centered at the origin, located in the XY-plane with the z-axis sticking through the hole.
By default, the solid torus is positioned such that its bottom face lies on the XY plane, with the Z-dimension extending upwards. If stacking or precise placement is needed, use the location argument to adjust its placement along the Z-axis.
- Parameters:
majorRadius (float | str) – The radius from the hole’s center to the rim’s midline. Can be a float, a string with
units (a string with) –
minorRadius (float | str) – The radius of the cross section of the rim and Must be less than majorRadius. Can be
float (a) –
units –
**kwds – Part attributes like name, location, color, material…
- Returns:
The created solid Torus.
- Return type:
from hwx import inspire # Import the 'inspire' module from the 'hwx' package model = inspire.getModel() # Retrieve the current model # To get a new modeling session #inspire.newModel() # Adding a model variable with a name 'majorRadius'. model.variables.add ('majorRadius',type='Length',expression= '24 cm') torus = model.createSolidTorus(majorRadius= 'majorRadius', minorRadius = '12 cm', material = "nylon", color = "YELLOW", location = (0,0,0)) inspire.orientView(direction="iso")
- createSolidEllipsoid(xRadius=1, yRadius=0.5, zRadius=0.25, **kwds)#
Creates a solid ellipsoid centered at the origin.
- Parameters:
xRadius (float | str) – The radius in x-axis. Can be a float, a string with units (e.g., ‘10 cm’), or a variable name.
yRadius (float | str) – The radius in y-axis. Can be a float, a string with units (e.g., ‘10 mm’), or a variable name.
zRadius (float | str) – The radius in z-axis. Can be a float, a string with units (e.g., ‘10 in’), or a variable name.
**kwds – Part attributes like name, location, color, material…
- Returns:
The created solid Ellipsoid.
- Return type:
# Import the 'inspire' module from the 'hwx' package from hwx import inspire # Retrieve the current model model = inspire.getModel() # To get a new inspire modeling session # model = inspire.newModel() # Adding a model variable with a name 'xRadius'. model.variables.add ('xRadius',type='Length',expression= '24 cm') ellipsoid = model.createSolidEllipsoid(xRadius= 'xRadius', yRadius = '12 cm', zRadius =0.12, location = (0,0,0)) inspire.orientView(direction="iso")
- createSheetCircle(radius=1, **kwds)#
Creates a circle centered at the origin in the XY plane.
By default, the sheet is positioned such that its bottom face lies on the XY plane. use the location argument to adjust its placement along the Z-axis.
- Parameters:
radius (float | str) – Radius of the sheet. Can be a float, a string with units (e.g., ‘10 cm’), or a variable name.
sheetThickness (float | str) – Thickness of the sheet. Can be a float, a string with units (e.g., ‘1 mm’).
**kwds – Part attributes like name, location, color, material, sheetThickness…
- Returns:
The created sheet circle.
- Return type:
# Import the 'inspire' module from the 'hwx' package from hwx import inspire # Retrieve the current model model = inspire.getModel() # To get a new inspire modeling session # model = inspire.newModel() # Adding a model variable with a name 'radius'. model.variables.add ('radius',type='Length',expression= '24 cm') sheet = model.createSheetCircle(radius= 'radius', sheetThickness = '2 mm', location = (0,0,0)) # Set the view to isometric inspire.orientView(direction="iso")
- createSheetPolygon(radius=1, nsides=3, **kwds)#
Creates a regular polygon centered at the origin in the XY-plane.
By default, the sheet is positioned such that its bottom face lies on the XY plane. use the location argument to adjust its placement along the Z-axis.
- Parameters:
radius (float | str) – The distance from the center to a vertex. Can be a float, a string with units (e.g., ‘10 cm’), or a variable name.
nsides (int | str) – The number of sides. Must be > 2. Can be a integer, a string without units (e.g., ‘10’), or a variable name.
sheetThickness (float | str) – Thickness of the sheet. Can be a float, a string with units (e.g., ‘2 mm’).
**kwds – Part attributes like name, location, color, material, sheetThickness…
- Returns:
The created sheet polygon.
- Return type:
# Import the 'inspire' module from the 'hwx' package from hwx import inspire model = inspire.getModel() # Retrieve the current model # get new modeling session #inspire.getModel() # Adding a model variable with a name 'radius'. model.variables.add ('radius',type='Length',expression= '24 cm') # Adding a model variable with a name 'numberOfSides'. model.variables.add ('numberOfSides',type='Unitless',expression= 6) sheet = model.createSheetPolygon(radius= 'radius', nsides='numberOfSides', sheetThickness = '1 mm', location = (0,0,0)) inspire.orientView(direction="iso")
- createSheetRectangle(x=1, y=1, **kwds)#
Creates a rectangle centered at the origin.
By default, the sheet is positioned such that its bottom face lies on the XY plane. use the location argument to adjust its placement along the Z-axis.
- Parameters:
x (float | str) – The length. Can be a float, a string with units (e.g., ‘10 cm’), or a variable name.
y (float | str) – The width. Can be a float, a string with units (e.g., ‘10 cm’), or a variable name.
sheetThickness (float | str) – Thickness of the sheet. Can be a float, a string with units (e.g., ‘2 mm’).
**kwds – Part attributes like name, location, color, material, sheetThickness …
- Returns:
The created sheet.
- Return type:
# Import the 'inspire' module from the 'hwx' package from hwx import inspire model = inspire.getModel() # Retrieve the current model # get a new modeling session # inspire.getModel() # Adding a model variable with a name 'length'. model.variables.add ('length',type='Length',expression= '24 cm') # Adding a model variable with a name 'width'. model.variables.add ('width',type='Length',expression= '12 cm') sheet = model.createSheetRectangle(x= 'length', y='width', sheetThickness = '2 mm', location = (0,0,0)) inspire.orientView(direction="iso")