seasick / openscad-web-gui

Web GUI for OpenSCAD, using OpenSCAD WASM

Home Page:https://seasick.github.io/openscad-web-gui/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for projection() and writing out DXF files

WillAdams opened this issue · comments

As discussed on Reddit:

https://old.reddit.com/r/openscad/comments/19bos33/i_created_an_openscad_web_application_to_make_it/kj59tb2/?context=3

It would help folks use this tool for designs suited to be described as DXFs (say for cutting out on a CNC).

Example file here:

https://raw.githubusercontent.com/WillAdams/Design_Into_3D/master/designinto3dboxfitted.scad

There's a Customizer option:

Generate_DXF_or_STL = 2;//[1:DXF,2:STL]

which when set to 1 (DXF) enables a

projection()

command which will allow a DXF (or SVG) to be exported after a project is Rendered (F6)

Thanks for creating this issue @WillAdams.

I've added the export functionality for DXF and SVG. The script you shared exports the following SVG:

drawing

It also exports DXF, but Github doesn't support showing that file type here.

But at the moment, I don't know yet how I could detect that the result of the script will be 2D. Currently there is only a log entry of OpenSCAD after it is rendered ( -> Current top level object is not a 3D object., which is what happens if you try to export the projection as STL).

Awesome! Thank you!

Maybe the OpenSCAD developers could provide a hook for this?

Thanks! This works (but I'm currently getting an older version of the .scad file from my Github --- any way to force the new one?)

It's a bit disconcerting since choosing "DXF" and then clicking "RENDER" still gets the 3D preview, but when one selects "Export SVG" (or DXF) it works.

EDIT: Would it be possible to set the "Generate_DXF_or_STL" variable using:

 -D [ --D ] arg               var=val -pre-define variables

and have that over-ride the Customizer setting? How would/could this be specified?

Thanks! This works (but I'm currently getting an older version of the .scad file from my Github --- any way to force the new one?)

You could try to reset the cache. But could also be because of the CORS proxy I'm using. I'm planning to use another cors proxy in the future, where I can have more control over it.

It's a bit disconcerting since choosing "DXF" and then clicking "RENDER" still gets the 3D preview, but when one selects "Export SVG" (or DXF) it works.

I understand that and I probably find some solution for the 2D render issue at one point.

EDIT: Would it be possible to set the "Generate_DXF_or_STL" variable using:

 -D [ --D ] arg               var=val -pre-define variables

and have that over-ride the Customizer setting? How would/could this be specified?

Not entirely sure if I'm understanding you correctly. If you don't want the setting available in the customizer, you can add it to the end of the variable definition and place a "dummy" module/function above it - similar to how its described in the OpenSCAD wiki.

I was wondering if including the variable at the command line would help in making the preview consistent, but it seems that's some other difficulty?

The variables that are available in the customizer are already used as parameters (-D varname=value).

The challenge with this feature is, that this tool assumes that everything is 3d and requests an STL from OpenSCAD to render the preview. To determine, that we have to request e.g. SVG for a preview would require that the tool can detect if e.g. projection() is used. Basically we have to search if the code contains projection. A simple text search might work for most of the cases, but for example in your script the projection() is always there, but not used always as it depends on a variable. So just searching for it would not work for your example.

Another approach could be to export an SVG for preview when it sees "Current top level object is not a 3D object." in the logs.

I guess the question here is how can one get a better (flatter?) view when DXF/SVG is selected --- I see such a view in OpenSCAD:

image

would it be possible to see that in the web version?

At some point, yes

The app now supports rendering 2D output (i.e. when projection() is used). This works by falling back to SVG export when OpenSCAD warns about no top level object being a 3D object. The (internally) exported SVG is then handed over to the preview view.
When a 3D object is previewed, the exports for 2D is disabled and vice-versa.

image