3D Printer slicer

Integrated into the Slicer official code sample.

Use the following code to slice an STL model in your 3D printing application.

ReadSTL rs = new ReadSTL(@"c:\devdept\bunny.stl");
rs.DoWork();
rs.AddToScene(viewportLayout1);

Mesh m = (Mesh) rs.Entities[0];
m.ColorMethod = colorMethodType.byEntity;
m.Color = Color.Aquamarine;

Plane p = Plane.XY;

LinkedList<SharedEdge>[] edgesPerVertex;
Utility.GetEdgesWithoutDuplicates(m.Triangles, m.Vertices.Length, out edgesPerVertex);

int num = 100;

List<Entity> sections = new List<Entity>(num);

for (int iz = 0; iz < num; iz++)
{
    p.Translate(new Vector3D(0, 0, m.BoxSize.Z / num));

    ICurve[] sCurves = m.Section(p, 0, edgesPerVertex);

    foreach (Entity c in sCurves)
    {
        sections.Add(c);
    }
}

viewportLayout1.Entities.AddRange(sections, Color.Blue);

An this is the result:

slicer.png

Was this article helpful?
1 out of 1 found this helpful
Have more questions? Submit a request

Comments

6 comments
  • Great Article,

    How to save these slices as separate 2D images (e.g. PNG files)

    1
  • After setting ViewportLayout.BoundingBox.OverrideSceneExtents = true and setting BoundingBox.Min and Max, you may want to try building a Region entity from each closed contour on the same plane, hide all the other contours (Entity.Visible), set top view (ViewportLayout.SetView()), set orthographic projection (ViewportLayout.Camera.OrientationMode), fit the bounding box to screen (ViewportLayout.ZoomFit()) and call ViewportLayout.RenderToBitmap() to generate the image.

    0
  • is it possible to get NC code about slicer?

     

    0
  • You can easily create a Toolpath entity from the slice data. From the Toolpath entity, you can create a post-processor specific for your 3D printer.

    0
  • Hi Alberto,

    Is there any source code in sample?

    if it is, please let me know about that...

    0
  • Just fill Toolpath.Motions with linear motions that represent section loop segments.

    0

Please sign in to leave a comment.