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 November 8th, 2019, 02:37 AM
macfan55 macfan55 is offline
Junior Community Member
 
Join Date: Apr 2011
Location: Netherlands - Emmen
Posts: 35
Default Insert default picture ONLY if picture name is not found

I have several picture frames which will be filled with pictures (pdf) as names stated in the data field of an excel file. If the datarecord is filled with a name of a picture that does not exist a default picture is inserted automatically. But this default picture is also placed with an empty record.
Is there a way to instruct FP to leave the picture field empty when there is no data in the datafield and only to insert the default picture when the data in the datafield is not found as name of a picture?
This way I can determine any missing pictures (wrong name etc)
Thanks in advance for helping me out!
Greetings from the Netherlands
Reply With Quote
  #2  
Old November 8th, 2019, 09:59 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,505
Default Re: Insert default picture ONLY if picture name is not found

Code:
if (!Field("Picture"))
    return NullResource();

var pic = CreateResource(Field("Picture"), "graphic", true);
if (pic.exists)
    return pic;

return Resource("NotFoundResource");
Though, if you want to easily "determine any missing pictures (wrong name etc)," I would add a line to log those to the .msg file, like so:
Code:
if (!Field("Picture"))
    return NullResource();

var pic = CreateResource(Field("Picture"), "graphic", true);
if (pic.exists)
    return pic;

Print("Picture not found: " + Field("Picture"));
return Resource("NotFoundResource");
Then click "View Log" after composing, and search for "Picture not found".
__________________
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)});

Last edited by Dan Korn; November 8th, 2019 at 04:51 PM..
Reply With Quote
  #3  
Old November 11th, 2019, 08:04 AM
macfan55 macfan55 is offline
Junior Community Member
 
Join Date: Apr 2011
Location: Netherlands - Emmen
Posts: 35
Default Re: Insert default picture ONLY if picture name is not found

Hi Dan;
Thanks for answering but I can't figure out where exactly I have to put this code in the Rule of the field. It was made as an XML-template rule. If I convert that field to Javascript it contains the next lines of code:

// Rule converted from XML Template "JA08":
// Please select the appropriate values.
// Begin XML Template selections //
var Var1 = "JA08"; // "Choose the field containing the graphic name:" (Required): FieldList
var Var2 = ".pdf"; // "Choose the type of graphic:" (Required): PickList [".jpg" (JPG or JPEG), ".tif" (TIF or TIFF), ".png" (PNG), ".pdf" (PDF), ".gif" (GIF), ".eps" (EPS)]
var Var3 = "/Volumes/Var_Print/DAR/DARsymbolen"; // "Enter a search path:" (Required): SingleLine
var Var4 = "FOUT.pdf"; // "Enter the image name of a default graphic:" (Required): SingleLine
// End XML Template selections //

temp = '';
var_extension = '';
has_extension = '';

if (Var3 == "")
Var3 = Var3;
else
{
if (FusionPro.isMac)
Var3 = Var3 + ":";
else
Var3 = Var3 + "\\";
}

for (i=0; i<Field(Var1).length; i++)
{
temp = Mid(Field(Var1), Field(Var1).length-i,1);
var_extension = temp + var_extension;
var_extension = ToLower(var_extension);
if(var_extension == ".png" || var_extension == ".pdf" || var_extension == ".gif" || var_extension == ".eps" || var_extension == ".tif" || var_extension == ".tiff" || var_extension == ".jpg" || var_extension == ".jpeg")
{
has_extension = "true";
i=Field(Var1).length;
}
else
has_extension = "false";
}

if(has_extension == "true")
Pic = CreateResource(Var3 + Field(Var1), "graphic", true);

else
{
if(Var2 == ".jpg")
{
Pic = CreateResource(Var3 + Field(Var1) + ".jpeg", "graphic", true);
if (Pic.exists)
Pic = Pic;
else
Pic = CreateResource(Var3 + Field(Var1) + ".jpg", "graphic", true);
}


if(Var2 == ".tif")
{
Pic = CreateResource(Var3 + Field(Var1) + ".tif", "graphic", true);
if (Pic.exists)
Pic = Pic;
else
Pic = CreateResource(Var3 + Field(Var1) + ".tiff", "graphic", true);
}


if(Var2 == ".png" || Var2 == ".pdf" || Var2 == ".eps" || Var2 == ".gif")
{
Pic = CreateResource(Var3 + Field(Var1) + Var2, "graphic", true);
}

}

if (Pic.exists)
{
return Pic;
}

else
{
return CreateResource(Var3 + Var4, "graphic", true);
}
Reply With Quote
  #4  
Old November 11th, 2019, 12:41 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,505
Default Re: Insert default picture ONLY if picture name is not found

Quote:
Originally Posted by macfan55 View Post
Hi Dan;
Thanks for answering but I can't figure out where exactly I have to put this code in the Rule of the field. It was made as an XML-template rule. If I convert that field to Javascript it contains the next lines of code:
Sorry, I didn't realize you were using that as a starting point. That XML rule is a bit of a mess when converted to JavaScript.

I think this will work for you:
Code:
if (!Field("JA08"))
    return NullResource();

var pic = CreateResource(ReplaceFileExtension(Field("JA08"), ".pdf"), "graphic", true);
if (pic.exists)
    return pic;

Print("Picture not found: " + Field("JA08"));
return CreateResource("FOUT.pdf");
Instead of hard-coding the search path ("/Volumes/Var_Print/DAR/DARsymbolen") in the rule, I recommend putting it in the Search Path box on the Advanced tab of the Composition Settings dialog. Just paste the path in there (without the quotes).
__________________
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
  #5  
Old November 19th, 2019, 01:59 AM
macfan55 macfan55 is offline
Junior Community Member
 
Join Date: Apr 2011
Location: Netherlands - Emmen
Posts: 35
Default Re: Insert default picture ONLY if picture name is not found

Thanks Dan!
It works great for me.
The side-effect of turning the rules into Javascript is that the processing of the files are going much faster since there are ± 300 of these rules in the job. (pick-up trash calendar of a complete city with little pictures of different sorts of trash)
Greetings from the Netherlands
Reply With Quote
  #6  
Old November 19th, 2019, 12:29 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,505
Default Re: Insert default picture ONLY if picture name is not found

Quote:
Originally Posted by macfan55 View Post
Thanks Dan!
It works great for me.
The side-effect of turning the rules into Javascript is that the processing of the files are going much faster since there are ± 300 of these rules in the job. (pick-up trash calendar of a complete city with little pictures of different sorts of trash)
Greetings from the Netherlands
300? Wow! Your original post just mentioned "several" frames.

There's almost surely a way to refactor the job so that you don't have 300 rules, which would make it both even faster to compose and more maintainable. You could probably just fill all the graphic frames in a loop in OnRecordStart, calling either FusionPro.Composition.AddVariable or FindGraphicFrame and SetGraphic on the frame object. Actually, I suspect that you could make the entire calendar in a table, and not have to have so many frames in the first place, which would be the real optimization. If you post the job, I could probably greatly simplify it.
__________________
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
Reply

Tags
default, picture, rule

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 07:35 PM.


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