gdellaiera Posted July 31, 2017 Share Posted July 31, 2017 So I was able to come up with a good rule for On Record Start for a Name/Title field, but then had to add in a condition for the address as well. It worked perfectly fine until I added the address portion & now it will only use the 'long page', even when the 'short page' is supposed to be used. Is there something missing below? I've been racking my brain to figure out what is going on, but every time I validate, FusionPro returns 'Expressions Ok'. Thanks for the look. var name = Field("Name"); var title = Field("Title"); var nametitle = name + "," + title; if (nametitle.length <= 26){ FusionPro.Composition.SetBodyPageUsage("Short Name", true); FusionPro.Composition.SetBodyPageUsage("Long Name", false); } else{ FusionPro.Composition.SetBodyPageUsage("Short Name", false); FusionPro.Composition.SetBodyPageUsage("Long Name", true); }; var address = Rule("Format Address"); if (address.length <= 40){ FusionPro.Composition.SetBodyPageUsage("Short Name", true); FusionPro.Composition.SetBodyPageUsage("Long Name", false); } else{ FusionPro.Composition.SetBodyPageUsage("Short Name", false); FusionPro.Composition.SetBodyPageUsage("Long Name", true); } Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted July 31, 2017 Share Posted July 31, 2017 It seems to me that this part of the rule has absolutely no effect: var name = Field("Name"); var title = Field("Title"); var nametitle = name + "," + title; if (nametitle.length <= 26){ FusionPro.Composition.SetBodyPageUsage("Short Name", true); FusionPro.Composition.SetBodyPageUsage("Long Name", false); } else{ FusionPro.Composition.SetBodyPageUsage("Short Name", false); FusionPro.Composition.SetBodyPageUsage("Long Name", true); }; Because, regardless of what page usage was set above based on the name and title, you're completely resetting the page usage based on the address: var address = Rule("Format Address"); if (address.length <= 40){ FusionPro.Composition.SetBodyPageUsage("Short Name", true); FusionPro.Composition.SetBodyPageUsage("Long Name", false); } else{ FusionPro.Composition.SetBodyPageUsage("Short Name", false); FusionPro.Composition.SetBodyPageUsage("Long Name", true); } It's not clear exactly what should happen if, say, the name and title are longer than 27 characters but the address is less than 40 characters. Although, in 99 out of 100 cases like this, you can usually implement some other way of accomplishing the results you need without creating entirely new sets of pages for variable text of different lengths. The most common way to resolve something like this is via copyfitting, either full-flow copyfitting (by checking the "Adjust text to fit" box on the Overflow Options dialog), or per-line copyfitting (by using the CopyfitLine or similar text measurement in a rule. Other strategies including having multiple (sets of) frames and selectively suppressing them, resizing frames, and using tables. If I could see the job files, or at least the desired output, I might be able to offer a more specific suggestion. Also, the reason you get "Expressions OK" is because, well, the expressions are okay. If you want to return something from the rule just to see what's happening, you can certainly do that, but, as the message will then say, the return value will have no effect on the composition. Quote Link to comment Share on other sites More sharing options...
gdellaiera Posted July 31, 2017 Author Share Posted July 31, 2017 Dan, Unfortunately I am not able to load the file or the zip right now. I will keep trying. As for the desired affect; If the name + title > 26 characters and/or the Address is > 40 characters, the initial page with graphic frames is to be forgone & the second page with no graphic frames is to be used (as it has larger text frames). This is due to the fact that fonts cannot be smaller than they already are (which is why I cannot use any sort of copy fitting or resizing rules). I don't know if this clears anything up for you Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted July 31, 2017 Share Posted July 31, 2017 (edited) Okay, I think the key word in your description of the requirement is "OR". As for the desired affect; If the name + title > 26 characters and/or the Address is > 40 characters, the initial page with graphic frames is to be forgone & the second page with no graphic frames is to be used (as it has larger text frames). So that should be an "OR" (denoted by "||") in your rule: var address = Rule("Format Address"); var name = Field("Name"); var title = Field("Title"); var nametitle = name + "," + title; if (nametitle.length > 26 || address.length > 40) { FusionPro.Composition.SetBodyPageUsage("Short Name", false); FusionPro.Composition.SetBodyPageUsage("Long Name", true); return "using long names"; } else { FusionPro.Composition.SetBodyPageUsage("Short Name", true); FusionPro.Composition.SetBodyPageUsage("Long Name", false); return "using short names"; } Or, equivalently: var address = Rule("Format Address"); var nametitle = Field("Name") + "," + Field("Title"); var needLongText = (nametitle.length > 26 || address.length > 40); FusionPro.Composition.SetBodyPageUsage("Short Name", !needLongText); FusionPro.Composition.SetBodyPageUsage("Long Name", needLongText); return "using " + (needLongText ? "long" : "short") + " names"; It is also still true that, instead of suppressing pages selectively, you could accomplish this by having multiple sets of named frames on the same page, and suppressing frames selectively, or by resizing frames if you're composing via FP Server or Producer. Edited July 31, 2017 by Dan Korn fixed typo Quote Link to comment Share on other sites More sharing options...
gdellaiera Posted July 31, 2017 Author Share Posted July 31, 2017 OK the or was definitely confusing me. I am however getting a syntax error with both rules. Line 6, (the first vertical bar is highlighted |) Syntax error: syntax error is what is read. This rule makes sense to use, but even after retyping it, I am still getting an error Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted July 31, 2017 Share Posted July 31, 2017 OK the or was definitely confusing me. I am however getting a syntax error with both rules. Line 6, (the first vertical bar is highlighted |) Syntax error: syntax error is what is read. This rule makes sense to use, but even after retyping it, I am still getting an error Sorry, I had an extra parend in there. That line should be: if (nametitle.length > 26 || address.length > 40) or in the second example: var needLongText = (nametitle.length > 26 || address.length > 40); Quote Link to comment Share on other sites More sharing options...
gdellaiera Posted July 31, 2017 Author Share Posted July 31, 2017 Thanks Dan, I think that is working. I cannot preview or see anything in the composition file, but I believe that means that all is good! Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted August 1, 2017 Share Posted August 1, 2017 Thanks Dan, I think that is working. I cannot preview or see anything in the composition file, but I believe that means that all is good! Great! Yes, if you suppress an entire page, then you won't see any content in its frames when you Preview, and that page will of course not be present at all in composed output. (Though if you use a different strategy, such as suppressing frames instead of entire pages, you will see a better representation of the composed output in Preview.) I will leave you with one other thing to consider: Counting the number of characters is a very poor way to determine whether text is going to fit into a particular frame. Unless you're using a monospaced font, some letters are wider than others. A name with a lot of W's and M's is going to take up a lot more space than a name with a lot of I's and L's, even with the same number of characters. For instance, in the default font on this forum: Mayweather ->10 letters, but wider Illivanovic -> 11 letters, but narrower So what you really should do is measure the text, using the FusionProTextMeasure object, to see how much space it really takes up, and compare that to the actual width of the frame. For instance, you can name your frame(s) and do this: var nametitle = Field("Name") + "," + Field("Title"); var address = Rule("Format Address"); var TM = new FusionProTextMeasure; TM.font = "Arial"; // <- font you're using TM.pointSize = 10; // <- text point size TM.CalculateTextExtent(nametitle); var nameFrame = FindTextFrame("Name"); // <- your frame name var nameTitleTooBig = TM.textWidth > nameFrame.GetSettableTextWidth(); TM.font = "Arial"; // <- font you're using TM.pointSize = 10; // <- text point size TM.CalculateTextExtent(address); var addressFrame = FindTextFrame("address"); // <- your frame name var addressTooBig = TM.textWidth > addressFrame.GetSettableTextWidth(); var needLongText = nameTitleTooBig || addressTooBig; FusionPro.Composition.SetBodyPageUsage("Short Name", !needLongText); FusionPro.Composition.SetBodyPageUsage("Long Name", needLongText); return "using " + (needLongText ? "long" : "short") + " names"; Quote Link to comment Share on other sites More sharing options...
gdellaiera Posted August 1, 2017 Author Share Posted August 1, 2017 Dan, thanks for all the help. I was wondering though, how one would go about suppressing frames vs. suppressing pages. Obviously you would have multiple frames overlapping each other, but is there something in FusionPro (like an OnRecordStart rule) that does this? Or is it pure scripting? Quote Link to comment Share on other sites More sharing options...
GreggRusson Posted August 1, 2017 Share Posted August 1, 2017 Look in the user manual for 'Modifying Frames During Composition'. This section will give you an overview of how to programmatically write (or add to ) a OnRecordStart rule to find and modify either a graphic or text frames properties. To find all the properties of a frame (of which suppress is one), consult the Rules system guide under the FusionProFrame Attributes section. Quote Link to comment Share on other sites More sharing options...
gdellaiera Posted August 1, 2017 Author Share Posted August 1, 2017 Dan, you are the man! Thanks for all 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.