Difficulty:: Medium.
Next Tutorial: Rotating and Extruding a dxf file

Linear Extruding a dxf file

In OOML we include, like in OpenSCAD, the capability of importing 2D pictures from other design programs in DXF format, in order to extrude it. One way to do it is calling to linearExtrudeFromDXF function, which extrude the picture along the z axis.

Component a(Component::linearExtrudeFromDXF("spiral.dxf",10));

This function need two parameters: the file's name and the height. Here, we're importing spiral.dxf file with 1 cm of height.

Next, we're going to center this object, and clone it by rotating it:

a.translate(-110,-150,0);
a = a + a.rotatedCopy(0,0,240) + a.rotatedCopy(0,0,120)

Object is rotated 120 and 240 degrees around z axis.

If we want to generate the OpenSCAD code for this component, we simply run:

IndentWriter writer; 
 
writer << a;
 
std::cout << writer;
//or
writer.dump(std::cout);

This will send to the standard output the following

union() {
  translate(v=[-110.000, -150.000, 0.000]) {
    linear_extrude(file="dibujo.dxf", height=10.000, twist=0, $fn=100, convexity=10, center=true);
  } // End translate
  rotate(a=[0.000, 0.000, 240.000]) {
    translate(v=[-110.000, -150.000, 0.000]) {
      linear_extrude(file="dibujo.dxf", height=10.000, twist=0, $fn=100, convexity=10, center=true);
    } // End translate
  } // End rotate
  rotate(a=[0.000, 0.000, 120.000]) {
    translate(v=[-110.000, -150.000, 0.000]) {
      linear_extrude(file="dibujo.dxf", height=10.000, twist=0, $fn=100, convexity=10, center=true);
    } // End translate
  } // End rotate
} // End union

The full code would be:

IndentWriter writer;
 
// Output file which contains the OpenSCAD code.
ofstream os("dfx.scad");
 
// Import dibujo.dxf file and extrude it 10 mm.
Component a(Component::linearExtrudeFromDXF("dibujo.dxf",10));
 
// Translate a to center it.
a.translate(-110,-150,0);
 
// Add two rotated copies.
Component b = a + a.rotatedCopy(0,0,240)
              + a.rotatedCopy(0,0,120);
 
// Generate the OpenSCAD code.
writer << b;
os << writer;
os.close();

Next Tutorial: Rotating and Extruding a dxf file

Recent changes RSS feed Creative Commons License Donate Minima Template by Wikidesign Driven by DokuWiki