mclisa81 Posted February 11, 2016 Posted February 11, 2016 Hi, I have 44 data files that I'm pulling in one at a time into my template and composing only the first and last record of each for proof pdfs. I am going in and modifying the rule each time, changing the last record since they are all different record counts. I'm sure there's a way to automate this to make it less painful. Any help is appreciated. var ranges = [ 1, 225 ]; function CheckRanges(val) { for (var i in ranges) if (val == ranges[i] || ((ranges[i] instanceof Array) && val >= ranges[i][0] && val <= ranges[i][1])) return true; return false; } FusionPro.Composition.composeThisRecord = CheckRanges(CurrentRecordNumber()); return FusionPro.Composition.composeThisRecord; Thanks in advance, Lisa Quote
esmith Posted February 11, 2016 Posted February 11, 2016 Is that in an OnJobStart rule? I think you can assign a variable for a global data file object which uses your input data file. Then you count the total records and use that as your secondary element in var ranges: myData = new ExternalDataFileEx(GetFileName(FusionPro.Composition.inputFileName), ",") //assuming CSV data totalRecords = myData.recordCount; var ranges = [ 1, totalRecords ]; // your function, etc. Admittedly, I have not tried this yet, but I think the logic is valid. Quote
step Posted February 11, 2016 Posted February 11, 2016 Actually, as long as pre-processing is occurring, FusionPro already knows how many records there are. That information is accessible through "FusionPro.Composition.totalRecordCount". If your job is imposing, then pre-processing is already occurring. Otherwise, you'll need to specifically tell the job to pre-process by putting this in an OnJobStart rule: FusionPro.Composition.forcePreprocessing = true; Then it's just a matter of making the following edit to your OnRecordStart code: var ranges = [ 1, [color="Red"]FusionPro.Composition.totalRecordCount[/color] ]; function CheckRanges(val) { for (var i in ranges) if (val == ranges[i] || ((ranges[i] instanceof Array) && val >= ranges[i][0] && val <= ranges[i][1])) return true; return false; } FusionPro.Composition.composeThisRecord = CheckRanges(CurrentRecordNumber()); Or more succinctly: FusionPro.Composition.composeThisRecord = [1,FusionPro.Composition.totalRecordCount].indexOf(CurrentRecordNumber()) > -1 Quote
mclisa81 Posted February 11, 2016 Author Posted February 11, 2016 Eric, Worked perfectly. Thank you so much! Lisa Quote
mclisa81 Posted February 16, 2016 Author Posted February 16, 2016 Hi Ste, I've already finished this job, however, I'm now trying your suggestions since they're a few less steps. Both of them are composing the first record (1) only. Any ideas? On Job Start FusionPro.Composition.forcePreprocessing = true; On Record Start var ranges = [ 1, FusionPro.Composition.totalRecordCount ]; function CheckRanges(val) { for (var i in ranges) if (val == ranges[i] || ((ranges[i] instanceof Array) && val >= ranges[i][0] && val <= ranges[i][1])) return true; return false; } FusionPro.Composition.composeThisRecord = CheckRanges(CurrentRecordNumber()); Thanks Lisa Quote
Dan Korn Posted February 16, 2016 Posted February 16, 2016 I've already finished this job, however, I'm now trying your suggestions since they're a few less steps. Both of them are composing the first record (1) only. Any ideas? I would add some calls to the Print function and look at the log file to trace what's going on. Try adding this to the end of your OnRecordStart rule: Print("FusionPro.Composition.totalRecordCount=" + FusionPro.Composition.totalRecordCount); Print("CurrentRecordNumber()=" + CurrentRecordNumber()); Print("FusionPro.Composition.composeThisRecord=" + FusionPro.Composition.composeThisRecord); Quote
mclisa81 Posted February 16, 2016 Author Posted February 16, 2016 Hi Dan, Thanks for getting back to me. I added the calls you suggested and I can see that the "totalRecordCount" is showing 0 in the msg file. I'm attaching the msg file for you to take a look at if you wouldn't mind. Thanks Lisa94305_.zip Quote
step Posted February 16, 2016 Posted February 16, 2016 Sorry, Lisa, I should have given that a try before I posted it as a solution. I think what's happening is that OnRecordStart is being called during pre-processing to determine the total number of records that will be generated. Since the range is set to "1" and "totalRecords" (which is unknown at the time of pre-processing), pre-processing will determine that only one record will be created thus making the total records 1. You'd have to add the following to tell pre-processing that all records should be composed when you're pre-processing the job so that the totalRecordCount is accurate: var ranges = [ 1, FusionPro.Composition.totalRecordCount ]; function CheckRanges(val) { for (var i in ranges) if (val == ranges[i] || ((ranges[i] instanceof Array) && val >= ranges[i][0] && val <= ranges[i][1])) return true; return false; } FusionPro.Composition.composeThisRecord = [color="Red"]FusionPro.Composition.inPreprocessing || [/color]CheckRanges(CurrentRecordNumber()); Alternatively, you could determine the total number of records yourself by incrementing a variable each time a record is pre-processed: [color="red"]this.total = this.total || 0; if (FusionPro.Composition.inPreprocessing) ++this.total;[/color] var ranges = [ 1, [color="Red"]this.total[/color] ]; function CheckRanges(val) { for (var i in ranges) if (val == ranges[i] || ((ranges[i] instanceof Array) && val >= ranges[i][0] && val <= ranges[i][1])) return true; return false; } FusionPro.Composition.composeThisRecord = CheckRanges(CurrentRecordNumber()); Quote
Dan Korn Posted February 16, 2016 Posted February 16, 2016 Okay, I see what's happening. The thing is, when you do preprocessing, the preprocessing pass figures out which records to compose ahead of time, generally for figuring out imposition stacking. So records that are skipped (composeThisRecord = false) at preprocessing are not included in the totalRecordCount. Therefore, you need to tell FusionPro to skip records only during the main composition pass, not during preprocessing. The easiest way to do that for this case is like so: FusionPro.Composition.composeThisRecord = FusionPro.Composition.inPreprocessing || [1,FusionPro.Composition.totalRecordCount].indexOf(CurrentRecordNumber()) > -1; Quote
mclisa81 Posted February 17, 2016 Author Posted February 17, 2016 Dan, That worked perfectly. Thanks again for all your help. Lisa Quote
iprint2 Posted February 18, 2016 Posted February 18, 2016 Hi Lisa Would you mind posting what your final code looks like? We have a job that this would work perfectly for proofing their multiple data records. Thank you! Jason Quote
mclisa81 Posted February 18, 2016 Author Posted February 18, 2016 Hi Jason, Here is my final code ... On Job Start FusionPro.Composition.forcePreprocessing = true; On Record Start FusionPro.Composition.composeThisRecord = FusionPro.Composition.inPreprocessing || [1,FusionPro.Composition.totalRecordCount].indexOf(CurrentRecordNumber()) > -1; Lisa Quote
iprint2 Posted February 19, 2016 Posted February 19, 2016 Lisa - thank you very much for this and for taking the time - enjoy your weekend J Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.