Is there any way to include scripting files? For example, if I had a function that I wanted to use in two different scripts, is there anyway to import those somehow? Something like a use or include/require statement?
Thanks in advance
Including files
Including files
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Including files
The only way is to read file into string and call eval().
Including files
Dwight,
Did some more thinking and I really need this functionality. For example, let's say in the AWS scripting project, I want a function that tests to see if AWS CLI is installed and accessible from Switch, which returns an error on failure. I wouldn't want to copy that functionality in each scripting configurator because if I make any updates to the function, I'd have to go back and do it in a bunch of places. Not to mention some of these scripts are kind of nuts to have all in one file.
I could have a separate repo of core scripts which each could eval() from. For example, if you clones the core repo to C:/core/ and then each script would open the file 'C:/core/core.js' and eval() the contents of that file, that would work, but I want everything to be contained in the script configurator itself.
So, since .sscript files are essentially just .zips, could you hack multiple JavaScript files into that zip, possibly update the manifest if needed, then within the script, read the files within the .sscript itself? Somehow we'd need to figure out if its possible to find the path of the script itself and then modify it to find the other included scripts. Does this sound at all possible?
Did some more thinking and I really need this functionality. For example, let's say in the AWS scripting project, I want a function that tests to see if AWS CLI is installed and accessible from Switch, which returns an error on failure. I wouldn't want to copy that functionality in each scripting configurator because if I make any updates to the function, I'd have to go back and do it in a bunch of places. Not to mention some of these scripts are kind of nuts to have all in one file.
I could have a separate repo of core scripts which each could eval() from. For example, if you clones the core repo to C:/core/ and then each script would open the file 'C:/core/core.js' and eval() the contents of that file, that would work, but I want everything to be contained in the script configurator itself.
So, since .sscript files are essentially just .zips, could you hack multiple JavaScript files into that zip, possibly update the manifest if needed, then within the script, read the files within the .sscript itself? Somehow we'd need to figure out if its possible to find the path of the script itself and then modify it to find the other included scripts. Does this sound at all possible?
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Including files
I did an experiment quite some time ago with reading a file and eval()-ing it: no luck, I could not get it to work. A simple javascript expression works, but when you start putting functions in it (which you will undoubtedly do) it does not work.
Squeezing multiple pieces of code into the sscript file is also not going to work. Yes, it can contain multiple pieces of code, even in different languages, but only one is executed.
An include function is certainly a very useful extension of the scripting functionality, but it will have to be done by engineering. The feature request exists. If everybody who is interested posts his/her mail address I will add them to the feature request.
Freddy
Squeezing multiple pieces of code into the sscript file is also not going to work. Yes, it can contain multiple pieces of code, even in different languages, but only one is executed.
An include function is certainly a very useful extension of the scripting functionality, but it will have to be done by engineering. The feature request exists. If everybody who is interested posts his/her mail address I will add them to the feature request.
Freddy
Including files
freddyp wrote: An include function is certainly a very useful extension of the scripting functionality, but it will have to be done by engineering. The feature request exists. If everybody who is interested posts his/her mail address I will add them to the feature request.
Good to know. I'd love it if you could add me to that request. My email is gabrielp@shawmutprinting.com
Thanks
Good to know. I'd love it if you could add me to that request. My email is gabrielp@shawmutprinting.com
Thanks
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
-
- Advanced member
- Posts: 230
- Joined: Thu Aug 07, 2014 10:04 am
Including files
Please add me to the request too: ariel.rauch@gmail.com
Re: Including files
I'm also interested in this: john@midtownprinting.com
Re: Including files
freddyp wrote:I did an experiment quite some time ago with reading a file and eval()-ing it: no luck, I could not get it to work. A simple javascript expression works, but when you start putting functions in it (which you will undoubtedly do) it does not work.
You have to define the function as a variable!
For example:
Code: Select all
myPlus = function(a,b) {
job.log(2,"Function: myPlus");
return a+b;
}
To use it in your script, you have to open and execute the file with eval. After that, you can use your function in the normal way:
Code: Select all
// PSEUDO-HEADERFILES
// Developed by Marc Listmayr <marc@loopart.at>
// Copyright 2015 -- All rights reserved
// open and read the included 'header'-file
eval(File.read(s.getPropertyValue(["headerpath"]), "UTF-8"));
// use function 'myPlus' and write it into the log
job.log(2,myPlus(6,4));
Re: Including files
MoodyBro, thanks for that info. I'll have to try that out.
Freddy, I've requested this before, and I'm still interested in this feature. Please add me: jskibbie@schawk.com.
Thanks.
Freddy, I've requested this before, and I'm still interested in this feature. Please add me: jskibbie@schawk.com.
Thanks.