I think openjscad lets you attach a property to an object and then
transforms it in the same way as the object. Why can’t this be done in
openscad?
Edmund
This is possible when using the pythonized fork of openscad.
Check out
https://guenther-sohler.net/openscad/tutorial/site/python_specialities/
for details
On Wed, Oct 4, 2023 at 3:12 PM edmund ronald edmundronald@gmail.com wrote:
I think openjscad lets you attach a property to an object and then
transforms it in the same way as the object. Why can’t this be done in
openscad?
Edmund
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
On 10/4/2023 6:11 AM, edmund ronald wrote:
I think openjscad lets you attach a property to an object and then
transforms it in the same way as the object. Why can’t this be done in
openscad?
"Can't" is a very strong word.
Could it be done? Maybe. Can it be done easily? That's a whole
different question.
The first, and probably biggest, problem is that structurally OpenSCAD
doesn't pass around its geometric objects using a mechanism that would
let you extract values from them. Suppose that you could add an extra
attribute to a cube like so:
cube(extra="hello");
Now... how do you get it back?
You could imagine a language where cube() was a function that returned
something, and then you would have a "handle" you could use to retrieve
the extra attribute... but OpenSCAD doesn't do that, and it would be a
significant change to allow it to.
PR#4478 has some related concepts - one alternative that it experiments
with has geometric objects as something you can pass around, and has
what other languages would call objects, dictionaries, or associative
arrays. Another alternative combines those two into a hybrid object
that has both geometry and values. (But: the values aren't
automatically transformed or passed through when the object is transformed.)
Yes, I think you raise some interesting issues in programming language
semantics
On Wednesday, October 4, 2023, Jordan Brown openscad@jordan.maileater.net
wrote:
On 10/4/2023 6:11 AM, edmund ronald wrote:
I think openjscad lets you attach a property to an object and then
transforms it in the same way as the object. Why can’t this be done in
openscad?
"Can't" is a very strong word.
Could it be done? Maybe. Can it be done easily? That's a whole
different question.
The first, and probably biggest, problem is that structurally OpenSCAD
doesn't pass around its geometric objects using a mechanism that would let
you extract values from them. Suppose that you could add an extra
attribute to a cube like so:
cube(extra="hello");
Now... how do you get it back?
You could imagine a language where cube() was a function that returned
something, and then you would have a "handle" you could use to retrieve the
extra attribute... but OpenSCAD doesn't do that, and it would be a
significant change to allow it to.
PR#4478 has some related concepts - one alternative that it experiments
with has geometric objects as something you can pass around, and has what
other languages would call objects, dictionaries, or associative arrays.
Another alternative combines those two into a hybrid object that has both
geometry and values. (But: the values aren't automatically transformed or
passed through when the object is transformed.)
On 04.10.23 15:11, edmund ronald wrote:
I think openjscad lets you attach a property to an object and > then transforms it in the same way as the object. Why can’t
this be done in openscad?
You can't attach properties to objects because OpenSCAD does
not have objects (yet?).
The current way of doing this is having a module which defines
the positioning. As added bonus, you can easily group things
with one module defining the placement logic (e.g. place 4
related things at once) and pass additional data (e.g. an extra
Z offset).
w = 100;
l = 200;
o = 20;
module pos(z = 0) {
for (x = [-1, 1], y = [-1, 1])
translate([x * (w/2 - o), y * (l/2 - o), z])
children();
}
difference() {
union() {
cube([w, l, 10], center = true);
pos(5) cylinder(h = 20, r1 = 10, r2 = 5);
}
pos() cylinder(h = 100, r = 3, center = true);
}
ciao,
Torsten.
You can fake proper objects though, if you're willing to do the work to set
them up in the first place: openscad_objects 1 was built for collecting
arbitrary list-based properties into a single "object" bundle to make
building multiple varieties of things simple. I don't think it's been used
to set absolute positioning data, but I don't see why it couldn't.
On Wed, Oct 4, 2023 at 11:31 AM Torsten Paul Torsten.Paul@gmx.de wrote:
On 04.10.23 15:11, edmund ronald wrote:
I think openjscad lets you attach a property to an object and > then
transforms it in the same way as the object. Why can’t
this be done in openscad?
You can't attach properties to objects because OpenSCAD does
not have objects (yet?).
The current way of doing this is having a module which defines
the positioning. As added bonus, you can easily group things
with one module defining the placement logic (e.g. place 4
related things at once) and pass additional data (e.g. an extra
Z offset).
w = 100;
l = 200;
o = 20;
module pos(z = 0) {
for (x = [-1, 1], y = [-1, 1])
translate([x * (w/2 - o), y * (l/2 - o), z])
children();
}
difference() {
union() {
cube([w, l, 10], center = true);
pos(5) cylinder(h = 20, r1 = 10, r2 = 5);
}
pos() cylinder(h = 100, r = 3, center = true);
}
ciao,
Torsten.
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
--