JSCAD User Group

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    function in getParameterDefinition

    Development Discussions
    2
    5
    2825
    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.
    • I
      imkael last edited by

      Hello everyone, i don't know if i'm at the right place. I want to know if there is a way to use some function in getParameterDefinitions. i have a list of things that i always use as parameter in my jscad project. Each time i change something in this list i have to open all my jscad files and change my parameters. Is there any way to put my list in an include file and retrieve it in the getParameterDefinition? Hope i'm clear. Thanks in advance for your answers

      1 Reply Last reply Reply Quote 0
      • I
        imkael @kaosat-dev last edited by

        @kaosat-dev thanks for your reply i haven't test it yet (I just saw it today). i will tell you if it's works for me. Best regards

        1 Reply Last reply Reply Quote 0
        • kaosat-dev
          kaosat-dev @imkael last edited by

          @imkael désolé pour la réponse très tardive !

          • la version expérimentale avec gestion de modules est ici: https://jscad.xyz/playground.html
          • si j'ai bien compris, oui ça devrait être possible
          • il faudra juste bien exporter les bonnes variables dans chaque module:

          drilling.jscad

          const listdrill = function listdrill(type) {
          
            var toreturn = [];
            if (type == ' countersunk'){
            toreturn=[
              [1.6,3.73,1],
              [2,4.78,1.1],
              [3,6.82,1.4],
            ...
            ];
            if( type =='hexagonal'){
              toreturn = [......
            ];
            return toreturn;
          }
          // IMPORTANT !!
          module.exports = listdrill
          
          

          index.jscad

          const listdrill = require('..path/to/drilling.jscad')
          
          function getParameterDefinitions{
            const listdrillPerType = listdrill(type);
            const foruser = '{name:'drillDiameter', initial: '3', type:'choice', caption: 'diameter', values: [';
            for(i=0;i<listdrillPerType.length;i++) {
             foruser= foruser+'''+listdrillPerType[i][0]+'',';}
              ...
            return[
              foruser,
            ];
           }
          
          function main (params) {
          }
          
          module.exports = { getParameterDefinitions, main }
          
          1 Reply Last reply Reply Quote 0
          • I
            imkael last edited by imkael

            Thanks @kaosat-dev Kaosat-dev but it's not really what i'm trying to do. I have a first file that contains parameters for screws to make holes easily in printed parts you have countersunk head, hexagonal head, cylindrical head etc... and for each you have different diameters of scew. For each new files that i creates who use this include file i've to make a section of choice in getParameterDefinitions . Is it posible to do something to retrieve those parameters directly in the first file. an exemple of what i'm trying to do:

            drilling.jscad
            [code]
            listdrill = function listdrill(type){
            var toreturn = [];
            if (type == ' countersunk'){
            toreturn=[
            [1.6,3.73,1],
            [2,4.78,1.1],
            [3,6.82,1.4],
            ...
            ];
            if( type =='hexagonal'){
            toreturn = [......
            ];
            }
            return toreturn;
            }
            [/code]
            and in the other file :
            [code]
            include("..path/to/drilling.jscad");

            function getParameterDefinitions{
            var listdrill = listdrill(type);
            var foruser='{name:'drillDiameter', initial: '3', type:'choice', caption: 'diameter', values: [';
            for(i=0;i<listdrill.length;i++){
            foruser= foruser+'''+listdrill[i][0]+'',';}
            ...
            return[
            foruser,
            ];
            }
            [/code]
            This is an exemple of what i'm trying to do. Hope it's a little bit clearer. it partialy work in the main part of a program but not in the getParameterDefinitions. Sorry i haven't found the way to put the code in black. Sorry for my pour english, i'm a french guy. Do you think it's possible? I've tryed with require that you have mentioned but jscad answer me ReferenceError: require is not defined. Thanks for reading hopes that a solution exist. Best regards

            kaosat-dev 1 Reply Last reply Reply Quote 0
            • kaosat-dev
              kaosat-dev last edited by

              Hi @imkael !
              I regularly use something similar (if I get your question right): ie store all defaults for parameters for re-use (https://github.com/PiRo-bots/kiwikee/blob/master/cad/kiwikee/index.js#L14), however I am not sure it would work for the old 'include' syntax: but you can get it working trivially using the 'require' module syntax (available in the V2 prototype, CLI & the desktop app):

              in a file called 'parameterDefaults.js' (or whatever you want to call it)

              const paramDefaults = {
                quality: 120,
                robotName: 'SMARS',
              }
              
              module.exports = paramDefaults
              

              and then you can simply require that module as you need it:

              const paramDefaults = require('./parameterDefaults.js')
              //code that uses those values elsewhere
              

              hope this helps !

              I 1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB | Contributors