View Full Version : How Can I Create a Function?

November 1st, 2012, 01:57 PM
I want to have this rule available to all jobs in Fusion Pro without having to copy and paste it everytime. The field will always be the same from my data.

"return MakeDataMatrixBarcode(Field("Sequen"), null, null, null, 7, null, null)"

Can this be done, I tried writing a .js file myself and putting the .js file in the plug-ins folder but it doesn't return anything. Thanks in advance for any help!!

Forgot to mention that I would need the Tagged Text box check as well.

November 1st, 2012, 02:38 PM
You were correct to create a .js file and place it in the plug-ins folder, but a function looks a bit different than a rule. Your rule would need to be written as:
function customDataMatrix() {
return MakeDataMatrixBarcode(Field("Sequen"), null, null, null, 7, null, null);
After placing the file in your plug-in folder and restarting FusionPro, the rule would appear in the Building Blocks dialog under the Functions tab in the (Globals) section. You would still need to create a rule in each job and check the tagged text box manually, but the rule would simply be written as:
return customDataMatrix();

Alternatively, you could keep (a copy of) the .dif file handy from a previous job that had your custom rule and when linking to data in a new template, you would choose to "Import a data source from another document" via the Wizard, choose the existing .dif file and then go back and pick the actual data file (if applicable) for the new project. Doing that will import all the rules from your former template so that you do not have to re-write the rule.

November 2nd, 2012, 06:00 AM
Thanks for the response, I have it working now.

Not as quick and easy as I was hoping it could be. May just have to keep the rule on my desktop for easy copying and pasting.

November 2nd, 2012, 07:19 AM
The last paragraph in my previous post is probably a better way to accomplish what you were after. Not sure if that's what you settled on or not. :)

I know a someone who keeps a .dif file containing all her "most used" rules in her documents folder which she imports for every new job she works on. She may not need all the rules it imports for every job, but it guarantees the common rules she does need will always be there when called upon.

November 2nd, 2012, 07:25 AM
I have used the method for creating a new job from a previous dif file, but this is a rule I would want available for every job no matter what rules were built in previous templates on a job per job basis.

Looking through the manual I think this can be accomplished if I edit the RulesTemplate.English.js file. Is this correct and has anyone tried this before?

Thanks for any help.

November 2nd, 2012, 07:38 AM
I figured it out, using the RulesTemplate.english.js file! This will be a great to use for rules I want to create for many of my jobs. I added this to the end of the file and it seems to work.

FusionPro.RuleTemplates["Make2D"] =
"Create 2D Barcode.",
"return MakeDataMatrixBarcode(Field(\"fieldname\"), null, null, null, 7, null, null);",

I actually now changed it to find my exact field name that will be the same for every job and now I don't have to make any edit to the rule, just add it.

November 2nd, 2012, 08:05 AM
You'll have to edit your signature now to "upgrade" your JavaScript knowledge. :)

Keep in mind that the next time you upgrade FusionPro, your RulesTemplate.english.js will be replaced and you'll have to add your custom rule back to the new file.

November 2nd, 2012, 08:10 AM
Great point, I will have to remember to keep that script handy if and when I upgrade to a newer version of FP!

I wouldn't go that far, but I am trying to learn things as I go!

November 2nd, 2012, 09:17 AM
Novice skills showing up again!!!

Wanted to do the same for my MAC but can't figure out where to get this done???

I don't see that same .js file in the location the manual says it is on the MAC.

Found it, for anyone that may want to know here it is:

/Library/Application Support/Printable/FusionPro