discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Problem rendering code

D
drs
Fri, Apr 29, 2016 7:26 AM

Hi all,

I am having trouble rendering a code I have and converting the .scad into an
.STL file that I need.

Staggered_circle2_0.scad
http://forum.openscad.org/file/n17226/Staggered_circle2_0.scad

If anyone could help me rendering the code, I'd really appreciate it.

--
View this message in context: http://forum.openscad.org/Problem-rendering-code-tp17226.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Hi all, I am having trouble rendering a code I have and converting the .scad into an .STL file that I need. Staggered_circle2_0.scad <http://forum.openscad.org/file/n17226/Staggered_circle2_0.scad> If anyone could help me rendering the code, I'd really appreciate it. -- View this message in context: http://forum.openscad.org/Problem-rendering-code-tp17226.html Sent from the OpenSCAD mailing list archive at Nabble.com.
P
Parkinbot
Fri, Apr 29, 2016 9:34 AM

Your code produces something like this

http://forum.openscad.org/file/n17229/honey.png
http://forum.openscad.org/file/n17229/honey1.png

Is it, what you want? For a hexagonal honeycomb you would use code like
this:

rows=23;
columns=23;
levels=2;
walls=.6;
cell_interior=1.5;
height=0.4;

// data for the honey comb
Wall = 3walls;
w = 2
(cell_interior + walls);
h = sqrt(3)*(cell_interior + walls);
W = (columns+.5)w+2Wall;
H = (rows)h + 2Wall ;

linear_extrude(height = height)
honeycomb(rows,columns,cell_interior,walls, height);

module honeycomb(rows,columns,cell_interior,walls, height)
{
difference()
{
square([W, H]);
for(i=[0:columns-1], j=[0:rows-1])
{
col_offs = (j%2)?w/2:0;
translate([Wall + w*(.5+i) + col_offs, Wall + h*(.5+j)])
rotate(30)
circle(cell_interior, $fn=6);
}
}
}

--
View this message in context: http://forum.openscad.org/Problem-rendering-code-tp17226p17229.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Your code produces something like this <http://forum.openscad.org/file/n17229/honey.png> <http://forum.openscad.org/file/n17229/honey1.png> Is it, what you want? For a hexagonal honeycomb you would use code like this: > rows=23; > columns=23; > levels=2; > walls=.6; > cell_interior=1.5; > height=0.4; > > // data for the honey comb > Wall = 3*walls; > w = 2*(cell_interior + walls); > h = sqrt(3)*(cell_interior + walls); > W = (columns+.5)*w+2*Wall; > H = (rows)*h + 2*Wall ; > > linear_extrude(height = height) > honeycomb(rows,columns,cell_interior,walls, height); > > module honeycomb(rows,columns,cell_interior,walls, height) > { > difference() > { > square([W, H]); > for(i=[0:columns-1], j=[0:rows-1]) > { > col_offs = (j%2)?w/2:0; > translate([Wall + w*(.5+i) + col_offs, Wall + h*(.5+j)]) > rotate(30) > circle(cell_interior, $fn=6); > } > } > } -- View this message in context: http://forum.openscad.org/Problem-rendering-code-tp17226p17229.html Sent from the OpenSCAD mailing list archive at Nabble.com.
F
fred_dot_u
Fri, Apr 29, 2016 9:37 AM

I'm not much on programming, but there are a few things that jump out at me
in your code.

The first is that you've either removed or ignored common indent practices.
After a { you should expect the code to be indented one tab stop until it
returns to the margin by use of }.  This allows for more easily read code,
important for your troubleshooting.

The next thing that seems amiss to me is you have modules inside modules.
The entire block of code is nested inside "one" and "two". Your modules
belong outside any calls to them.

Consider to re-write your code using those practices and see what happens
next.

I would expect someone with better coding skills than I to offer additional
suggestions.

--
View this message in context: http://forum.openscad.org/Problem-rendering-code-tp17226p17230.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

