To date I've been using "#include 'somepath' to include all my files, but today I started to get out of memory issues and it appears to be related to the fact that includes are being included multiple times. At least if I remove one particular #include statement which in turn includes a bunch of files previously included, all my problems go away... So my question: is it possible to get photoshop to include a file only if it hasn't been included previously?
As a side note, I noticed xbytor's code all uses the syntax '//@include' - is there any difference between the two directives?
Thanks all!
Anna
Include directives
Include directives
Where do you have the include statements? They are normally at or near the start of the script and are only process once. When the script ends the memory is cleared, includes as well.
I also use //@include. I guess that is because of how much I have learned from Xbytor. I noticed that Adobe is now using $.evalFile for their Photoshop script like Photomerge and Merge to HDR. The Adobe Output Module uses #include. I don't know that there is any real difference other than you can localize the path to the file easier with $.evalFile.
The AOM has about 15 include files, Photomerge has 5. At a guess I would say that there is something wrong with either the way you are including the file(s) or the files themselves. I have not had memory problems with includes.
I also use //@include. I guess that is because of how much I have learned from Xbytor. I noticed that Adobe is now using $.evalFile for their Photoshop script like Photomerge and Merge to HDR. The Adobe Output Module uses #include. I don't know that there is any real difference other than you can localize the path to the file easier with $.evalFile.
The AOM has about 15 include files, Photomerge has 5. At a guess I would say that there is something wrong with either the way you are including the file(s) or the files themselves. I have not had memory problems with includes.
Include directives
The project in question is made up of ~20 files. Each file has its own includes (at the top) and some files likes xbytor's stdlib file are included by most of the other files. I've rationalised the includes by just putting them at the top of each of the main scripts that fire in response to the various events I'm monitoring and that fixes the issue, but it makes it hard to tell what is required by each of the other files...
Include directives
So if I understand what you are doing you have includes files that also include other files, some of which include the same file like stblib.
Depending on the files you may be able to have have conditional includes. For example you can test to see if Stdlib is defined and if it is not run the include. With that as part of the include files stblib will only be included once.
Code: Select alltry{
Stdlib;
}catch(e){
// @include '/C/Program Files/Adobe/xtools/xlib/stdlib.js'
}
Depending on the files you may be able to have have conditional includes. For example you can test to see if Stdlib is defined and if it is not run the include. With that as part of the include files stblib will only be included once.
Code: Select alltry{
Stdlib;
}catch(e){
// @include '/C/Program Files/Adobe/xtools/xlib/stdlib.js'
}
Include directives
Actually, if you want to do conditional inclusion, it would look something like this:
Code: Select alltry {
Stdlib;
}catch(e){
$.evalFile('/C/Program Files/Adobe/xtools/xlib/stdlib.js');
}
The problem with the //@include in the catch block in Mike's code is that the //@include happens textually: it's a preprocessor directive so the code is going to get stuffed in there anyway, it just may not get evaluated.
I deal with the problem myself generally by having only the top-level script do all of the //@includes. For lib-level scripts that require other scripts, I have sections like this at the top of the script to document what other lib-scripts it depends on:
Code: Select all//
//-include "xlib/PSConstants.js"
//-include "xlib/stdlib.js"
//-include "xlib/Stream.js"
//-include "xlib/Action.js"
//-include "xlib/xml/atn2bin.jsx"
//-include "xlib/xml/atn2js.jsx"
//-include "xlib/ActionStream.js"
//-include "xlib/ieee754.js"
//
Also, I never ship application scripts that have //@includes in them. Everything gets flattened out before I send them out.
-X
Code: Select alltry {
Stdlib;
}catch(e){
$.evalFile('/C/Program Files/Adobe/xtools/xlib/stdlib.js');
}
The problem with the //@include in the catch block in Mike's code is that the //@include happens textually: it's a preprocessor directive so the code is going to get stuffed in there anyway, it just may not get evaluated.
I deal with the problem myself generally by having only the top-level script do all of the //@includes. For lib-level scripts that require other scripts, I have sections like this at the top of the script to document what other lib-scripts it depends on:
Code: Select all//
//-include "xlib/PSConstants.js"
//-include "xlib/stdlib.js"
//-include "xlib/Stream.js"
//-include "xlib/Action.js"
//-include "xlib/xml/atn2bin.jsx"
//-include "xlib/xml/atn2js.jsx"
//-include "xlib/ActionStream.js"
//-include "xlib/ieee754.js"
//
Also, I never ship application scripts that have //@includes in them. Everything gets flattened out before I send them out.
-X
Include directives
I've already found your flattener script and was going to give it a go this time - Previous projects have been much smaller so it never was much of an issue. Thanks guys.