Object not occuring when include several times same .scad-file.

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

Object not occuring when include several times same .scad-file.

chemiey
Hello OpenSCAD community

I am new to 3D modelling and relatively equal newbe to programming-code so please have mercy on my thread if this subject is already covered or if there might be an easy piece-of-cake solution to this.

I am trying different means of indexing the code. My, so far, best-build option of index is by making each object for itself (fx a tube) then halfing it in another. (new shape, new file). Though it requires a (possibly) large chain of "include<*.scad>; each for every file.

The problem is that i have made a plate, a halfpipe, a plate-and-a-halfpipe, and now want to make a file several of the plateandhalfpipe. But the halfpipe is missing on the second (and third) include of the same file so that it is only the plate.

This is the code:

include<vinge.scad>;
translate([0,69,0])
include<vinge.scad>;
translate([0,100,0])
include<vinge.scad>;
doubleincludeerror
Reply | Threaded
Open this post in threaded view
|

Re: Object not occuring when include several times same .scad-file.

chemiey
Well I didn't come across an answer that solved the include-issue but I found out another solution to the central problem itself. Exporting the shape/object as .stl and using import-method made it without any parts of the object missing.

I guess that it is a question of difference between a modelled/rendered item, and the code for making it - but it is only a guess.
Reply | Threaded
Open this post in threaded view
|

Re: Object not occuring when include several times same .scad-file.

doug.moen
In reply to this post by chemiey
You don't show the contents of 'vinge.scad'. But i can guess the problem.

The include <filename> statement is implemented by replacing the text 'include <filename>' with the contents of 'filename', and then interpreting the resulting text as an OpenSCAD script.

Since vinge.scad implements plate-and-a-halfpipe, I suppose it contains more than one top-level statement (after include statements are processed). I'm guessing the plate is the first statement, and the halfpipe is the second statement. So in

translate([0,69,0])
include<vinge.scad>;

after expanding the include, then you'll have something like

translate([0,69,0])
plate();
halfpipe();

and the translate will only be applied to the plate, not to the halfpipe. So you have three identical halfpipes superimposed at the same position.

I recommend that you switch to a different coding idiom. Each include file defines a module of the same name, and the module is explicitly invoked by the including script. So your code will look like this:

include<vinge.scad>;

vinge();
translate([0,69,0]) vinge();
translate([0,100,0]) vinge();


On 12 August 2015 at 14:23, chemiey <[hidden email]> wrote:
Hello OpenSCAD community

I am new to 3D modelling and relatively equal newbe to programming-code so
please have mercy on my thread if this subject is already covered or if
there might be an easy piece-of-cake solution to this.

I am trying different means of indexing the code. My, so far, best-build
option of index is by making each object for itself (fx a tube) then halfing
it in another. (new shape, new file). Though it requires a (possibly) large
chain of "include<*.scad>; each for every file.

The problem is that i have made a plate, a halfpipe, a plate-and-a-halfpipe,
and now want to make a file several of the plateandhalfpipe. But the
halfpipe is missing on the second (and third) include of the same file so
that it is only the plate.

This is the code:

include<vinge.scad>;
translate([0,69,0])
include<vinge.scad>;
translate([0,100,0])
include<vinge.scad>;
<http://forum.openscad.org/file/n13513/OpenSCAD_issue.jpg>



--
View this message in context: http://forum.openscad.org/Object-not-occuring-when-include-several-times-same-scad-file-tp13513.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: Object not occuring when include several times same .scad-file.

chemiey
The code for vinge.scad is:
cube([35,1,135]);

translate([0.1,0.5,0])
include<halfcylinder2.scad>


I am not familiar with how you achieve to make or to use the 'selfmade' methods such as vinge() (for me it looks like another "translate()"-method. I guess that these are what is called "Classes" and can be inherited by other fragments of code and reshaped/modelled for specific purpose.(Change of color etc)

But what I am understanding is that my library will be better of constructing the model from the different parts of the objects (plate, halfpipe) for themselves and linking to the most simple objects in itself, then by rotating/translating or what else needs to be done. Different from the accumulating progress i had before.
Reply | Threaded
Open this post in threaded view
|

Re: Object not occuring when include several times same .scad-file.

G. Wade Johnson
On Wed, 12 Aug 2015 12:22:38 -0700 (MST)
chemiey <[hidden email]> wrote:

> The code for vinge.scad is:
> /cube([35,1,135]);
>
> translate([0.1,0.5,0])
> include<halfcylinder2.scad>/

Following up on what doug said:

You are trying to treat a scad file as a unit of geometry. In OpenSCAD,
that is handled with a module.

Replace the code for vinge.scad with this definition:

   module vinge()
   {
      cube([35,1,135]);
      translate([0.1,0.5,0])
         halfcylinder2();
   }

Assuming the code for halfcylinder2.scad, looks something like this:

   intersection() {
       cylinder( h=10, r=5, center=true );
       translate([5,0,0]) cube([10, 10, 11], center=true )
   }

you could define the module halfcylinder2 as

   module halfcylinder2()
   {
       intersection() {
           cylinder( h=10, r=5, center=true );
           translate([5,0,0]) cube([10, 10, 11], center=true )
       }
   }

To get it to render, you would then call the module as:

   vinge();

To translate these, you could do

   vinge();
   translate([0,69,0]) vinge();
   translate([0,100,0]) vinge();

It seems that the only piece you are missing here is the use of a
module for a reusable piece of geometry.

G. Wade

> I am not familiar with how you achieve to make or to use the
> 'selfmade' methods such as vinge() (for me it looks like another
> "translate()"-method. I guess that these are what is called "Classes"
> and can be inherited by other fragments of code and reshaped/modelled
> for specific purpose.(Change of color etc)
>
> But what I am understanding is that my library will be better of
> constructing the model from the different parts of the objects (plate,
> halfpipe) for themselves and linking to the most simple objects in
> itself, then by rotating/translating or what else needs to be done.
> Different from the accumulating progress i had before.
>
>
>
> --
> View this message in context:
> http://forum.openscad.org/Object-not-occuring-when-include-several-times-same-scad-file-tp13513p13517.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


--
A tautology is a thing which is tautological.

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

Re: Object not occuring when include several times same .scad-file.

chemiey
Thank you for your advice!
I will continue exercising:
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Modules