OpenSCAD: Difference between revisions
| Line 12: | Line 12: | ||
A SCAD file can include other SCAD files with either the <tt>include</tt> or <tt>use</tt> keywords. <tt>include</tt> statements are replaced with the body of the <tt>include</tt>d file (any <tt>include</tt>s or <tt>use</tt>s within the file are expanded). <tt>use</tt> only lifts <tt>module</tt>s and <tt>function</tt>s, and only affects the current file (i.e. recursive <tt>use</tt>s do not escape beyond the file that <tt>use</tt>s them). | A SCAD file can include other SCAD files with either the <tt>include</tt> or <tt>use</tt> keywords. <tt>include</tt> statements are replaced with the body of the <tt>include</tt>d file (any <tt>include</tt>s or <tt>use</tt>s within the file are expanded). <tt>use</tt> only lifts <tt>module</tt>s and <tt>function</tt>s, and only affects the current file (i.e. recursive <tt>use</tt>s do not escape beyond the file that <tt>use</tt>s them). | ||
It's useful to have a file draw its various modules, so that running it at the top level generates examples etc. Such a file can be imported with <tt>use</tt>, and these examples won't be drawn. | It's useful to have a file draw its various modules, so that running it at the top level generates examples etc. Such a file can be imported with <tt>use</tt>, and these examples won't be drawn. The downside is that any variables declared in a <tt>use</tt>d file are unavailable, so you might want to wrap them in <tt>function</tt> accessors. | ||
These cannot be used within a <tt>module</tt> or <tt>function</tt>. | These cannot be used within a <tt>module</tt> or <tt>function</tt>. | ||