module function not working

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

module function not working

jjnat14
Hi, I'm a newbie and have just started exploring openScad. For some reason whenever I try to create a module function, it returns a 'No top level geometry to render' error. I've tried it multiple times and it always results in this error. I'm clueless now. An example code and a screenshot of the error are below.

radius=16;
sides=5;
thickness=1.5;

module polyshape(){

difference(){
    //outside part
offset(r=5,$fn=48)
circle(r=radius, $fn=sides);
    //inside part which is being subtracted
    offset(r=5-thickness,$fn=48)
circle(r=radius, $fn=sides);}
}



Thanks in advance!
Reply | Threaded
Open this post in threaded view
|

Re: module function not working

macdarren
This is pretty common for non-programmers.

The deal is you have created the module but you never invoke it.

you need to add the line:

polyshape();

in the main part of the program..I typically place it at the top

Darren


> On Jan 17, 2016, at 7:56 PM, jjnat14 <[hidden email]> wrote:
>
> Hi, I'm a newbie and have just started exploring openScad. For some reason
> whenever I try to create a module function, it returns a 'No top level
> geometry to render' error. I've tried it multiple times and it always
> results in this error. I'm clueless now. An example code and a screenshot of
> the error are below.
>
> radius=16;
> sides=5;
> thickness=1.5;
>
> module polyshape(){
>
> difference(){
>    //outside part
> offset(r=5,$fn=48)
> circle(r=radius, $fn=sides);
>    //inside part which is being subtracted
>    offset(r=5-thickness,$fn=48)
> circle(r=radius, $fn=sides);}
> }
>
> <http://forum.openscad.org/file/n15744/Screen_Shot_2016-01-17_at_10.png>
>
> Thanks in advance!
>
>
>
> --
> View this message in context: http://forum.openscad.org/module-function-not-working-tp15744.html
> Sent from the OpenSCAD mailing list archive at Nabble.com.
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: module function not working

doug.moen
In reply to this post by jjnat14
A module is like a function definition: it defines a named "function" which takes arguments, and returns geometry as a result. It doesn't "do" anything by itself.

If you don't call the module, then no geometry is generated.

Add the following code to the end of your script, which calls the module:

polyshape();

On 17 January 2016 at 22:56, jjnat14 <[hidden email]> wrote:
Hi, I'm a newbie and have just started exploring openScad. For some reason
whenever I try to create a module function, it returns a 'No top level
geometry to render' error. I've tried it multiple times and it always
results in this error. I'm clueless now. An example code and a screenshot of
the error are below.

radius=16;
sides=5;
thickness=1.5;

module polyshape(){

difference(){
    //outside part
offset(r=5,$fn=48)
circle(r=radius, $fn=sides);
    //inside part which is being subtracted
    offset(r=5-thickness,$fn=48)
circle(r=radius, $fn=sides);}
}

<http://forum.openscad.org/file/n15744/Screen_Shot_2016-01-17_at_10.png>

Thanks in advance!



--
View this message in context: http://forum.openscad.org/module-function-not-working-tp15744.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org




_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: module function not working

jjnat14
In reply to this post by jjnat14
Thank you