Hello world
I'm trying to use Matthew Venn's scad script to create a slicer that will
import stl files and then export each slicel as a dxf file. See his original
code at the bottom.
https://github.com/mattvenn/cad/blob/master/openscad/layer_demo/layer_demo.scad
Is there a way I can write an "export dxf" module so each slice will get
exported as a dxf? (layer1.dxf, layer2.dxf, etc.)
Right now it simply prints to the console.
//define some variables
//can vars
can_radius = 6;
can_wall_thickness=1;
can_height = 30;
top_cone_h = 2;
//nozzle vars
nozzle_h=3;
nozzle_r = 2;
//calculated variable
total_can_height=can_height+top_cone_h+nozzle_h;
echo(str("can height:", total_can_height));
//global vars
smooth=20; //circular shapes are drawn with this number of edges
slice_thickness=1;
//so we can choose what to do from the command line
make_can=true;
//slice_can=true;
import_slices=true;
//get_single_slice=true;
//cut_level=20;
//make a simple 3d model of a can
module make_can()
{
//the body
color("grey")
//the 0.1 is to make sure the objects merge together
difference()
{
cylinder(r=can_radius,h=can_height+0.1,$fn=smooth);
translate([0,0,can_wall_thickness])
cylinder(r=can_radius-can_wall_thickness,h=can_height-can_wall_thickness2,$fn=smooth);
}
//the top cone
color("grey")
translate([0,0,can_height-0.1])
cylinder(r2=nozzle_r,r1=can_radius0.8,h=top_cone_h+0.1,$fn=smooth);
//the nozzle
color("white")
translate([0,0,can_height+top_cone_h])
cylinder(r=nozzle_r,h=nozzle_h,$fn=smooth);
}
//slice the part into sections
module slice_can()
{
for(cut_level=[0:slice_thickness:total_can_height])
{
projection(cut=true)
translate([cut_level/slice_thickness3can_radius,10,-cut_level])
make_can();
}
}
module get_single_slice()
{
echo(str("cut level:", cut_level));
projection(cut=true) //cutting it at plane z=0
translate([0,0,-cut_level])
make_can();
}
module import_slices()
{
translate([can_radius*3,0,0])
for(cut_level=[0:slice_thickness:total_can_height-1])
{
echo(str("layer", cut_level, ".dxf"));
translate([0,0,cut_level*2]) //*2 to explode it
color("gray")
linear_extrude(height=slice_thickness) import(str("layer", cut_level,
".dxf"));
}
}
//do it
if(make_can)
make_can();
if(slice_can)
slice_can();
if(get_single_slice)
get_single_slice();
if(import_slices)
import_slices();
--
View this message in context: http://forum.openscad.org/using-openscad-as-a-slicer-to-export-dxf-files-tp10984.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
On Jan 9, 2015, at 11:15 AM, digital aklee42@neo.tamu.edu wrote:
Is there a way I can write an "export dxf" module so each slice will get
exported as a dxf? (layer1.dxf, layer2.dxf, etc.)
This is not possible today, but similar functionality is discussed in these two issues:
https://github.com/openscad/openscad/issues/1041
https://github.com/openscad/openscad/issues/1044
-Marius
On 01/09/2015 05:15 PM, digital wrote:
Is there a way I can write an "export dxf" module so each slice will get
exported as a dxf? (layer1.dxf, layer2.dxf, etc.)
That could be done using a simple shell-script/batch-file that
calls OpenSCAD multiple times passing a parameter to select what
to generate/write.
Example:
https://github.com/openscad/openscad/wiki/Multi-File-export
ciao,
Torsten.
Hi Marius,
Thanks for the reply. Coincidentally, I was going to email you about the
google summer of code projects. It sounds like there is some overlap.
Torsten,
Thanks for reply. I will try that out with dxf files.
--
View this message in context: http://forum.openscad.org/using-openscad-as-a-slicer-to-export-dxf-files-tp10984p10988.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
What about evolving the animation with an export option? Use $t to define the
slices and a box to allow export (export type by use of extension).
??
Unless specifically shown otherwise above, my contribution is in the Public Domain; To the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. This work is published globally via the internet. :) Inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/using-openscad-as-a-slicer-to-export-dxf-files-tp10984p10991.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
On 01/09/2015 11:10 PM, MichaelAtOz wrote:
What about evolving the animation with an export option? Use $t to define the
slices and a box to allow export (export type by use of extension).
Hmm, why not, that would just require an option to actually
render the model instead of just using the preview.
That could fit into https://github.com/openscad/openscad/issues/891
I think the declarative way to give meta data for export would
still be useful and cover other use-cases.
ciao,
Torsten.
This is what I have so far for a slicer. Basing this work off of clothbot and
Matthew Venn's slicer.
All feedback is welcome.
// rough draft for a slicer that can export to dxf
z_min=-7; // this was found by experimenting with different values
z_max=15;
slice_width=1; //need to add 1 to whatever your desired thickness is
//layer=5; //z_min<layer<z_max, using this instead of for loop for now
because the for loop is so slow
slice_count=(max_z-max_z%slice_width) / slice_width + 1;
echo("Max Z ", max_z, " sliced into ", slice_width, " width slices: ",
slice_count);
module model()
{
import("C:/Users/z003EE9Y/Downloads/stl_files/nozzle_0pcs00-cbg11-030-a04-master_hr.stl");
//need to figure out where stl is located
}
module slice_model()
{
for(layer = [z_min:slice_width+1:z_max]) //for (i= [start:step:end]
{
echo(str("Layer:", layer)); //print on console
projection(cut=true) //project z=0 onto the xy plane
translate([0,0,layer]) // move the part by z index
model();
//this is the hardpart
// sliceFileName="Model_name_layer."+layer+".dxf";
// export_dxf( sliceFileName, slice_model(index=layer);
}
}
slice_model();
--
View this message in context: http://forum.openscad.org/using-openscad-as-a-slicer-to-export-dxf-files-tp10984p11015.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Just curious.. did you have a look at Slic3r? I don't know if DXF is supported,
but Slic3r can export slices as multi-layer SVG file.
ciao,
Torsten.
thanks for the tip. that would make life easier.
Tried it out right now. How could I split each layer in the svg into
separate svg files?
still, i've spent so much time on this issue that i am now resolved to come
up with a solution.
see below
https://github.com/openscad/openscad/wiki/Project:-Improve-DXF-import-and-export
--
View this message in context: http://forum.openscad.org/using-openscad-as-a-slicer-to-export-dxf-files-tp10984p11018.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
On 01/12/2015 10:48 PM, digital wrote:
Tried it out right now. How could I split each layer in the svg into
separate svg files?
I don't know if there's existing tools, but the generated SVG looks
very regular, so it's probably easily extracted using basic XML tools
or some scripting.
Essentially it seems to be just a list of layers like:
<g id="layer1" slic3r:z="3.75e-07"> <polygon slic3r:type="contour" points="57.85,3.44 ..." style="fill: white" /> <polygon slic3r:type="hole" points="16.425,4.15 ..." style="fill: black" /> </g>Another option is of cause to ask if it's possible to add an option
to Slic3r to separate the files (or maybe even export DXF too).
still, i've spent so much time on this issue that i am now resolved
to come up with a solution.
:-)
The focus of that project is more using a library to be able to read
more files saved by various programs. Right now the import is very
restrictive so special care has to be taken to get DXF files imported
correctly.
The project was up for GSoC and is now for "Semester of Code", but so
far there's (to my knowledge) nobody actively working on that. It would
be very nice to get that implemented, but I think it's not strictly
needed for multi-file export.
ciao,
Torsten.