I'm not much on programming, but there are a few things that jump out at me in your code. The first is that you've either removed or ignored common indent practices. After a { you should expect the code to be indented one tab stop until it returns to the margin by use of }. This allows for more easily read code, important for your troubleshooting. The next thing that seems amiss to me is you have modules inside modules. The entire block of code is nested inside "one" and "two". Your modules belong outside any calls to them. Consider to re-write your code using those practices and see what happens next. I would expect someone with better coding skills than I to offer additional suggestions. -- View this message in context: http://forum.openscad.org/Problem-rendering-code-tp17226p17230.html Sent from the OpenSCAD mailing list archive at Nabble.com.
D
drs
Fri, Apr 29, 2016 11:08 AM

Hi, I am not very good at writing codes. I am trying to produce something
like this:

http://forum.openscad.org/file/n17232/Staggered_circular_honeycomb.png

It is a "negative honeycomb" made of cylinders (instead of hexagons), and
the layers shifted a little bit with respect to the next one, as shown in
the image.

--
View this message in context: http://forum.openscad.org/Problem-rendering-code-tp17226p17232.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Hi, I am not very good at writing codes. I am trying to produce something like this: <http://forum.openscad.org/file/n17232/Staggered_circular_honeycomb.png> It is a "negative honeycomb" made of cylinders (instead of hexagons), and the layers shifted a little bit with respect to the next one, as shown in the image. -- View this message in context: http://forum.openscad.org/Problem-rendering-code-tp17226p17232.html Sent from the OpenSCAD mailing list archive at Nabble.com.
D
drs
Fri, Apr 29, 2016 11:20 AM

Hi, I'm not very good at coding. Are you suggesting it is not possible to
have one module nested inside another one?

--
View this message in context: http://forum.openscad.org/Problem-rendering-code-tp17226p17233.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Hi, I'm not very good at coding. Are you suggesting it is not possible to have one module nested inside another one? -- View this message in context: http://forum.openscad.org/Problem-rendering-code-tp17226p17233.html Sent from the OpenSCAD mailing list archive at Nabble.com.
F
fred_dot_u
Fri, Apr 29, 2016 12:28 PM

I'm no genius when it comes to coding either, but some things are engineered
to make life easier and that's where modules come in.

I can't say that modules can't be nested, but a more practical approach is
to nest the calls to the module. Modules "define" a sequence to be
performed, sometimes with parameters being passed by the calling command,
other times by parameters created within the module itself. Your variable
assignments should also be outside the module.

An example of "nothing":

variable_one = 10;
variable_two = 100;
variable_three = 50;

module make_cube(x_value, y_value, z_value){
cube([x_value, y_value, z_value]);
}

make_cube(4,5,6);

// end of code

the above "program" does nothing but make a cube, but only because the
make_cube(4,5,6); command is included at the end. I could nest that command,
which passed the parameters 4, 5, 6 to the module inside a loop and have the
parameters provided by the loop counter or other math performed inside the
loop.

It would make for a much cleaner and easier to read code.

--
View this message in context: http://forum.openscad.org/Problem-rendering-code-tp17226p17234.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

I'm no genius when it comes to coding either, but some things are engineered to make life easier and that's where modules come in. I can't say that modules can't be nested, but a more practical approach is to nest the calls to the module. Modules "define" a sequence to be performed, sometimes with parameters being passed by the calling command, other times by parameters created within the module itself. Your variable assignments should also be outside the module. An example of "nothing": variable_one = 10; variable_two = 100; variable_three = 50; module make_cube(x_value, y_value, z_value){ cube([x_value, y_value, z_value]); } make_cube(4,5,6); // end of code the above "program" does nothing but make a cube, but only because the make_cube(4,5,6); command is included at the end. I could nest that command, which passed the parameters 4, 5, 6 to the module inside a loop and have the parameters provided by the loop counter or other math performed inside the loop. It would make for a much cleaner and easier to read code. -- View this message in context: http://forum.openscad.org/Problem-rendering-code-tp17226p17234.html Sent from the OpenSCAD mailing list archive at Nabble.com.
P
Parkinbot
Fri, Apr 29, 2016 1:06 PM

ah, OK - it is quite hard to guess what a code producing no reasonable output
is meant to do.

Boolean operations over hundreds of objects with a high polygon count (you
use $fn = 100) are notoriously slow when it comes to rendering. It might be
a good idea to

  1. turn down your polygon count as low as possible (e.g. $fn=20)
  2. save an stl from a single layer and import it for boolean operations or
    use render() within code.

--
View this message in context: http://forum.openscad.org/Problem-rendering-code-tp17226p17235.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

