JSCAD User Group
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Website "load a file" functionality?

    Scheduled Pinned Locked Moved General Discussions
    14 Posts 4 Posters 3.7k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • sheffieldnickS Offline
      sheffieldnick
      last edited by

      Hi,

      I'm new to OpenJSCAD. Is there an API on the openjscad.org site to load & render a supplied JSCAD script as a URL parameter? e.g.

      https://www.openjscad.org/?file=https://my.url/something.jscad

      or

      https://www.openjscad.org/?script=function main () {...

      I have a web page that generates a jscad file with javascript, and I'd like to be able to render it on the openjscad.org site with just a single click.

      Thanks

      1 Reply Last reply Reply Quote 0
      • gilboonetG Offline
        gilboonet
        last edited by gilboonet

        Hello, it can be done like that, put a "#" after openJSCAD.org then the url of your script.
        https://openjscad.org/#https://raw.githubusercontent.com/gilboonet/designs/master/make_pattern.jscad

        sheffieldnickS 1 Reply Last reply Reply Quote 1
        • sheffieldnickS Offline
          sheffieldnick
          last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • sheffieldnickS Offline
            sheffieldnick @gilboonet
            last edited by

            Thanks 🙂 It doesn't seem to support data: URIs? e.g.

            https://www.openjscad.org/#data:text/javascript;charset=utf-8;base64,ZnVuY3Rpb24gbWFpbiAoKSB7DQogIHJldHVybiB1bmlvbigNCiAgICBjdWJlKHtzaXplOiBbMjAyLDEwNCw0XX0pLA0KICAgIGN5bGluZGVyKHtyOiAyLCBoOiA2fSkudHJhbnNsYXRlKFsxMCw1LDRdKSwNCiAgICBjeWxpbmRlcih7cjogMiwgaDogNn0pLnRyYW5zbGF0ZShbMjAyLTEwLDUsNF0pDQogICk7DQp9

            should load the script:

            function main() {
              return union(
                cube({size: [202,104,4]}),
                cylinder({r: 2, h: 6}).translate([10,5,4]),
                cylinder({r: 2, h: 6}).translate([202-10,5,4])
              );
            }
            

            Thanks

            gilboonetG z3devZ 2 Replies Last reply Reply Quote 0
            • gilboonetG Offline
              gilboonet @sheffieldnick
              last edited by

              @sheffieldnick I don't remember that it handles data protocol, only used if with file names

              1 Reply Last reply Reply Quote 0
              • z3devZ Offline
                z3dev @sheffieldnick
                last edited by

                @sheffieldnick sorry, but only full URLs are supported.

                there's a backend process involved, that down loads the URL contents, and posts the contents to the WEB UI.

                i think that you are trying to create a custom website using a JSCAD design in the back ground. if so you can look at some of the previous threads posted here, so on the issue list.

                sheffieldnickS 1 Reply Last reply Reply Quote 0
                • sheffieldnickS Offline
                  sheffieldnick @z3dev
                  last edited by

                  @z3dev Thanks. I've done some searches of previous threads but couldn't find anything directly relevant.

                  Here is my site that dynamically generates a small piece of JSCAD code for 3D printing a stencil alignment jig for PCBs:

                  https://climbers.net/sbc/kicad-pcb-panelization-javascript/

                  at the moment I'm just asking users to copy'n'paste the code into the jscad.org website, but it would be great if you could add support for loading content with data: URIs so that I could provide a simple link and avoid the extra copy'n'paste steps.

                  It should be very easy to support data: URIs, and you wouldn't need the backend process to get around CORS issues, etc.

                  gilboonetG sheffieldnickS 2 Replies Last reply Reply Quote 0
                  • gilboonetG Offline
                    gilboonet @sheffieldnick
                    last edited by gilboonet

                    @sheffieldnick As V2 is on active development, I don't think that new functionality could be add to V1, but I'm only a user not a developer. This project could maybe help you :
                    https://github.com/danmarshall/jscad-gallery
                    Or you could also do a fork. Long ago, I added some functionalities to OpenJSCAD v0.5 so the user can select a data file that will load openJSCAD with a .jscad file and populate it with parameters, but it's very old code (from 2016) that's not on github... http://gilboo.carton.free.fr/OJSC5/edit_ner2.html

                    sheffieldnickS 1 Reply Last reply Reply Quote 0
                    • sheffieldnickS Offline
                      sheffieldnick @sheffieldnick
                      last edited by sheffieldnick

                      @sheffieldnick said in Website "load a file" functionality?:

                      It should be very easy to support data: URIs, and you wouldn't need the backend process to get around CORS issues, etc.

                      Looking at the V1 source (which is what the public site is running?), it appears the loading is done in /packages/web/src/ui/examples.js in function loadInitialExample(). Adding something like this would probably work:

                      const isData = documentUri ? documentUri.match(/(data:\S+)$/) !== null : false
                      
                      ...
                      
                          } else if (isData) { // base64-encoded data example, e.g. https://openjscad.org/#data:...
                            loadLocalStorage(atob(documentUri.split(',')[1]), params)
                      
                      z3devZ 1 Reply Last reply Reply Quote 0
                      • sheffieldnickS Offline
                        sheffieldnick @gilboonet
                        last edited by

                        @gilboonet Thanks, but I'm not interested in running my own custom version of the site. I just want to link to the public website, hence the request to add this feature.

                        1 Reply Last reply Reply Quote 0
                        • z3devZ Offline
                          z3dev @sheffieldnick
                          last edited by

                          @sheffieldnick this would be a nice addition, but V2 is the main focus now. we would welcome changes to make this part of V2. 🙂

                          1 Reply Last reply Reply Quote 0
                          • Z Offline
                            zorglups
                            last edited by zorglups

                            Strangely enough, the following link won't work:
                            https://openjscad.org/?uri=https://www.thingiverse.com/download:106799

                            This is said because it would make easy to let people open an openjscad object from a link in the thingiverse description.

                            The error is:
                            Uncaught Error: The JSCAD script must contain a function main() which returns one or more CSG or CAG solids.
                            Line: 89,col: 7

                            Tjere is a main() though.

                            gilboonetG z3devZ 2 Replies Last reply Reply Quote 0
                            • gilboonetG Offline
                              gilboonet @zorglups
                              last edited by gilboonet

                              @zorglups The syntax is not ?url=[your_url] but #[your_url]. But on this case, the url is a download url, the script must be downloaded then dropped to OpenJSCAD.org file drop zone (bottom left frame).

                              1 Reply Last reply Reply Quote 0
                              • z3devZ Offline
                                z3dev @zorglups
                                last edited by z3dev

                                @zorglups there's a bug in the V1 proxy script, remote.pl, and this prevents files to be loaded properly if the file (URL) does not have a proper extention.

                                a fix has been made, and the V2 website is running the fixed version of remote.pl

                                but you need to provide a URL which accesses a V2 design, such as...

                                https://www.jscad.xyz?uri=https://www.thingiverse.com/download:8705160

                                OR

                                https://www.jscad.xyz#https://www.thingiverse.com/download:8705160

                                1 Reply Last reply Reply Quote 0

                                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                With your input, this post could be even better 💗

                                Register Login
                                • First post
                                  Last post
                                Powered by NodeBB | Contributors