Jump to content

Change color of a box with Rule


EricC

Recommended Posts

I have a Graphic Box in my FusionPro PDF.

The box is colored red.

 

I want to write a rule that allows the user to select a color from a drop-down list, and then the color of this box will change.

 

i.e. if the user selects 'Green' from the list, then the box changes from red to green.

 

Is this possible?

Link to comment
Share on other sites

Hi Eric,

 

Depending on how many colors you plan on offering, the set up may be a little tedious and time consuming but this always works well for us:

 

- Create a file for each color (if it's just a box, you can create it easily in Illustrator as save as an EPS)

- Add all the files as graphic resources to your template

- Create a text field in your database that includes the color name

- Set up a Graphic rule that pulls the correct file based on the color name indicated in your database

 

Hope that helps!

Link to comment
Share on other sites

Eric,

 

Lisa's suggestion is the best option I can think of to accomplish this as well.

 

However, we will have a MUCH easier way to change the background color of a frame in the 6.0 release of our FusionPro 6.0 suite. Release is just weeks away. Stay tuned....

Link to comment
Share on other sites

I made a custom font with differently shaped boxes. It takes some fiddling but you can then create a text frame and use that font with the color control tags to change the color.

 

Easiest to use a font editor that can import EPS files. That way you can get the correct proportions, then you just need to scale the font to the correct size in FP.

 

You can do random colors and all kinds of weird things.

Link to comment
Share on other sites

I made a custom font with differently shaped boxes. It takes some fiddling but you can then create a text frame and use that font with the color control tags to change the color.

 

Easiest to use a font editor that can import EPS files. That way you can get the correct proportions, then you just need to scale the font to the correct

 

I've gotta admit, that's pretty sick! I love the approach..

Link to comment
Share on other sites

  • 4 months later...

Hello Dadburne,

 

With FP 6.0, you can set the background color of your frame programatically via JavaScript.

 

Just a couple items to mention regarding this capability:

- With your JS, you refer to your frame by name. The name is set in the properties dialog for that frame (it's the setting at the very top of that properties dialog that is "Untitled" by default)

- This JS goes into an OnRecordStart rule

- You need to refer to a color that FusionPro has in its color dictionary for the template (FusionPro -> Advanced -> Colors)

 

Here's some sample code that shows setting the background color of a text frame called "MessageFrame" to "Green":

 

var MessageFrame = FindTextFrame("Welcome");
MessageFrame.fillColorName = "Green";

 

Note that you can also set the background color for graphic frames as well as about 50 other frame properties using JavaScript. More details about this can be found in the FusionPro 6.0 documentation. See the "Rules Guide Excerpt..." PDF doc here:

 

http://forums.printable.com/showthread.php?t=329

 

hth.

Link to comment
Share on other sites

Mark,

Thanks for the info. This template is for a PrintOne store. What is the most efficient way to give the user access to 10 colors to choose from for the fill color of the text frame?

Should I just add 10 instances of the var in the rule?

Link to comment
Share on other sites

Dadburn,

 

I would have a field in your data called something like "FrameColor". This would contain the name of the color that the user selects.

 

Your rule can then be:

 

var MessageFrame = FindTextFrame("Welcome");
MessageFrame.fillColorName = Field("FrameColor");

 

When you setup this item in FP Web, I suggest a drop-down where the user can select from the 10 colors.

 

hth.

Link to comment
Share on other sites

What is the proper code if I have 5 text boxes that need to receive this color?

 

var theframe = FindTextFrame("TextBox2","TextBox1","TextBox3");

if (Field("ColorTheme")=="Red")

theframe.fillColorName = "red"

else if (Field("ColorTheme")=="Royal Blue")

theframe.fillColorName = "Royal Blue"

else if (Field("ColorTheme")=="Forest Green")

theframe.fillColorName = "Forest Green"

else if (Field("ColorTheme")=="Navy")

theframe.fillColorName = "Navy"

else if (Field("ColorTheme")=="Maroon")

theframe.fillColorName = "Maroon"

else if (Field("ColorTheme")=="Purplee")

theframe.fillColorName = "Purple"

else if (Field("ColorTheme")=="Green")

theframe.fillColorName = "Green"

else if (Field("ColorTheme")=="Black")

theframe.fillColorName = "Black"

else

theframe.fillColorName = "Black"

Link to comment
Share on other sites

var theframe = FindTextFrame("TextBox2","TextBox1","TextBox3");

theframe.fillColorName = Field("ColorTheme")

 

What would I use for the font color?

I'm not sure exactly what you're asking. I can tell you that the FindTextFrame function only returns one frame at a time, so if you wanted to apply a particular color to five different frames, you'd have to call the function five times. For example:

FindTextFrame("TextBox1").fillColorName = Field("ColorTheme");
FindTextFrame("TextBox2").fillColorName = Field("ColorTheme");
FindTextFrame("TextBox3").fillColorName = Field("ColorTheme");
FindTextFrame("TextBox4").fillColorName = Field("ColorTheme");
FindTextFrame("TextBox5").fillColorName = Field("ColorTheme");

Or, more programatically:

for (var i = 1; i <= 5; i++)
 FindTextFrame("TextBox" + i).fillColorName = Field("ColorTheme");

Link to comment
Share on other sites

What would I use for the font color?

Sorry, I think you're asking about an entirely different thing. If you want to change the color of the text itself (not the background color of the frame), you can write a rule that returns a <color> tag, like so:

return '<color name="' + Field("ColorTheme") + '">';

And then insert the rule variable before whatever text you want in that color.

 

If you need the color to apply to multiple paragraphs, you can use the <span> tag instead, like so:

return '<span color="' + Field("ColorTheme") + '">';

Link to comment
Share on other sites

  • 9 months later...

I want to do something simalir to this...

 

I have a custoner who has 6 differnt BC' template and was hoping to consolidate them so we could do one print run instead of 3 or 5.

 

what I would like to do is something like

 

var theframe = FindTextFrame("1 name","1 Cell","1 Title");
if (Field("Template") == ("#1 - IMS Template"))
theframe.fillColorName = "White";
else 
theframe.fillColorName = "none";

var theframe = FindTextFrame("2 name","2 Cell","2 Title");
if (Field("Template") == ("#2 - IMS Template"))
theframe.fillColorName = "White";
else 
theframe.fillColorName = "none";

 

and so on untill I have all six done. I can get the code to validate but it doesnt change the color of the frames??

 

any help would be great!

 

thanks

 

Aaron

Link to comment
Share on other sites

var theframe = FindTextFrame("1 name","1 Cell","1 Title");

You can't call the FindTextFrame function that way with multiple parameters. It takes a single parameter, the name of a single text frame. If you want to access multiple frames, you need to call the function multiple times. For instance:

if (Field("Template") == "#1 - IMS Template")
{
 FindTextFrame("1 name").fillColorName = "White";
 FindTextFrame("1 Cell").fillColorName = "White";
 FindTextFrame("1 Title").fillColorName = "White";
}

I can get the code to validate but it doesnt change the color of the frames??

Getting the code to validate in the Rule Editor is one thing; actually having it work successfully at composition time is another. Always do a regular (non-Preview) composition and check your log (.msg) file for warning messages. In particular, the FindTextFrame and FindGraphicFrame functions will throw an exception if the named frame is not found, and unless it's caught, that exception will prevent any code in the rule following that call from being executed. To get around this, you can wrap the call in a try block, like so:

if (Field("Template") == "#1 - IMS Template")
{
 try
 {
   FindTextFrame("1 name").fillColorName = "White";
   FindTextFrame("1 Cell").fillColorName = "White";
   FindTextFrame("1 Title").fillColorName = "White";
 }
 catch (e)
 {
   Print(e);
 }
}

Calling the Print function will make sure the message is still written to the log file, while still catching the exception to allow other code in your rule to run.

 

Maybe what you want to do is wrap this logic into a custom function which can take multiple frame names as parameters, like so:

function SetTextFramesColor(ColorName) // , Frame1Name, Frame2Name, etc.
{
 for (var i = 1; i < arguments.length; i++)
 {
   try
   {
     var result = Field(arguments[i]);
     FindTextFrame(arguments[i]).fillColorName = ColorName;
   }
   catch (e)
   {
     Print(e);
   }
 }
}

if (Field("Template") == ("#1 - IMS Template"))
  SetTextFramesColor("White", "1 name","1 Cell","1 Title");
else 
  SetTextFramesColor("none", "1 name","1 Cell","1 Title");

if (Field("Template") == ("#2 - IMS Template"))
  SetTextFramesColor("White", "2 name","2 Cell","2 Title");
else 
  SetTextFramesColor("none", "2 name","2 Cell","2 Title");

// etc.

Furthermore, all this code which is repeated with "1" and "2" and so on can be reduced and put into a loop, like so:

function SetTextFramesColor(ColorName) // , Frame1Name, Frame2Name, etc.
{
 for (var i = 1; i < arguments.length; i++)
 {
   try
   {
     var result = Field(arguments[i]);
     FindTextFrame(arguments[i]).fillColorName = ColorName;
   }
   catch (e)
   {
     Print(e);
   }
 }
}

for (var tNum = 1; tNum <= 6; tNum++) // template number
{
 var color = "none";
 if (Field("Template") == ("#" + tNum + " - IMS Template"))
   color = "White";

 SetTextFramesColor(color, tNum + " name", tNum + " Cell", tNum + " title");
}

In any case, you'll still want to check the log file for messages.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...