ah, OK - it is quite hard to guess what a code producing no reasonable output is meant to do. Boolean operations over hundreds of objects with a high polygon count (you use $fn = 100) are notoriously slow when it comes to rendering. It might be a good idea to 1. turn down your polygon count as low as possible (e.g. $fn=20) 2. save an stl from a single layer and import it for boolean operations or use render() within code. -- View this message in context: http://forum.openscad.org/Problem-rendering-code-tp17226p17235.html Sent from the OpenSCAD mailing list archive at Nabble.com.
D
drs
Fri, Apr 29, 2016 2:38 PM

I exported the first 2 layers as an .STL file, as you suggested.
Here is the .scad file (no nested modules this time) that I exported to
.STL:
Staggered_circle2_0.scad
http://forum.openscad.org/file/n17238/Staggered_circle2_0.scad

However, when I import it and try to make boolean operations in another
.scad:
Staggered_circle_0.scad
http://forum.openscad.org/file/n17238/Staggered_circle_0.scad
and then try to render the model, I get this error:
ERROR: CGAL error in CGAL_Nef_polyhedron3(): CGAL ERROR: assertion
violation! Expr: pe_prev->is_border() ||
!internal::Plane_constructor::get_plane(pe_prev->facet(),pe_prev->facet()->plane()).is_degenerate()
File:
/opt/mxe/usr/x86_64-w64-mingw32.static/include/CGAL/Nef_3/polyhedron_3_to_nef_3.h
Line: 251

--
View this message in context: http://forum.openscad.org/Problem-rendering-code-tp17226p17238.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

I exported the first 2 layers as an .STL file, as you suggested. Here is the .scad file (no nested modules this time) that I exported to .STL: Staggered_circle2_0.scad <http://forum.openscad.org/file/n17238/Staggered_circle2_0.scad> However, when I import it and try to make boolean operations in another .scad: Staggered_circle_0.scad <http://forum.openscad.org/file/n17238/Staggered_circle_0.scad> and then try to render the model, I get this error: ERROR: CGAL error in CGAL_Nef_polyhedron3(): CGAL ERROR: assertion violation! Expr: pe_prev->is_border() || !internal::Plane_constructor::get_plane(pe_prev->facet(),pe_prev->facet()->plane()).is_degenerate() File: /opt/mxe/usr/x86_64-w64-mingw32.static/include/CGAL/Nef_3/polyhedron_3_to_nef_3.h Line: 251 -- View this message in context: http://forum.openscad.org/Problem-rendering-code-tp17226p17238.html Sent from the OpenSCAD mailing list archive at Nabble.com.
P
Parkinbot
Fri, Apr 29, 2016 3:49 PM

Seems like the stl produced by your code is not valid and needs repair.

Usually singular vertices/edges or float conversion inaccuracies are
responsible for errors like this. Try small overlapping (or distancing) of
layers and avoid boolean operations on objects just touching at one point or
line.

Try to alter Staggered_circle2_0.scad in this way and test with smaller
number of rows and columns first.

--
View this message in context: http://forum.openscad.org/Problem-rendering-code-tp17226p17239.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Seems like the stl produced by your code is not valid and needs repair. Usually singular vertices/edges or float conversion inaccuracies are responsible for errors like this. Try small overlapping (or distancing) of layers and avoid boolean operations on objects just touching at one point or line. Try to alter Staggered_circle2_0.scad in this way and test with smaller number of rows and columns first. -- View this message in context: http://forum.openscad.org/Problem-rendering-code-tp17226p17239.html Sent from the OpenSCAD mailing list archive at Nabble.com.
P
Parkinbot
Fri, Apr 29, 2016 3:55 PM

tried it on a smaller size and got same error. Works after adding .01 to the
stacked height.

// twice as big for now, not necesary to be that big though
honeycomb(rows2,columns2,cell_interior,walls,height+.01);

--
View this message in context: http://forum.openscad.org/Problem-rendering-code-tp17226p17240.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

tried it on a smaller size and got same error. Works after adding .01 to the stacked height. // twice as big for now, not necesary to be that big though honeycomb(rows*2,columns*2,cell_interior,walls,height+.01); -- View this message in context: http://forum.openscad.org/Problem-rendering-code-tp17226p17240.html Sent from the OpenSCAD mailing list archive at Nabble.com.