Primitive Shapes
DeclaraCAD supports the following primitive shapes to help start modeling.
Box
The Box
declaration creates a cube or extruded rectangle relative at the bottom left corner from dx
, dy
, and dz
dimensions.
Note: The box can be centered by setting the
position = (-dx/2, -dy/2, -dz/2)
.
# Created in DeclaraCAD
from declaracad.occ.api import *
enamldef Assembly(Part):
Box:
color = 'coral'
transparency = 0.8
dx = 5
dy = 6
dz = 10
Wedge
The Wedge
declaration creates a wedge or extruded triangle. The dx
, dy
and dz
define the triangle and it is positioned at the bottom left corner and may be centered in the same way as the box.
# Created in DeclaraCAD
from declaracad.occ.api import *
enamldef Assembly(Part):
Wedge:
color = 'coral'
transparency = 0.5
dx = 4
dy = 1
dz = 2
The itx
attribute can be set to adjust where the edge starts, by default it is at 0.
# Created in DeclaraCAD
from declaracad.occ.api import *
enamldef Assembly(Part):
Wedge:
color = 'coral'
transparency = 0.5
dx = 4
dy = 1
dz = 2
itx = dx/2
Cylinder
The Cylinder
declaration creates a cylinder from a radius
and height
in the given direction
. The cylinder is starts at the position
and extends in the direction
by the height
.
# Created in DeclaraCAD
from declaracad.occ.api import *
enamldef Assembly(Part):
Cylinder:
color = 'coral'
transparency = 0.5
height = 5
radius = 2
An angle
can be specified in radians to limit the angle of revolution.
# Created in DeclaraCAD
from math import pi
from declaracad.occ.api import *
enamldef Assembly(Part):
Cylinder:
color = 'coral'
transparency = 0.5
height = 5
radius = 2
angle = pi/2
Tube
The Tube
is a shortcut for a hollowed out cylinder. The parameters are the same but it takes a radius2
. The smaller of radius
and radius2
will be used as the inner radius cut out of the tube. If either radius
or radius2
is zero it will create a cylinder.
# Created in DeclaraCAD
from declaracad.occ.api import *
enamldef Assembly(Part):
Tube:
radius = 4
radius2 = 3.75
height = 6
Tube:
position = (10, 0)
radius = 2
radius2 = 0
height = 6
Tube:
position = (0, 10)
radius = 0
radius2 = 2
height = 6
Tube:
position = (-10, 0)
radius = 2
radius2 = 3
height = 6
Hole
The Hole
declaration creates a cylinder with optional chamfers or cones on the top and bottom edges. Define the diameter
and depth
of the hole to create a simple cylinder. The near_edge
and far_edge
attributes can be set as a tuple containing the edge type (either 'cone' or 'chamfer') and the distance of the cone or chamfer as shown below. To create a cone or chamfer that is not at 45 degrees a second distance can also be added to the tuple. This was added as a shortcut to avoid needing to add and maintain chamfer edge lists.
Note: The
near_edge
andfar_edge
can be somewhat confusing depending on the orientation. Thenear_edge
is always closest to theposition
while thefar_edge
isdepth
away from the position along the direction axis. For example, in the default orientation along the positive Z axis thenear_edge
is the bottom and thefar_edge
is the top.
# Created in DeclaraCAD
from declaracad.occ.api import *
enamldef Assembly(Part):
Axis:
pass
Cut:
color = 'maroon'
Box: box:
position = (-dx/2, -dy/2)
dx = 50
dy = 60
dz = 10
Hole: center_through_hole:
# A hole with no near_edge or far_edge styles
# defined is the same as a Cylinder except the diameter
# and depth are used instead of radius and height
diameter = 10
depth = box.dz
Hole: center_hole:
# Defining the far edge as "cone" 1 adds a cone
# to the top of the hole which when cut from the box
# makes it chamfered by the cone distance.
position = (0, 0, 2)
diameter = 20
depth = box.dz-self.z
far_edge = ("cone", 1)
near_edge = ("chamfer", 2)
Looper: corner_holes:
attr offset = 8
iterable = [
(box.dx/2-offset, box.dy/2-offset),
(-box.dx/2+offset, box.dy/2-offset),
(-box.dx/2+offset, -box.dy/2+offset),
(box.dx/2-offset, -box.dy/2+offset),
]
Hole:
position = loop.item
diameter = 4
depth = box.dz
# Defining the far edge as "cone" 1 adds a cone
# to the top of the hole which when cut from the box
# makes it chamfered by two distances.
far_edge = ("cone", 2, 4)
Cone
The Cone
declaration creates a tapered cylinder. It is defined the same as a cylinder with a radius
and height
and may also be limited by an angle
.
# Created in DeclaraCAD
from math import pi
from declaracad.occ.api import *
enamldef Assembly(Part):
Cone:
color = 'coral'
height = 5
radius = 2
The radius2
attribute may be given to limit the radius where it stops.
# Created in DeclaraCAD
from math import pi
from declaracad.occ.api import *
enamldef Assembly(Part):
Cone:
color = 'coral'
height = 5
radius = 2
radius2 = 1
Sphere
The Sphere
declaration creates a ball or sphere centered at the given position. The radius
attribute defines the size.
# Created in DeclaraCAD
from math import pi
from declaracad.occ.api import *
enamldef Assembly(Part):
Sphere: s1:
color = 'coral'
transparency = 0.5
radius = 10
The sphere can be reduced to a section by setting angle
, angle2
, and angle3
which limit the sphere in the u and v ranges.
The angle
can range from 0
to 2*pi
to limit the sphere around the direction
axis. For example angle = pi
(shown below) will create a half sphere, angle = pi/2
will create a quarter sphere.
The other two angle2
and angle3
range from -pi/2
to pi/2
and limit the sphere in the opposite sweep direction.
# Created in DeclaraCAD
from math import pi
from declaracad.occ.api import *
enamldef Assembly(Part):
Sphere: s1:
color = 'coral'
transparency = 0.5
radius = 10
angle2 = -pi/4
angle3 = pi/4
Torus
The Torus
declaration creates a circle revolved around a radius or a "ring" shape. Set the radius
attribute for the revolve radius and the radius2
for the profile radius.
# Created in DeclaraCAD
from math import pi
from declaracad.occ.api import *
enamldef Assembly(Part):
Torus: s1:
color = 'coral'
radius = 4
radius2 = 1
The torus can also be limited by the angle
in radians.
# Created in DeclaraCAD
from math import pi
from declaracad.occ.api import *
enamldef Assembly(Part):
Torus: s1:
color = 'coral'
radius = 4
radius2 = 1
angle = pi
And the start and stop angles of the circle profile can be limited by angle2
and angle3
# Created in DeclaraCAD
from math import pi
from declaracad.occ.api import *
enamldef Assembly(Part):
Torus: s1:
color = 'coral'
radius = 4
radius2 = 1
angle2 = pi/2
angle3 = 0