dshaut Posted February 29, 2012 Share Posted February 29, 2012 I am creating tickets and I need each ticket to correspond to a seat in the auditorium. For example the ticket would say Right A-1. Right meaning the section, A the row, and 1 the seat number. Is there a way that fusion pro can automate this process without me having to type in all the seats into a data file? I was looking at this post about using ExternalDataFileEx, but wasn't able to get it to work. Any help would be appreciated. Quote Link to comment Share on other sites More sharing options...
step Posted February 29, 2012 Share Posted February 29, 2012 What are the names of the Sections, Rows, and Seats? Quote Link to comment Share on other sites More sharing options...
dshaut Posted February 29, 2012 Author Share Posted February 29, 2012 There are three sections 0 Right, Center, Left, 15 rows - letters A thru O, and the seats range from 11 to 15 depending on the row. Quote Link to comment Share on other sites More sharing options...
esmith Posted March 1, 2012 Share Posted March 1, 2012 (edited) I read through the scenario and although I'm sure that my interpretation is probably incorrect and Dan will almost certainly have a more concise solution (which I welcome), I had some spare time and thought I'd take a stab at this. I tried using the fromCharCode() JS method but FP doesn't seem to like it so instead I borrowed some custom code from the interwebz and placed it in JavaScript Globals: var thisSeat = 0; // Use this array since .fromCharCode doesn't seem to work in FP var asciiTable = // 0 thru 9 "??????????" + // 10 thru 19 "??????????" + // 20 thru 29 "??????????" + // 30 thru 39 "?? !\"#$%&'" + // 40 thru 49 "()*+,-./01" + // 50 thru 59 "23456789:;" + // 60 thru 69 "<=>?@ABCDE" + // 70 thru 79 "FGHIJKLMNO" + // 80 thru 89 "PQRSTUVWXY" + // 90 thru 99 "Z[\\]^_`abc" + // 100 thru 109 "defghijklm" + // 110 thru 119 "nopqrstuvw" + // 120 thru 127 "xyz{|}~?"; function itoa(i) { return asciiTable.substr(i, 1); } With the above "reference chart" to convert integers to ASCII characters, I added the following to my OnJobStart rule: var sectionArr = ["Right","Center","Left"]; var section = ''; var row = ''; var seat = ''; var result = ''; // section as defined by sectionArr for (var s=0; s<sectionArr.length; s++) { section = sectionArr[s]; // row (assuming 15 rows, A-O) for (var r=1; r<16; r++) { row = itoa(64+r); //seat var seatsPerRow = ''; switch (row) { case "A": case "B": case "C": case "D": case "E": case "K": case "L": case "M": case "N": case "O": seatsPerRow = 11; break; default: seatsPerRow = 15; } for (var t=0; t<seatsPerRow; t++) { seat = t + 1; result += section + ' ' + ToUpper(row) + '-' + seat + '\n'; } } } // remove last break tag result = Left(result,result.length-1); // split all seats into array allSeats = result.split("\n"); The code above generates an array of all the seats available in the theater. Next we need a way to associate a record with a specific seat so I add the following to an OnRecordStart rule: // assuming total seats = total number tickets = total records thisSeat = CurrentRecordNumber(); And finally, to return the value of each record's individual seat on the ticket template, I add a generic text rule: var currSeat = allSeats[int(thisSeat)-1]; return currSeat; This code worked for me on a test run, but I imagine you might have to edit the values of the OnJobStart rule to fit your scenario. Namely sectionArr (line 1), r (line 11), (case options in the switch loop if 'r' changes), and seatsPerRow (lines 26 and 30) may need adjusting. Good luck! Edited March 1, 2012 by esmith Quote Link to comment Share on other sites More sharing options...
dshaut Posted March 1, 2012 Author Share Posted March 1, 2012 I tired this and it seems to want to work, however when I preview and compose it I only get one record, Right A-1. Is there something I am missing that will compose all the records? I am also not sure where I can assign the number of seats per row. For example, in sections Right and Left rows A and B have 11 seats rows C and D have 12 seats, etc. until 15 seats in a row. The Center section has 14 seats in row A and 15 seats in row B and alternates between 14 and 15 seats throughout the rest of the rows. Thanks for all your help with this! Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted March 1, 2012 Share Posted March 1, 2012 I tried using the fromCharCode() JS method but FP doesn't seem to like it I'm not sure what you mean. You did a fine job of finding some code on the Internet, but you didn't do a simple Google search for "JavaScript fromCharCode", which would have returned plenty of examples of its proper usage. Anyway, the String.fromCharCode function is a standard part of JavaScript, and works just fine in FusionPro. However, it's a prototype, or static function, so you don't call it on an instance of a String or Number object or literal, but rather you call it on the String class itself, as String.fromCharCode(Number). FusionPro also adds a global VB-like function called Chr for convenience. So both of these return a capital "A": return String.fromCharCode(65);return Chr(65);Conversely, you can use either the standard JavaScript String.charCodeAt function or FusionPro's built-in Asc function to return the ASCII code of a character. These both return 65: return 'A'.charCodeAt();return Asc('A');So, this line in your rule: row = itoa(64+r);can simply be replaced with: row = Chr(r);And you don't need that huge table in the JavaScript Globals. For that matter, you don't need to manually count the rows in the first place. You can use the Asc function to drive the iteration as well, like so: for (var r = Asc('A'); r <= Asc('O'); r++) { row = Chr(r); // etc. There are a few other things you could do to simplify the code. I'll get into that in the next post. Quote Link to comment Share on other sites More sharing options...
esmith Posted March 1, 2012 Share Posted March 1, 2012 (edited) I'm not sure what you mean. You did a fine job of finding some code on the Internet, but you didn't do a simple Google search for "JavaScript fromCharCode", which would have returned plenty of examples of its proper usage. Anyway, the String.fromCharCode function is a standard part of JavaScript, and works just fine in FusionPro. However, it's a prototype, or static function, so you don't call it on an instance of a String or Number object or literal, but rather you call it on the String class itself, as String.fromCharCode(Number). FusionPro also adds a global VB-like function called Chr for convenience. So both of these return a capital "A": return String.fromCharCode(65);return Chr(65); Although I did search for that exact string and I did see sample code referencing its use, I did not pick up on the fact that "String" was a class rather than a generic variable. Thanks for the explanation. Edited March 1, 2012 by esmith Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted March 1, 2012 Share Posted March 1, 2012 I tired this and it seems to want to work, however when I preview and compose it I only get one record, Right A-1. Is there something I am missing that will compose all the records? Yes. You need to set FusionPro.Composition.repeatRecordCount = allSeats.length in OnRecordStart, then use FusionPro.Composition.repeatRecordNumber to access the the allSeats array for each repeated record. Or, you can set FusionPro.Composition.composeAllRecords = false and FusionPro.Composition.endRecordNumber = allSeats.length in OnJobStart, and then use either CurrentRecordNumber() or FusionPro.Composition.processedRecordNumber to access the allSeats array for each record. While I think the OnRecordStart method with repeated records is a bit more straightforward, I chose to stick with Eric's method using OnJobStart, and I just added the lines to set FusionPro.Composition.composeAllRecords and FusionPro.Composition.endRecordNumber, in the solution below. (Note that you can set your input data source to "None" as this is a ticketing job which doesn't require a data file.) I am also not sure where I can assign the number of seats per row. For example, in sections Right and Left rows A and B have 11 seats rows C and D have 12 seats, etc. until 15 seats in a row. The Center section has 14 seats in row A and 15 seats in row B and alternates between 14 and 15 seats throughout the rest of the rows. Okay, I came up with algorithms to meet those requirements, here in the OnJobStart rule, which I simplified a bit: var sectionArr = ["Left", "Center", "Right"]; for (var s = 0; s < sectionArr.length; s++) { var section = sectionArr[s]; // row (assuming 15 rows, A-O) for (var r = Asc('A'); r <= Asc('O'); r++) { var row = Chr(r); var rowNumber = r - Asc('A') + 1; var seatsPerRow = 0; if (section == "Center") { // The Center section has 14 seats in row A and 15 seats in row B and // alternates between 14 and 15 seats throughout the rest of the rows. seatsPerRow = 14 + ((rowNumber-1) % 2); } else // Right or Left { // In sections Right and Left rows A and B have 11 seats, // rows C and D have 12 seats, etc. until 15 seats in a row. seatsPerRow = Math.min(10 + Round(rowNumber / 2, 0), 15); } for (var seat = 1; seat <= seatsPerRow; seat++) allSeats.push(section + ' ' + row + '-' + seat); } } FusionPro.Composition.composeAllRecords = false; FusionPro.Composition.endRecordNumber = allSeats.length;You'll also need to add this single declaration to the JavaScript Globals: var allSeats = [];Finally, you'll want to create a standard Text rule (probably named "Seat") for use in a Text frame, like so: return allSeats[FusionPro.Composition.processedRecordNumber - 1]; Quote Link to comment Share on other sites More sharing options...
dshaut Posted March 1, 2012 Author Share Posted March 1, 2012 That works terrific. But of course two more things came up. In the last row of the right and left sections there are only 11 seats and the last row of the center section is empty. The other problem is that the order of the rows isn't straight forward. They go from A to H, then from J to N, then P to Q. I tried adding in the different order in this part of the code for (var r = Asc('A'); r <= Asc('O'); r++) but it was giving me an error. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted March 1, 2012 Share Posted March 1, 2012 That works terrific. But of course two more things came up. In the last row of the right and left sections there are only 11 seats and the last row of the center section is empty. Hmm, I think I'm getting all the right numbers of seats. If I put this line at the end of the big rule: return allSeats.join('\n');And then I click Validate, the last line starting with "Left" says "Left O-15" and the last line starting with "Center" says "Center O-14". Do you not get those same results? The other problem is that the order of the rows isn't straight forward. They go from A to H, then from J to N, then P to Q. I tried adding in the different order in this part of the code for (var r = Asc('A'); r <= Asc('O'); r++)but it was giving me an error. Okay, well, in your second post, you very specifically said "15 rows - letters A thru O." Although most systems like this do skip the letters I and O to avoid confusion with numbers. And fortunately I, as a developer, always enjoy changing requirements. Actually, the somewhat arbitrary set of row names makes the loop logic simpler, since we don't have to base it on a contiguous sequence of letters. This should meet the new requirements: //var allSeats = []; // <- define this in the JavaScript Globals var allRows = []; // for validation (see below) var sectionArr = ["Left", "Center", "Right"]; for (var s = 0; s < sectionArr.length; s++) { var section = sectionArr[s]; var rowLetters = "ABCDEFGHJKLMNPQ"; for (var rowNumber = 1; rowNumber <= rowLetters.length; rowNumber++) { var row = rowLetters[rowNumber-1]; var seatsPerRow = 0; if (section == "Center") { // The Center section has 14 seats in row A and 15 seats in row B and // alternates between 14 and 15 seats throughout the rest of the rows. seatsPerRow = 14 + ((rowNumber-1) % 2); } else // Right or Left { // In sections Right and Left rows A and B have 11 seats, // rows C and D have 12 seats, etc. until 15 seats in a row. seatsPerRow = Math.min(10 + Round(rowNumber / 2, 0), 15); } allRows.push(section + ' ' + row + '-' + seatsPerRow); for (var seat = 1; seat <= seatsPerRow; seat++) allSeats.push(section + ' ' + row + '-' + seat); } } FusionPro.Composition.composeAllRecords = false; FusionPro.Composition.endRecordNumber = allSeats.length; return allRows.join('\n'); // click Validate to see how many seats per row // Do this in a text rule to return a unique seat for each output record: // return allSeats[FusionPro.Composition.processedRecordNumber - 1]; Note that I've added a second array for debugging purposes, so that you can easily see how many seats we have per row when you click Validate. Quote Link to comment Share on other sites More sharing options...
dshaut Posted March 1, 2012 Author Share Posted March 1, 2012 Hmm, I think I'm getting all the right numbers of seats. If I put this line at the end of the big rule: Code: return allSeats.join('\n'); And then I click Validate, the last line starting with "Left" says "Left O-15" and the last line starting with "Center" says "Center O-14". Do you not get those same results? I am getting those exact results and it is exactly what I wanted. However, what I just found out though, is that the last row Q(which was row O in the original code you gave me) doesn't follow what I had previously said. In row Q for the Right and Left sections there are only 11 seats instead of 15 and in the center section there is no row Q. I believe this is to accommodate handicap seating. Quote Link to comment Share on other sites More sharing options...
dshaut Posted March 2, 2012 Author Share Posted March 2, 2012 Everything is working perfectly with now. I just had to add the things in red: var allRows = []; // for validation (see below) var sectionArr = ["Left", "Center", "Right"]; for (var s = 0; s < sectionArr.length; s++) { var section = sectionArr[s]; var rowLetters = "ABCDEFGHJKLMNPQ"; for (var rowNumber = 1; rowNumber <= rowLetters.length; rowNumber++) { var row = rowLetters[rowNumber-1]; var seatsPerRow = 0; if (section == "Center") { [color=Red]rowLetters = "ABCDEFGHJKLMNP"[/color] // The Center section has 14 seats in row A and 15 seats in row B and // alternates between 14 and 15 seats throughout the rest of the rows. seatsPerRow = 14 + ((rowNumber-1) % 2); } else // Right or Left { [color=Red]if (rowNumber < rowLetters.length){[/color] // In sections Right and Left rows A and B have 11 seats, // rows C and D have 12 seats, etc. until 15 seats in a row. seatsPerRow = Math.min(10 + Round(rowNumber / 2, 0), 15); } [color=Red]else seatsPerRow = 12;[/color] } allRows.push(section + ' ' + row + '-' + seatsPerRow); for (var seat = 1; seat <= seatsPerRow; seat++) allSeats.push(section + ' ' + row + '-' + seat); } } FusionPro.Composition.composeAllRecords = false; FusionPro.Composition.endRecordNumber = allSeats.length; return allRows.join('\n'); // click Validate to see how many seats per row // Do this in a text rule to return a unique seat for each output record: // return allSeats[FusionPro.Composition.processedRecordNumber - 1]; I'm not sure if my additions were the best way but everything is working exactly how I needed it to. Thanks everyone for the help. 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.