I will be needing to make objects as displayed in the picture. Many
different shapes. These will be used throughout different projects for
building things.
The object you see was created with an inner and outer array of X,Y vectors
each having variable names (i.e. shapeOuter, shapeInner). Each of these
were used with the difference() and offset_sweep() functions commands to
create the object.
How can I create callable SCADs for this and other shaped objects so that
they may be included into different projects without the need to recreate
each object in every project that receives it? In other words, just
including or calling or using them.
Their use will be in different positions in different projects so they will
need to be called into use and positioned correctly.
How do I avoid overwriting variable names that created them with this
procedure?
[image: example.png]
[ Punched the wrong button and sent this privately first. Joe, sorry
for the duplicate. ]
There are three related parts of doing this sort of thing.
First, you probably want to put each of your things into a module.
module mySphereThing(d=10) {
difference() {
sphere(d=d);
cube([d/2, d/2, d*2], center=true);
}
}
module myCubeThing(d=10) {
difference() {
cube(d, center=true);
cylinder(h=d*2, d=d/2, center=true);
}
}
and invoke them like so:
translate([-20,0,0]) mySphereThing();
translate([20,0,0]) myCubeThing(15);
Second, one of two similar options. Both start with putting your
definitions into a separate file - call it myThings.scad.
You can refer to a file using either
include <myThings.scad>
or
use <myThings.scad>
In either case, you can then refer to your modules from the calling file
Which of the two styles is right depends on your needs. If you need to
share variables, you need to use "include". If you need to keep them
separate, you need to use "use".
The general intent is that "use" is good for libraries. It allows those
library files to be independently executable - since their top level
geometry is not executed at "use" time, they can include demonstration /
test invocations. It avoids polluting the caller's namespace with the
library's variables. It avoids having the library accidentally call the
main program's functions or modules.
In complex cases "use" has performance problems, and its interactions
with global-level $ variables are ... subtle. However, for simple cases
neither of those is a significant factor.
Where should you put your library file myThings.scad? There are, I
believe, four options. The details depend on your platform, but they
are basically:
Have you looked into modules?
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/User-Defined_Functions_and_Modules#Modules
Peter-Frank Spierenburg
Sent from Outlookhttp://aka.ms/weboutlook
From: Joe Weinpert joe.weinpert@gmail.com
Sent: May 5, 2022 5:33 PM
To: OpenSCAD general discussion discuss@lists.openscad.org
Subject: [OpenSCAD] Saving and retrieving objects
I will be needing to make objects as displayed in the picture. Many different shapes. These will be used throughout different projects for building things.
The object you see was created with an inner and outer array of X,Y vectors each having variable names (i.e. shapeOuter, shapeInner). Each of these were used with the difference() and offset_sweep() functions commands to create the object.
How can I create callable SCADs for this and other shaped objects so that they may be included into different projects without the need to recreate each object in every project that receives it? In other words, just including or calling or using them.
Their use will be in different positions in different projects so they will need to be called into use and positioned correctly.
How do I avoid overwriting variable names that created them with this procedure?
[example.png]