The LoadShape declaration can load models and sketches from the 3D formats: STL, BREP, and IGES and 2D formats: DXF. These can be used directly in parts or with operations like any other shape. Just set the path attribute to the file location.

For example to load a 2D aluminum extrusion profile we can load a DXF profile and then extrude it to any width.

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

enamldef Assembly(Part):
    LoadShape: dxf:
        attr outside_wire = self.topology.wires[5]
        attr inside_wires = [w for w in self.topology.wires if w != outside_wire]
        path = 'examples/models/25-5050.dxf'
        color = 'red'
    Extrude:
        material = 'aluminium'
        vector = (0, 0, 1000)    
        Cut:
            color = 'red'
            Face:
                wires = [dxf.outside_wire]
                color = 'red'
            Looper:
                iterable << dxf.inside_wires
                Face:
                    wires = [loop.item]

Loading DXF

Note: Loading a 2D profile imports everything as a compound path. In order to convert it into a face the internal paths must be cut out from the outside path as shown above.

The same can be done for 3D models.

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

enamldef Assembly(Part):
    LoadShape:
        path = 'examples/models/five_spoke_wheel.stl'
        material = 'chrome'

Load STL