The LoadedPart
declaration can load models and sketches from the 3D formats: STL, BREP, and IGES and 2D formats: SVG, PDF, and DXF. Use from declaracad.occ.loader import LoadedPart
to import this node as it is not in the standard api. These can be used directly in parts or with operations like any other shape. Just set the filename
attribute to the file location.
Note: Previous versions of DeclaraCAD used
LoadShape
andpath
, these have been replaced withLoadedPart
andfilename
which supports loading multiple shapes with colors.
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 *
from declaracad.occ.loader import LoadedPart
enamldef Assembly(Part):
LoadedPart: dxf:
attr outside_wire = self.topology.wires[5]
attr inside_wires = [w for w in self.topology.wires if w != outside_wire]
filename = '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]
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 *
from declaracad.occ.loader import LoadedPart
enamldef Assembly(Part):
LoadedPart:
filename = 'examples/models/five_spoke_wheel.stl'
material = 'chrome'