Admin1676454018 Posted August 22, 2008 Share Posted August 22, 2008 NOTE: The example in this thread only applies to FusionPro versions prior to 6.0. With the FusionPro VDP Suite v6.0 release, a new method exists to make repeating records MUCH easier. If you need to repeat records, Printable recommends upgrading to FusionPro 6.0 if necessary, and then using the new method over the method described in this thread. See the following sample job that demonstrates the new repeat record capability here: http://forums.printable.com/showthread.php?t=391 __________________ This example shows how a job with a "repeat count" value in the input data can be used to essentially repeat a given data record a given number of times. Download the attached ZIP file.Business Card Repeat.zip Link to comment Share on other sites More sharing options...
Admin1676454018 Posted August 22, 2008 Author Share Posted August 22, 2008 This was from a post made by Printable's own Dan Korn on June 19, 2008 to the user's forum: I wrote up a version that seems to work for me, with the Frodo Travel tutorial, using FusionPro 5.1P2b in Acrobat 8 on Mac OS X 10.5.3. The rule is below. This version uses ExternalDataFileEx, makes it easy to specify your repeat field name and delimiter, and gives more feedback, at both composition and validation time. It should work on Windows too, obviously with DOS paths. (It does require you to specify full paths; a more robust solution which allows you to simply specify a file name and parses the original input file name, on any platform, to get the path is definitely possible to write, but this doesn't do that.) DISCLAIMER: While I consider this a superior solution to the posted example above, this is still a workaround, and the technology upon which it relies (specifically the JavaScript File object), should be considered deprecated and unsupported, and may be removed in a future version of FusionPro. We will continue to investigate a way to allow "repeat record" functionality in a more straightforward way. // OnJobStart rule to repeat records var RepeatFieldName = "Repeat Count"; // EDIT THIS var FieldDelimiter = ","; // EDIT THIS ("\t" for tab-delimited) var orginputfilename = FusionPro.Composition.inputFileName; // For composition, the original name is set, // and the new name must be specified as an HFS path on Mac. // EDIT THIS var newfilename = "Macintosh HD:Applications:Printable:FusionPro:Tutorial:FrodoTravel:tempout.txt"; if (FusionPro.inValidation) { // For composition, both names must be specified as POSIX paths on Mac. // EDIT THIS orginputfilename = "/Applications/Printable/FusionPro/Tutorial/FrodoTravel/frodo-InstanceData-Repeat.txt"; // EDIT THIS newfilename = "/Applications/Printable/FusionPro/Tutorial/FrodoTravel/tempout.txt"; } // DO NOT EDIT BELOW THIS LINE var sf = new ExternalDataFileEx(orginputfilename, FieldDelimiter); if (!sf.valid) throw("Unable to open ExternalDataFile: " + orginputfilename); var of = new File(newfilename); //of.remove(); if (of.open("create") == false) throw("Could not create output file."); of.close(); if (of.open("write") == false) throw("Could not write output file."); for (var i=0;i<sf.fieldCount;i++) { if (i) of.write(FieldDelimiter); of.write(sf.GetFieldValue(0, i)); } of.write("\r\n"); var NewInputTotalRecords = 0; for (var i = 0 ; i <= sf.recordCount; i++) { var startval = 1; var repeatcount = Int(sf.GetFieldValue(i, RepeatFieldName)); for(var j = 0; j < repeatcount; j++) { NewInputTotalRecords++; for(var k = 0; k < sf.fieldCount; k++) { if (k) of.write(FieldDelimiter); switch(sf.GetFieldValue(0, k)) { case RepeatFieldName: of.write(startval+j); break; default: of.write(sf.GetFieldValue(i, k)); } } of.write("\r\n"); } } of.close(); FusionPro.Composition.inputFileName = newfilename; var message = orginputfilename + "\n" + sf.recordCount + " records\n\n"; message += FusionPro.Composition.inputFileName + "\n" + NewInputTotalRecords + " records"; Print(message); return message; Link to comment Share on other sites More sharing options...
Ryan Graybeal Posted December 19, 2008 Share Posted December 19, 2008 Is this rule just supposed to create a new data file? Or is it supposed to link to the new data file it created during the composition and compose the new total number of records? I am attempting to use this rule in a file but I can only get it to write the new data file. It won't compose the new total number of records. The rule validates just fine and I don't get any errors in the log. Any idea what is going on? thanks, Ryan Graybeal FPD 5.1p2 Mac OS X 10.4.11 Link to comment Share on other sites More sharing options...
MHardee Posted December 23, 2008 Share Posted December 23, 2008 Is this rule just supposed to create a new data file? Or is it supposed to link to the new data file it created during the composition and compose the new total number of records? Ryan Graybeal FPD 5.1p2 Mac OS X 10.4.11 That's what I do... I have it generate the datafile, then close FP and move the generated datafile to a safe folder. Then I reopen the PDF, KILL the onJobStart rule and link to the newly created file.. failure to do this and you get a datafile generated that is basically the number in the repeat field squared each time you open it.. This is why it would be GREAT to have a checkmark next to the rule in the rule dialog box that allows LEAVING the programming, but not reacting to it.. i.e. turn it off.. I have a feeling, this is one of those things on the list to "fix on the Mac version next week"... Anyway, you have found the workflow... Link to comment Share on other sites More sharing options...
Ryan Graybeal Posted December 23, 2008 Share Posted December 23, 2008 Thanks for telling me that I am on the right track. I appreciate it. Happy Holidays. Ryan Link to comment Share on other sites More sharing options...
Dan Korn Posted December 23, 2008 Share Posted December 23, 2008 EDIT: I'm assuming that you're using the updated logic in the second post in this thread. If not, please try that instead. And also please make sure you're not overwriting your original input file. Is this rule just supposed to create a new data file? No. Or is it supposed to link to the new data file it created during the composition and compose the new total number of records? Yes. At the fifth line from the bottom, the rule tells FusionPro to use the newly-created file as its input file for composition: FusionPro.Composition.inputFileName = newfilename; Any idea what is going on? Not really. I can't tell why it's not working for you without at least some information about your job. Posting the log file would be extremely helpful. Actually, based on the last few lines of the rule: var message = orginputfilename + "\n" + sf.recordCount + " records\n\n"; message += FusionPro.Composition.inputFileName + "\n" + NewInputTotalRecords + " records"; Print(message); return message; You should be seeing a message containing the names of both the original and new input files, and the number of records in each, in the composition log file, and in the message box when you click Validate in the Rule Editor. If you're not seeing this message, then something is definitely going wrong, in which case you should post your entire rule. That's what I do... I have it generate the datafile, then close FP and move the generated datafile to a safe folder. Then I reopen the PDF, KILL the onJobStart rule and link to the newly created file.. failure to do this and you get a datafile generated that is basically the number in the repeat field squared each time you open it.. You should not have to do this. I've tested this rule and I don't see the behavior you're describing. Actually, I suppose that you would see that behavior if the file name you're assigning to the "newfilename" variable is the same as your original input file name. If you're doing this, please change your logic to specify a different file name for that variable than your original input file. The whole point of this rule is that it creates a different input file and uses that to compose. It should never overwrite the original input file. This is why it would be GREAT to have a checkmark next to the rule in the rule dialog box that allows LEAVING the programming, but not reacting to it.. i.e. turn it off.. I'm not sure I see the utility in such a feature, but you can always just do something like this at the start of the OnJobStart rule if you don't want it to have any effect on your composition: if (!FusionPro.inValidation) return; I have a feeling, this is one of those things on the list to "fix on the Mac version next week"... Well, since you mention a future version, as I noted in my previous post, we are working on a much simpler way to repeat records without having to go through all this "rewrite your entire input file" rigamarole in the next major release of FusionPro, which is scheduled for a release early next year. The solution in the first message in this thread used to work fine on both Windows and Mac until Apple forced us to change from HFS to POSIX paths, which made this approach much more complicated. So I apologize for the trouble, and hopefully we can figure out how to fix your rule to make this work until the new version of FusionPro is available. Link to comment Share on other sites More sharing options...
Ryan Graybeal Posted December 24, 2008 Share Posted December 24, 2008 Dan, the validation looks good. I get a message as you stated in the previous post. original file name and path + the number of records new file name and path + the new number of records Right now I am getting an error message at the beginning of the compose: "Processing Begun OnJobStart, line 28 Error: File operation open failed" Line 28-30 is if (of.open("create") == false) throw("Could not create output file."); of.close(); Could this be a permissions issue? If the IF (of.open) isn't able to create the new file why don't i get the message "Could not create output file." ? Thanks for all of your help on this. Happy Holidays!!!!! Ryan Graybeal Here is the whole OnJobStart rule: // OnJobStart rule to repeat records var RepeatFieldName = "Quantity"; // EDIT THIS var FieldDelimiter = "\t"; // EDIT THIS ("\t" for tab-delimited) var orginputfilename = FusionPro.Composition.inputFileName; // For composition, the original name is set, // and the new name must be specified as an HFS path on Mac. // EDIT THIS var newfilename = "/Volumes/In House/In House/In House Folder/Jones Soda Files/JonesFusion Pro/data/tempout.txt"; if (FusionPro.inValidation) { // For composition, both names must be specified as POSIX paths on Mac. // EDIT THIS orginputfilename = "/Volumes/In House/In House/In House Folder/Jones Soda Files/JonesFusion Pro/data/CGjonesTest_p.txt"; // EDIT THIS newfilename = "/Volumes/In House/In House/In House Folder/Jones Soda Files/JonesFusion Pro/tempout2.txt"; } // DO NOT EDIT BELOW THIS LINE var sf = new ExternalDataFileEx(orginputfilename, FieldDelimiter); if (!sf.valid) throw("Unable to open ExternalDataFile: " + orginputfilename); var of = new File(newfilename); //of.remove(); if (of.open("create") == false) throw("Could not create output file."); of.close(); if (of.open("write") == false) throw("Could not write output file."); for (var i=0;i<sf.fieldCount;i++) { if (i) of.write(FieldDelimiter); of.write(sf.GetFieldValue(0, i)); } of.write("\r\n"); var NewInputTotalRecords = 0; for (var i = 0 ; i <= sf.recordCount; i++) { var startval = 1; var repeatcount = Int(sf.GetFieldValue(i, RepeatFieldName)); for(var j = 0; j < repeatcount; j++) { NewInputTotalRecords++; for(var k = 0; k < sf.fieldCount; k++) { if (k) of.write(FieldDelimiter); switch(sf.GetFieldValue(0, k)) { case RepeatFieldName: of.write(startval+j); break; default: of.write(sf.GetFieldValue(i, k)); } } of.write("\r\n"); } } of.close(); FusionPro.Composition.inputFileName = newfilename; var message = orginputfilename + "\n" + sf.recordCount + " records\n\n"; message += FusionPro.Composition.inputFileName + "\n" + NewInputTotalRecords + " records"; Print(message); return message; Link to comment Share on other sites More sharing options...
Dan Korn Posted December 24, 2008 Share Posted December 24, 2008 First you said: The rule validates just fine and I don't get any errors in the log. Then you said: Right now I am getting an error message at the beginning of the compose: "Processing Begun OnJobStart, line 28 Error: File operation open failed" Anyway, now that we know know what the error is, we can identify the problem, which is here: // For composition, the original name is set, // and the new name [b][color=red]must be specified as an HFS path[/color][/b] on Mac. // EDIT THIS var newfilename = "/Volumes/In House/In House/In House Folder/Jones Soda Files/JonesFusion Pro/data/tempout.txt"; You're specifying a POSIX path, not an HFS path. You probably want something like: var newfilename = "Macintosh HD:Volumes:In House:In House:In House Folder:Jones Soda Files:JonesFusion Pro:data:tempout.txt"; Line 28-30 is if (of.open("create") == false) throw("Could not create output file."); of.close(); Could this be a permissions issue? If the IF (of.open) isn't able to create the new file why don't i get the message "Could not create output file." ? Because of subtle differences in the internal implementation of the File object in JavaScript on different platforms, which is just one of the reasons why we're trying to implement a better way to repeat records that doesn't rely on this complicated rule. At any rate, the error message does tell you exactly where it's failing. Link to comment Share on other sites More sharing options...
MHardee Posted December 24, 2008 Share Posted December 24, 2008 Right now I am getting an error message at the beginning of the compose: "Processing Begun OnJobStart, line 28 Error: File operation open failed" Line 28-30 is if (of.open("create") == false) throw("Could not create output file."); of.close(); Could this be a permissions issue? If the IF (of.open) isn't able to create the new file why don't i get the message "Could not create output file." ? Ryan: I fought this forever.. The ONLY WAY I could ever get this to function was to copy and run the job from the server to the desktop of the mac.. Once this was done, copy the job back to the server.. I've tried many combinations to enter the valid path information into the rule for the server-based way.. Dan: I can verify, reproduce and send the results (and I am pretty sure I already did a few months ago) IF you do not generate the file and stop. It becomes cancerous and starts multiplying.. It is as if the counter never gets reset and if you produce the job once, get the correct number of records produced and then make an edit to the data and rerun the job, the resulting output if MANY TIMES larger than the first. But, is it a MOOT point now? I don't know.. I guess we'll have to pony up for the 6.0 suite to see, right? Link to comment Share on other sites More sharing options...
Dan Korn Posted December 24, 2008 Share Posted December 24, 2008 Ryan: I fought this forever.. The ONLY WAY I could ever get this to function was to copy and run the job from the server to the desktop of the mac.. Once this was done, copy the job back to the server.. I've tried many combinations to enter the valid path information into the rule for the server-based way.. I admit that this rule is overly complicated, especially with the whole HFS vs. POSIX path thing on the Mac, which, again, wasn't an issue when this rule was first created. But if you use the updated version, and you give it the right paths, in the right formats, it does work, both at rule validation and composition time. Dan: I can verify, reproduce and send the results (and I am pretty sure I already did a few months ago) IF you do not generate the file and stop. It becomes cancerous and starts multiplying.. It is as if the counter never gets reset and if you produce the job once, get the correct number of records produced and then make an edit to the data and rerun the job, the resulting output if MANY TIMES larger than the first. Again, not to be argumentative, but just because your customized version of the rule behaves that way, that doesn't mean it's a general problem. I still suspect that you're overwriting your original input file with the "newfilename" variable. If you would post your rule I could verify this and help you fix the problem. On the other hand, if you simply continue to insist that it doesn't work and never possibly could, then I can't help. But, is it a MOOT point now? I don't know.. I guess we'll have to pony up for the 6.0 suite to see, right? Well, once again, this is something that was never really an official feature of the product, but rather something that you could program in a rule, which has been shared on the forum as a workaround for users who need it. I guess it's no longer a secret that in 6.0, repeated records will become an official feature, and will be much easier to implement. Whether the new version, with that new feature and others, is worth whatever upgrade price you would have to "pony up" is something you will have to decide for yourself. Link to comment Share on other sites More sharing options...
Admin1676454018 Posted February 4, 2009 Author Share Posted February 4, 2009 Hi all, With the FusionPro VDP Suite v6.0 release, a new method exists to make repeating records MUCH easier. Printable recommends this new method over the method described in this thread. See the following sample job that demonstrates the new repeat record capability here: http://forums.printable.com/showthread.php?t=391 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.