Jump to content

Applying a Specific Color to a Variable


Admin1676454018

Recommended Posts

// This rule allows you to apply a color to a variable.

 

// There are three methods of specifying a color – using the color's name from the color dictionary, using the RGB value, using the CMYK value.

// Both the RGB and CMYK declarations use the Hexadecimal values.

 

// In the code, all three methods are listed. Simply remoev the methods you don't want and apply the correct value.

// For example, to apply "blue", <color name = "Blue">, <color RGB = "0000FF">, or <color CMYK = "FFE61900">

 

// The final line resets the color back to "black"

 

 

if (Field("fax") == "")

return "";

 

else

return "Fax: "+ "<color name = \"Blue\"> <color RGB = \"0000FF\"> <color CMYK = \"FFE61900\">" + Field("fax") + "<color name= \"Black\">";

Link to comment
Share on other sites

  • 1 month later...

I have a business card template that contains several fields (Name, Title, Slogan, Phone1label, Phone1, etc). I also have several rules in the template. I want to make all of the text blue if Blue is chosen from a dropdown list, or all the text Red if Red is chosen from the dropdown list, otherwise all needs to remain black. Do I need to write a rule for each field, or is there a rule i can write to effect all active fields?

 

gabrielle

gabrielleb@harrisprinters.com

Link to comment
Share on other sites

Gabrielle-

 

Use the above rule, but instead of Calling the color out like: <color name = \"Blue\">,

call it out as a variable as such : <color name = CardColor>

 

Then write a rule to assign Red or Black to CardColor: if .... then CardColor = "Red", else CardColor = "Black"

Link to comment
Share on other sites

Thank you jshobar:

I understand where you are going with this, but i am still unclear how to fully implement this to all of the fields without writing a separate rule for each field.

Is there a script to change all the variable fields to the ColorCard color?

Link to comment
Share on other sites

Not that I can think off off hand. Even with alot of Fields, you only have to write one rule and duplicate it a number of times, changing one line. Or if you can set all your text as a Resource, you could then grab the tagged text and have one rule that would change the entire color of the resource. Alternatively, there may be code you could write that would redefine the color "Black" to be what ever you wanted it to be, but I'm not sure on that one.
Link to comment
Share on other sites

Hello Gabrielle,

 

I tried a couple of things and think there might be an easier way to accomplish what you are after with 1 rule.

 

Make a rule called something like colorChangeRule that looks like this:

 

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

Make sure you select the "treat returned strings as tagged text" option in your rule. This rule assumes you have a field called "Color" that references a valid color in your template.

 

Then, in the variable text editor where you want the color to be used for your data, just insert this rule "colorChangeRule" before any placement of your fields. for example:

 

«colorRule»«First Name» «Last Name»

«colorRule»«Address 1»

 

This rule should change the color of the text after it. Notice, though, that if you have a new line, you need to place that rule again.

 

Is this what you are looking for?

Link to comment
Share on other sites

Great Solution!

 

If you didn't want to Include the color in the data you could change the above to:

 

 return '<color name="' + Rule("Color") + '">'; 

 

And then have one Rule that decides the color.

Edited by jshobar
Link to comment
Share on other sites

Good to hear this works for you, Gabrielle.

 

As you point out, you can indeed use this method to have rules enable a number of other character/paragraph formatting options as well such as font name, bold, italic, font size, alignment, etc.

Link to comment
Share on other sites

  • 6 years later...

I'd like to chime in on this with an additional twist to the problem...we are doing items for different area schools and would like to have type and backgrounds output in their specific school color. We are being supplied with either a PMS color or a cmyk build-up for their color. Either way we have the ability to get the base cmyk build for each school. My problem is that if we do 100 schools, I would probably need to individually program around 60 or maybe 70 specific colors for the different schools, then create a rule to change the color to one of this variations. I would like to stream-line that down to just one definition.

 

Is there a way to have a predefined color name, in my example say "schoolColor", and then within the data file dynamically read in the color values and assign it to schoolColor. So for records 1 thru 10 every variable item in the template that is defined with "schoolColor" would turn a specific color of Blue for School-A, then when records 11 thru 25 are read in the definition of "schoolColor" is reassigned to a cmyk variation of Red or Green or Pink or whatever school is being processed at the time.

 

Having to predefine and program less than 100 schools and colors might not be too bad, but if this program takes off we might be doing 1000's of schools with virtually any number of school colors. That's a headache that I don't want to be hit with.

 

Any help would be appreciated.

.

Link to comment
Share on other sites

