2

is it possible to pass a value from openjscad to javascript?

I would like to show the dimensions of a 3d-object in a div or any other html-element.

Example: A cube is created with openjscad with the following parameters:

function main() {
    var cube = CSG.cube({
        center: [0, 0, 0],
        radius: [1, 2, 3]
    });
    return cube;
}

How can I pass the parameters for center and radius to javascript in order to use them in other areas of the website?

TimoStaudinger
  • 41,396
  • 16
  • 88
  • 94
Lukas
  • 148
  • 2
  • 12

1 Answers1

3

I did this by making my own cube object, you can add all the variables you want and add some functions too like my translate function.

function myCube(size,pos){
    this.obj = cube({size:size,center:false}).translate(pos);
    this.size = size;
    this.pos = pos;
    this.translate = function(pos){
        this.obj.translate(pos);
    };
}

then you can make a cube like this var MC = new myCube(radius, [x,y,z]);

and now to get your radius you can do MC.size;

it does get tricky when you try to do something with the shape itself, you'll have to do something like union(MC.obj, CIL.obj)

ps: I hope this helps although I know this isn't the ideal way and there's probably some easy way of doing it but this worked for me.

Sam Apostel
  • 593
  • 3
  • 18