burningpony Posted September 18, 2010 Posted September 18, 2010 I have built a proof of concept for a script that scans a folder for files using scriptmaster ListAllFilesRecursivly, sort files based upon filename using (MoveOrRename), and create a record in a Documents table including a reference in a container. Here is the issue. The Script runs fine processing about 1500 files in about 3 or 5 minutes. But upon completion Filemaker is nearly locked up. It hangs even when trying to get to a drop menu like "Format". I have the script flush the cache periodically through the loop. I am kinda at a loss since the script runs at a decent speed yet makes me have to quit and relaunch the application upon completion. Any ideas?
burningpony Posted September 19, 2010 Author Posted September 19, 2010 So I did some various optimization and was able to get the script to complete in 58 seconds for 1511 documents.... But Filemaker still locks up upon completion... Judging by top filemaker's Memory use starts increasing exponentially.
Valentin Posted September 20, 2010 Posted September 20, 2010 Are you running the module as GUI function? In ScriptMaster 3 all modules were GUI functions, in ScriptMaster 4 we've added a way to specify that a module is a GUI one. Please make sure that you're using the latest ScriptMaster plugin and file.
burningpony Posted September 20, 2010 Author Posted September 20, 2010 None of the Modules are running as GUI. As far as I know. I have the register groovy command running in my open script. One Set Variable Command to One RegisterGroovy. I am running SM 4.02. RegisterGroovy( "ListAllFilesRecursively( path )" ; "def result = new StringBuffer();¶ def dir = new File(path);¶ count = 0;¶ listFiles( dir, result );¶ result.toString().trim();¶ ¶ void listFiles( File directory, StringBuffer buff ) {¶ for (eachFile in directory.listFiles() ) {¶ if (eachFile.getName().startsWith(".")) continue;¶ buff.append("n" + eachFile.getPath());¶ if( eachFile.isDirectory() ) {¶ buff.append( File.separator );¶ listFiles( eachFile, buff );¶ }¶ count++;¶ }¶ }" ) RegisterGroovy( "CheckWhetherFileExists( pathToFile )" ; "new File( pathToFile ).exists()" ) RegisterGroovy( "CreateFolder( pathToCreate )" ; "//Really simple version:¶ //return new File(path).mkdirs();¶ ¶ //Version with decent error reporting:¶ File dir = new File(pathToCreate);¶ if( dir.exists() ) return false;¶ if( dir.mkdirs() ) { //Success!¶ return true;¶ } else { //Figure out why it failed¶ File realParent = dir;¶ while( realParent != null && ! realParent.exists() ) {¶ realParent = realParent.getParentFile();¶ }¶ if( realParent != null && !realParent.canWrite() ) {¶ throw new FileNotFoundException("Directory " + dir.getAbsolutePath() + " could not be created because the parent directory " + realParent.getAbsolutePath() + " is not writeable" );¶ } else {¶ throw new FileNotFoundException("Directory + " + dir.getAbsolutePath() + " could not be created because of an unknown error." );¶ }¶ }" ) RegisterGroovy( "GetFileModificationDate( filePath )" ; "return new Date(new File(filePath).lastModified());" ) RegisterGroovy( "MoveOrRenameFile( originalPath ; moveToPath )" ; "File moveToFile = new File( moveToPath );¶ boolean success = new File( originalPath ).renameTo( moveToFile );¶ return success;" ) RegisterGroovy( "DeleteFileOrFolder( pathToDelete )" ; "if( pathToDelete == null ) throw new Exception("You must provide a pathToDelete");¶ File toDelete = new File(pathToDelete);¶ if( ! toDelete.exists() ) {¶ return false;¶ } else {¶ deleteRecursive( toDelete );¶ }¶ ¶ void deleteRecursive( File fileToDelete ) throws IOException {¶ if( fileToDelete.isDirectory() ) {¶ File[] children = fileToDelete.listFiles();¶ for( int n=0; n deleteRecursive( children[n] )¶ }¶ }¶ if( ! fileToDelete.delete() ) {¶ throw new IOException("Could not delete " + fileToDelete.getAbsolutePath());¶ }¶ }" ) RegisterGroovy( "GetFileExtension( html )" ; "import java.util.regex.*;¶ ¶ String regex = "(?<=.)(.*)";¶ ¶ Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);¶ Matcher matcher = pattern.matcher(html);¶ ¶ List result = new LinkedList();¶ while (matcher.find()) {¶ result.add( matcher.group(1) );¶ }¶ return result;" )
Smef Posted September 20, 2010 Posted September 20, 2010 It looks like all of the functions you have there are running as GUI functions. You will need to add "isGui=false" as a parameter on your function to have it run as a non-gui function. RegisterGroovy( functionSignature; yourGroovyCode; "isGui=false")
burningpony Posted September 20, 2010 Author Posted September 20, 2010 Alright, So I added the isGui = False, ran the script again. Same issue. I have attached a sample code to check to see if my syntax is wrong. RegisterGroovy( "CheckWhetherFileExists( pathToFile )" ; "new File( pathToFile ).exists()"; "isGui = false" )
andries Posted September 21, 2010 Posted September 21, 2010 I have exactly the same issue with this function. The situation is as follows: a list of paths, and a FM script looping over the path, and check each time if the file exists. Runs very well, but at the end it freezes FileMaker.
Smef Posted September 21, 2010 Posted September 21, 2010 Could you post an example FM file to show this happening which I could look at?
burningpony Posted September 21, 2010 Author Posted September 21, 2010 Attached. For filename the script is expecting name 3lettersofmonth2010 Inv.fileextension so burningpony aug2010 Inv.pdf It is expecting a hard coded filepath to look for files FYI. filetest.fp7.zip
andries Posted September 21, 2010 Posted September 21, 2010 Here is another example. There are 15000 records in the file, but also when I only have 2000 records in my foundset it causes this crash. I don't see anything special in the error log. What is the difference between a GUI function and another one? Or what is the difference in behavior? TestSM.zip
Smef Posted September 22, 2010 Posted September 22, 2010 I wasn't sure what to run in your first example, or which scripts I would need to adjust, so I took a look at the second example you uploaded. When I first ran it I noticed that you were missing "isGui=false" in your RegisterGroovy call. I experienced the same freezing as you with this parameter missing. Once I added "isGui=false", quit filemaker, re-opened the file and re-registered the function I did not experience the freezing any more. Can you try adding "isGui=false" to your RegisterGroovy function as well, quit filemaker and re-open your file (the quit is needed to clear the function registration) and see if it still happens for you?
burningpony Posted September 22, 2010 Author Posted September 22, 2010 I reworked my example to be a easier to demonstrate. This will simply scan your desktop for the first 2000 files. The Script to run is Scan Desktop. All functions have isGui=false filetest2.fp7_2.zip
andries Posted September 22, 2010 Posted September 22, 2010 I wasn't sure what to run in your first example, or which scripts I would need to adjust, so I took a look at the second example you uploaded. When I first ran it I noticed that you were missing "isGui=false" in your RegisterGroovy call. I experienced the same freezing as you with this parameter missing. Once I added "isGui=false", quit filemaker, re-opened the file and re-registered the function I did not experience the freezing any more. Can you try adding "isGui=false" to your RegisterGroovy function as well, quit filemaker and re-open your file (the quit is needed to clear the function registration) and see if it still happens for you? This solved the issue for me. But why does this matter? What is the reason we need to add this? As I understood scriptmaster has some issues with GUI functions? Thanks!
Smef Posted September 22, 2010 Posted September 22, 2010 Java handles the two types of functions differently, and running it as a non-gui function requires much fewer resources and allows it to run much faster, so FileMaker and Java don't have to worry about creating invisible windows, removing them, maintaining focus, and a host of other things that happen when you use a GUI function.
burningpony Posted September 25, 2010 Author Posted September 25, 2010 Even with isGui=false I am still getting a crash with filetest2. Any Advice?
Smef Posted September 27, 2010 Posted September 27, 2010 Double check and make sure that the flag is in your registration fucntions. Filetest2.fp7 does not have the isGui=false parameter in the RegisterGroovy function calls, so you will need to go back and type that in manually into each RegisterGroovy function call.
burningpony Posted September 27, 2010 Author Posted September 27, 2010 (edited) Every RegisterGroovy Function in the Open script of FileTest2.fp7 has the "isGui = False" flag as its last parameter sent is this incorrect? I already had to manually enter them prior to uploading that file to the forum. Below is the code for the first RegisterGroovy Command RegisterGroovy( "ListAllFilesRecursively( path )" ; "def result = new StringBuffer();¶ def dir = new File(path);¶ count = 0;¶ listFiles( dir, result );¶ result.toString().trim();¶ ¶ void listFiles( File directory, StringBuffer buff ) {¶ for (eachFile in directory.listFiles() ) {¶ if (eachFile.getName().startsWith(".")) continue;¶ buff.append("n" + eachFile.getPath());¶ if( eachFile.isDirectory() ) {¶ buff.append( File.separator );¶ listFiles( eachFile, buff );¶ }¶ count++;¶ }¶ }"; "isGui = false" ) Edited September 27, 2010 by Guest
burningpony Posted September 27, 2010 Author Posted September 27, 2010 (edited) Apparently "isGui = false" cannot have any spaces. "isGui=false" ran without ending in a crash. Edited September 27, 2010 by Guest
Recommended Posts
This topic is 5182 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now