Sweeps

In DeclaraCAD there are two ways to sweep a profile along a path or spline. These are done with the Pipe and Evolved declarations.

Pipe

The Pipe declaration requires two shapes to operate on, the profile and the spline. The angle made by the spine with the profile is maintained along the length of the pipe. The spline does not need to be closed.

Note: Add from declaracad.occ.api import Pipe as Sweep to rename if you prefer the name sweep instead

# Created in DeclaraCAD
from declaracad.occ.api import *

enamldef Path(Wire):
    Segment: s1:
        points = [(0,0), (0,10)]
    #: 180 deg elbow
    Arc: a1:
        attr p = s1.points[-1]
        position = (radius, p.y)
        radius = 5
        points = [
            p + (2*radius, 0),
            p,
        ]
    Segment:
        attr p = a1.start # Arc goes backwards
        points = [p, (10, 0)]

enamldef Assembly(Part):        
    Path: path:
        color = 'red'

    Circle: pipe_profile:
        color = 'blue'
        direction = (0,1,0)
        radius = 2

    Pipe:
        color = '#333'
        spline = path
        profile = pipe_profile

Which creates the following pipe.

Sweep a pipe along a path

Instead of assigning spline and profile attributes they may be added into the Pipe block, the first being the spline and the second being the profile for example:

enamldef Assembly(Part):            
    Pipe:
        color = '#333'
        Path: path:
            pass
        Circle: pipe_profile:
            direction = (0,1,0)
            radius = 2

It will also accept one child declaration and one of the attributes.

Note: It is important to note that the spline and profile being swept should start at the same position and the angle between the profile normal and spline direction is maintained throughout the sweep. Above the direction of the circle was set to the y axis since the first line segment moves in the y direction. In some cases it may be hard to find the direction, in this case the position and direction of a curve can be obtained using the get_value_at method of the shapes topology. For example:

# Created in DeclaraCAD
from declaracad.occ.api import *

enamldef Path(Wire):
    alias s1
    Segment: s1:
        points = [(0,0), (0,10)]
    Arc: a1:
        attr p = s1.points[-1]
        position = (radius, p.y)
        radius = 5
        points = [
            p + (2*radius, 0),
            p,
        ]
    Segment:
        attr p = a1.start # Arc goes backwards
        points = [p, (10, 0)]

enamldef Assembly(Part):            
    Pipe:
        color = '#333'
        Path: path:
            color = 'red'

        Circle: pipe_profile:
            attr r = path.s1.get_value_at(t=0, derivative=1)
            position = r[0]
            direction = r[1]
            radius = 2

As of this writing the you cannot get the derivative from the Wire itself so instead we add an alias to the first segment of the wire and use that.

Evolved

The Evolved declaration does a sweep of a profile along a spline like a Pipe, however unlike the Pipe declaration any discontinuities in the spline are connected by joining using the join_type (similar to using an offset). The spline must be closed and planar.

from declaracad.occ.api import (
    Axis, Part, Evolved, Polygon, Ellipse, Rectangle, Circle
)


enamldef Assembly(Part): 
    name = "Evolved"
    Axis:
        pass

    Evolved:
        Ellipse:
            major_radius = 30
            minor_radius = 40
        Polygon:
            points = [
                (0, 2, 0),
                (0, -2, 0),
                (0, 0, 3),
            ]

    Evolved:
        color = 'teal'
        Rectangle: 
            position = (-width/2, -height/2)
            width = 40
            height = 20
        Circle:
            direction = (1, 0)
            radius = 2

Evolved examples