Landisa Posted January 28, 2016 Share Posted January 28, 2016 (edited) ================ UPDATE: 1/29/2016 Listing as solved and leaving code for future people if they need help. ================ I am working on creating several rules based on the page number of a document. First rule is a barcode for our inserter. We need to include: customer idcurrent page (2-digit)total pages in record (2-digit)check digit So it should look something like: CN61341010300 I am having difficulty calling the page numbers in the empty rules though. Second rule is making it so that the barcode only displays on odd number pages and the first page is a different setup than all the other pages. Page 1 has a special check digit that signifies start of a document. Page 2-N have a different check digit to signify that it continues to pull. How would I call up page numbers in these situations? Will they work in empty rules or do I need a callback? Edited January 29, 2016 by Landisa Solved Quote Link to comment Share on other sites More sharing options...
step Posted January 29, 2016 Share Posted January 29, 2016 First rule is a barcode for our inserter. We need to include: customer idcurrent page (2-digit)total pages in record (2-digit)check digit Okay, it sounds like you're going to want to make a text rule to return those values and then apply it to the frames in which you'd like for the barcode to display. Is that right? So the "total pages" are the "total pages of a particular record," is the "current page" the "current page of a particular record" or the "current page of the output file?" There are methods to handle both but for the sake of example, I'm going to assume you're just talking about the current page in the record. I am having difficulty calling the page numbers in the empty rules though. I don't understand what you mean by that. Can you elaborate on what you mean by "calling page numbers in the empty rules?" Are you referring to rules that return a null value or empty string? If so, why are you worried about calling the page number? Second rule is making it so that the barcode only displays on odd number pages Easy enough. You can just return an empty string in your text rule when the current page mod 2 is 0. Or just don't put a text frame with that rule in it on even pages. and the first page is a different setup than all the other pages. Page 1 has a special check digit that signifies start of a document. Page 2-N have a different check digit to signify that it continues to pull. Page 1 has a special check digit that signifies the start of a document like... a 1? I'm not sure what your intent with this "check digit" is. It seems like that information is already included in the barcode but I'll just assume that you want the last two digits to be "01" if it's the first page in the document and "00" if it's any other page in the document. I also just assumed you wanted to make a 3 of 9 barcode but you should be able to easily swap that out with whatever format you prefer: var id = 'CN61341'; // Your Client ID field would go here var pg = FusionPro.Composition.currentPageNumber; var pgs = FusionPro.Composition.totalPages; var check = pg == 1 ? 1 : 0; // Format pg, pgs, & check to 2 digits and join the string. var digits = [pg,pgs,check].map(function(s){ return Str(FormatNumber('00',s));}).join(''); // If the current page is odd, return the barcode return pg%2 ? Make39Barcode(id + digits) : ''; That would go in a text rule that is set to "re-evaluate for every text flow" and "treat strings at tagged text" and then you just insert it into your text frames. Quote Link to comment Share on other sites More sharing options...
Landisa Posted January 29, 2016 Author Share Posted January 29, 2016 (edited) Step your code helped me figure out my mistake! Looks like I just needed to set my code to re-evaluate for every text flow so that it would actually call the page number rather than always using page 1 as the result. Could this theory be applied to a set of OMR marks (essentially a table with borders that change from 3-fin marks on page 1 and 2-fin marks on pages 2-N)? I am using this code to apply the marks: //Create 3-Fin OMR Mark using tables and borders new FPTable; var OMR = new FPTable; OMR.AddColumns(7200); OMR.AddRows(3); OMR.Rows[0].minHeight = 1800; //specified in hundredths of a point OMR.Rows[0].Cells[0].SetBorders("Medium", "Black", "Top"); OMR.Rows[0].Cells[0].Content = ""; OMR.Rows[1].minHeight = 1800; //specified in hundredths of a point OMR.Rows[1].Cells[0].SetBorders("Medium", "Black", "Top"); OMR.Rows[1].Cells[0].Content = ""; OMR.Rows[2].minHeight = 1800; //specified in hundredths of a point OMR.Rows[2].Cells[0].SetBorders("Medium", "Black", "Top"); OMR.Rows[2].Cells[0].Content = ""; return OMR.MakeTags(); Edited January 29, 2016 by Landisa Quote Link to comment Share on other sites More sharing options...
Landisa Posted January 29, 2016 Author Share Posted January 29, 2016 Nevermind! I just needed to think it through a little bit. Made each table unique and set an easy if else statement. I got these to work with the following code: // If the current page is odd, return the barcode if (pg == 1){ return pg %2 ? OMR3.MakeTags() : ''; } else { return pg %2 ? OMR2.MakeTags() : ''; } Quote Link to comment Share on other sites More sharing options...
step Posted January 29, 2016 Share Posted January 29, 2016 Could this theory be applied to a set of OMR marks (essentially a table with borders that change from 3-fin marks on page 1 and 2-fin marks on pages 2-N)? Sure, you could determine the number of marks (rows) to add based on what page the record is on: var pg = FusionPro.Composition.currentPageNumber; var rows = !--pg+2; var OMR = new FPTable(); OMR.AddColumns(7200); for (var i=0; i<rows; i++) { var row = OMR.AddRow(); row.minHeight = 1800; //specified in hundredths of a point row.Cells[0].SetBorders('Medium', 'Black', 'Top'); } return pg%2 ? OMR.MakeTags() : ''; Quote Link to comment Share on other sites More sharing options...
Landisa Posted January 29, 2016 Author Share Posted January 29, 2016 Sure, you could determine the number of marks (rows) to add based on what page the record is on: Nice! I really need to start wrapping my brain around the slimmer code style. My code always feels so barbaric compared to yours XD Quote Link to comment Share on other sites More sharing options...
step Posted January 29, 2016 Share Posted January 29, 2016 By the way, just as a little explanation about the 'rows' variable since I know it looks kind of weird: --pg subtracts 1 from the page number. !--pg Converts the number to a boolean (true/false). In this case we're testing that the page number minus one is zero; if it is, the boolean returns true and if it's greater than 0 it returns false. !--pg+2 The binary value of the boolean (1: true, 0: false) is converted to an integer by performing arithmetic on it. In this case we're adding 2 so that the number of rows will be 2 when the page is greater than one (0 + 2 = 2) and 3 when then page number is 1 (1 + 2 = 3). It by no means has to be written that way. I was just saving a few keystrokes but it could certainly be written in a more easy-to-read format: var rows = pg==1 ? 3 : 2; Quote Link to comment Share on other sites More sharing options...
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.