I would think you could put something like this in your OnRecordStart rule to define the CMYK values of the color you've defined in your template:

var field = "100,0,100,0"; // Your CMYK Field
var [c,m,y,k] = field.split(',').map(function(s){ s=StringToNumber(s); return (s>100) ? 100 : (s < 0) ? 0 : s;})
new FusionProColor("schoolColor", c, m, y, k);

I'm assuming that the field you're keying off of is a comma-separated CMYK definition but I'm sure you could easily adapt this solution to your particular scenario.

Link to comment
Share on other sites

I'd like to chime in on this with an additional twist to the problem...we are doing items for different area schools and would like to have type and backgrounds output in their specific school color. We are being supplied with either a PMS color or a cmyk build-up for their color. Either way we have the ability to get the base cmyk build for each school. My problem is that if we do 100 schools, I would probably need to individually program around 60 or maybe 70 specific colors for the different schools, then create a rule to change the color to one of this variations. I would like to stream-line that down to just one definition.

 

Is there a way to have a predefined color name, in my example say "schoolColor", and then within the data file dynamically read in the color values and assign it to schoolColor. So for records 1 thru 10 every variable item in the template that is defined with "schoolColor" would turn a specific color of Blue for School-A, then when records 11 thru 25 are read in the definition of "schoolColor" is reassigned to a cmyk variation of Red or Green or Pink or whatever school is being processed at the time.

 

Having to predefine and program less than 100 schools and colors might not be too bad, but if this program takes off we might be doing 1000's of schools with virtually any number of school colors. That's a headache that I don't want to be hit with..

Sure, this is possible. Although exactly what to do depends on what you're trying to apply a color to; in other words, it's different for text than for things like frame borders and fill/shading.

 

For text, it's pretty easy: you just use <color> tags. As detailed in the FusionPro Tags Reference Guide (and elsewhere in these forums), you can specify either RGB or CMYK attributes, with hexadecimal values, such as <color rgb="ff0000"> or <color cmyk="ff00ff00">, in addition to being able to call out a color by name, such as <color name="green">.

 

You can also add a named color in JavaScript, with the FusionPro Color object, as detailed here:

http://forums.pti.com/showpost.php?p=11580&postcount=3

 

In OnRecordStart, you can add a new color on a per-record basis by calling "new FusionProColor", or modify an existing color by calling the Color function or accessing a property of FusionPro.Colors to obtain a FusionProColor object, which you can then modify. You can also add a new color "on the fly" in any rule where you need it. Then you can access that color, by name, in a <color> tag in text, and also for things like frame borders and fills, with properties like borderColorName or fillColorName on a frame object returned from FindTextFrame or FindGraphicFrame.

 

Or you can simply modify an existing color in OnRecordStart, and the changes will apply to everything using that named color in the record, which is basically what Step's code does. Or you could do it like this:

var color = Color("schoolColor");
color.cyan = 20;
color.magenta = 50;
color.yellow = 30;
color.black = 0;

Or the same thing with this as the first line instead of the call to the Color function:

var color = FusionPro.Colors["schoolColor"];

As in the other post, with the JavaScript objects, each color range is a decimal percentage, from 0 to 100.

 

If you want to call out a Spot color, such as Pantone color, you can set the .isSpot property of the FusionProColor object to true, or pass true as the sixth parameter in the call to "new FusionProColor". Then you can call that color out by name, either in a <color> tag, or by setting a property in JavaScript to it, just like with any other color, and as long as that spot color is indeed available when the output is printed, it should work. Although you should try to get the CMYK process color equivalent of the spot color right for on-screen display or other conversions.

Link to comment
Share on other sites

So I am restricted into only being able to do this by a color-tag? I am not able to predefine in the Colors Palette the color "schoolColor" and then redefine it in OnRecordStart? This way I would be able to just use the color as part of the pull downs when assigning it to text and frame elements?
Link to comment
Share on other sites

So I am restricted into only being able to do this by a color-tag?

No, you're not restricted that way at all. Sorry if I wasn't clear in my post:

Or you can simply modify an existing color in OnRecordStart, and the changes will apply to everything using that named color in the record, which is basically what Step's code does. Or you could do it like this...

I am not able to predefine in the Colors Palette the color "schoolColor" and then redefine it in OnRecordStart?

Yes, you can in fact do exactly that. Here's a better example: If I set some text in Red, and then add this line to OnRecordStart:

new FusionProColor("Red", 100, 0, 0, 0);

It then comes out in Cyan (light blue) in the output.

This way I would be able to just use the color as part of the pull downs when assigning it to text and frame elements?

Yes.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...