Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library > Graphic Rules

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old July 7th, 2015, 03:09 PM
DWilliams DWilliams is offline
Forum n00b
 
Join Date: Dec 2014
Location: St. Louis, MO
Posts: 8
Default Return an Image value Based on the Value of a Selected Image?

Hello Again,

I find myself having trouble with some code that I have validated in Fusion Pro VDP's code editor, and as data output on my local computer, not behaving as expected in Marcom.

The idea is that a user will select a cover image for a multiple page brochure - out of a gallery style picker - and depending on the specific image they select the background images of the inside pages, inset flap and back cover will populate with images that best compliment the colors in the cover image. Basically letting the user pick the cover and having that determines the style for every other background image in the booklet.

My variable to select the cover is applied directly to the graphic frame of the cover, and is functioning correctly in Marcom, but the value of it does not seem to be making it to the rule in the template. The following code is an example of the rule I wrote for the back cover.

Code:
switch (GetFileName(Field("Cover Image")).toLowerCase())
{
	case "Sunset_Fade.pdf".toLowerCase():
		return Resource("Backer_Red.pdf");
	 case "Waterfall.pdf".toLowerCase():
		return Resource("Backer_Blue.pdf");
	 case "Starry_Sky.pdf".toLowerCase():
		return Resource("Backer_Purple.pdf");
	default:
		return Resource("Backer_Gray.pdf");
}
The rule is structured as a graphic switch rule, that I converted to java to try to trouble shoot, but in Marcom it only returns the default value.


I got it to work based on a text value input from Marcom, using a different variable as a quick test, but the client wants to be able to see the cover images in a gallery when ordering the brochure, so I cannot alter that part on the product. I'm baffled as to why it doesn't work.

Any thoughts on how to accomplish this while in Marcom?

Help is much appreciated!
__________________
FusionPro VDP Creator 9.2.31 | Adobe Acrobat XI Professional Ver 11.0.10 | Mac OS X 10.8.5
Reply With Quote
  #2  
Old July 7th, 2015, 03:38 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,359
Default Re: Return an Image value Based on the Value of a Selected Image?

First, if the question really is specific to MarcomCentral, then it should be asked in the MarcomCentral forum.

That said, it seems that the data field value from the data file that MarcomCentral is generating for the end user's web form selections is different than what you're expecting.

I would think that the easiest way to troubleshoot this would be to simply set the value of that "Cover Image" data field in a text frame, then you should see it right there in the output. My guess is that the data field value that MarcomCentral is putting in there isn't just a file path, it's a graphic tag.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #3  
Old July 7th, 2015, 04:06 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Return an Image value Based on the Value of a Selected Image?

Your problem sounds pretty similar to this thread. I'd bet with a few tweaks, the same solution would work for you:
Code:
var header = String(GetFileName(Field("Cover Image")).match(/(sunset_fade|waterfall|starry_sky)\.pdf/ig));
var color = '';

switch (ToLower(header)){
    case "sunset_fade.pdf":
        color = "Red";
        break;
     case "waterfall.pdf":
        color = "Blue";
        break;
     case "starry_sky.pdf":
        color = "Purple";
        break;
    default:
        color = "Gray";
}

return Resource("Backer_" + color + ".pdf");
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #4  
Old July 8th, 2015, 11:36 AM
DWilliams DWilliams is offline
Forum n00b
 
Join Date: Dec 2014
Location: St. Louis, MO
Posts: 8
Thumbs up Re: Return an Image value Based on the Value of a Selected Image?

Quote:
Originally Posted by step View Post
Your problem sounds pretty similar to this thread. I'd bet with a few tweaks, the same solution would work for you:
Code:
var header = String(GetFileName(Field("Cover Image")).match(/(sunset_fade|waterfall|starry_sky)\.pdf/ig));
var color = '';

switch (ToLower(header)){
    case "sunset_fade.pdf":
        color = "Red";
        break;
     case "waterfall.pdf":
        color = "Blue";
        break;
     case "starry_sky.pdf":
        color = "Purple";
        break;
    default:
        color = "Gray";
}

return Resource("Backer_" + color + ".pdf");
Thank you both so much, this answer worked!

Logically, I can't see how the resource return being outside the switch rule should have an effect on the return value other than being able to build the file name returned from a variable? I think what I needed was the line ensuring the input matched my options while converting the input value to a string before heading into the switch. I haven't tested the theory yet, but I might when I'm less pressed for time.

This also marks the first coding use I have had for a regular expression outside of an academic setting. Yay..?

__________________
FusionPro VDP Creator 9.2.31 | Adobe Acrobat XI Professional Ver 11.0.10 | Mac OS X 10.8.5
Reply With Quote
  #5  
Old July 8th, 2015, 12:32 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Return an Image value Based on the Value of a Selected Image?

Quote:
Originally Posted by DWilliams View Post
Logically, I can't see how the resource return being outside the switch rule should have an effect on the return value other than being able to build the file name returned from a variable?
There shouldn't be. That's just personal preference for me. I'm not a fan of writing the same things multiple times.
Quote:
Originally Posted by DWilliams View Post
I think what I needed was the line ensuring the input matched my options while converting the input value to a string before heading into the switch.
I don't think that's it. The "String" function is converting the array value that's returned from the 'match' method to a string – not your input value. Your input value is already a string. What you were probably missing was the RegExp that is searching the entire field for "sunset_fade.pdf" (for example) so that if what Dan said is true and MarcomCentral is tagging that field, a match is still made.

So, if your field value in Producer is "/path/to/sunset_fade.pdf" then:
Code:
GetFileName("/path/to/sunset_fade.pdf") == "sunset_fade.pdf"
But MarcomCentral may tag it so:
Code:
GetFileName('<graphic file="/path/to/sunset_fade.pdf">') == 'sunset_fade.pdf">' // NOT "sunset_fade.pdf"
But with the RegExp the match is still made:
Code:
String(GetFileName('<graphic file="/path/to/sunset_fade.pdf">).match(/(sunset_fade|waterfall|starry_sky)\.pdf/ig)) == "sunset_fade.pdf"
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
Reply

Tags
fusion pro, image, image rule, marcomcentral

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:46 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.