use / include and nested modules calls bug

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

use / include and nested modules calls bug

Apass
I'm having problems creating a hierarchical design using modules. For instance, I have 2 library files found in the 3d_idf_modules sub-folder and one main job file and I want to be able to use all of them using "use" statements.
For instance, the main job.scad looks like this:
 
comp_alfa  =0.5;
comp_red = 1;
comp_green = 0;
comp_blue = 0;
board_height = 1.4;
 
top_comp(comp_red, comp_green, comp_blue, comp_alfa, board_height);
 
use <3D_IDF_modules/generic_comp.3d>
use <3D_IDF_modules/comp_place.3d>
 
/////////
generic_comp.3d file contains:
 
module openscad_generic_component(hi) {
linear_extrude(height = hi)
circle(r = 2.5);
}
 
 
/////
comp_place.3d file contains - notice the calls to openscad_generic_component module inside the top_comp module
 
module top_comp(comp_red, comp_green, comp_blue, comp_alfa, board_height) {
color([comp_red, comp_green, comp_blue, comp_alfa])
translate([0, 0, board_height])
union() {
 translate([-58.97, 43.48, 0])
 rotate([0, 0, 180.00])
 openscad_generic_component(board_height);
 translate([-45, 43.48, 0])
 rotate([0, 0, 180.00])
 openscad_generic_component(board_height);
 }
}

When trying to compile the main file I get the following message and nothing is rendered
 
Loaded design `D:/xxx/3D_IDF_PCB/job.scad'.
Parsing design (AST generation)...
Compiling library `D:/xxx/3D_IDF_PCB/3D_IDF_modules/generic_comp.3d'.
Compiling library `D:/xxx/3D_IDF_PCB/3D_IDF_modules/comp_place.3d'.
Compiling design (CSG Tree generation)...
WARNING: Ignoring unknown module 'openscad_generic_component'.
WARNING: Ignoring unknown module 'openscad_generic_component'.
Compilation finished.
Compiling design (CSG Products generation)...
ERROR: CSG generation failed! (no top level object found)
PolySets in cache: 0
Polygons in cache: 0
CGAL Polyhedrons in cache: 0
Vertices in cache: 0
 
 
If I comment both use statements and move the modules to the main file everything works fine. Also, when I change
use <3D_IDF_modules/comp_place.3d> to include <3D_IDF_modules/comp_place.3d>, again, everything works fine.
However, I want to be able to acces the module(s) from the comp_place.3d file with the use statement.
I tested the code using the last windows release (openscad-2011.06) and OpenSCAD-2011.11.01 snapshot and in both I have the same problem.

Reply | Threaded
Open this post in threaded view
|

Re: use / include and nested modules calls bug

kintel
Administrator
On Dec 15, 2011, at 13:33 PM, Pasca Andrei wrote:

> If I comment both use statements and move the modules to the main file everything works fine. Also, when I change
> use <3D_IDF_modules/comp_place.3d> to include <3D_IDF_modules/comp_place.3d>, again, everything works fine.
> However, I want to be able to acces the module(s) from the comp_place.3d file with the use statement.

Libraries accessed using the use statement create their own scope, meaning they can only access functionality located in the global scope or child scopes to itself (i.e. explicitly imported from the same library file).

To import modules into the global scope, use the include statement instead of the use statement in your toplevel job.scad.

 -Marius


Reply | Threaded
Open this post in threaded view
|

Re: use / include and nested modules calls bug

Apass
Ok, thanks for clarifying it.
I whish this would have been specified also in the user manual.
I experimented a bit and I think I'll "use" or maybe "include" the generic_comp file in the other library file (it seems to work this way)

----- Original Message -----
From: Marius Kintel <[hidden email]>
To: Pasca Andrei <[hidden email]>; [hidden email]
Cc:
Sent: Friday, December 16, 2011 7:03 PM
Subject: Re: [OpenSCAD] use / include and nested modules calls bug

On Dec 15, 2011, at 13:33 PM, Pasca Andrei wrote:

> If I comment both use statements and move the modules to the main file everything works fine. Also, when I change
> use <3D_IDF_modules/comp_place.3d> to include <3D_IDF_modules/comp_place.3d>, again, everything works fine.
> However, I want to be able to acces the module(s) from the comp_place.3d file with the use statement.

Libraries accessed using the use statement create their own scope, meaning they can only access functionality located in the global scope or child scopes to itself (i.e. explicitly imported from the same library file).

To import modules into the global scope, use the include statement instead of the use statement in your toplevel job.scad.

-Marius

Reply | Threaded
Open this post in threaded view
|

Re: use / include and nested modules calls bug

Brad Pitcher
On Fri, Dec 16, 2011 at 10:14 AM, Pasca Andrei <[hidden email]> wrote:
Ok, thanks for clarifying it.
I whish this would have been specified also in the user manual.
I experimented a bit and I think I'll "use" or maybe "include" the generic_comp file in the other library file (it seems to work this way)


Please update the user manual to clarify this. 
Reply | Threaded
Open this post in threaded view
|

3 different experimental patches for viewport - reloaded

Apass
I can't check the youtube link to see how it behaves (I get 404 error - but maybe that's because of the company proxy) - but as far as I understand your statements, subsequent saves for the current file will not reset the viewport.
However, at least for what I'm working, this would be what I whish, because I'm creating a model with another progam an I'm using OpenSCAD with autoreload and compile. I would like to be able to set the viewport at each recompile.
Imagine that my model consists, let't say, of 3 objects drawn one above the other and using transparency (although it's transparent, you won't see other objects through the last drawn object). I want to be able to change the drawing order (using the external program) and with this, to change also the viewport to match the current object drawing order.
Is there another way of changing on the fly the viewport like exporting / importing a windows registry key? (I'm using Windows and I'll stick to this)?
Also - I had a quick look at the last dev snapshot - but as far as I saw, this viewport settings are not implemented in the main version - will this ever be included in a release?