Jump to content

Insert default picture ONLY if picture name is not found


macfan55

Recommended Posts

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

Link to comment
Share on other sites

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:

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".

Edited by Dan Korn
Link to comment
Share on other sites

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);

}

Link to comment
Share on other sites

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:

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).

Link to comment
Share on other sites

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

:)

Link to comment
Share on other sites

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.

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...