Calculated value

Issues related to label design (working with databases, data processing, RFID encoding etc.) and printing (from NiceLabel Express, NiceLabel Pro, NiceForm and NicePrint)

Moderators: Georges, milos, NiceLabel Support Team

Post Reply
cedmik
Enthusiast
Posts: 11
Joined: Tue Sep 30, 2014 9:46 am

Calculated value

Post by cedmik » Tue Sep 04, 2018 11:30 am

I have the necessity to put on a label a calculated value, referred to a string variable.
The value must be calculated with MD5 algorithm.
This algorithm is present on Nicelabel ?
Thanks

User avatar
Saso
NiceLabel
NiceLabel
Posts: 2933
Joined: Mon Sep 04, 2006 8:09 am
Contact:

Re: Calculated value

Post by Saso » Tue Sep 04, 2018 1:17 pm

NiceLabel does not have MD5 algorithm built in, but it can still calculate it for you.

The easiest method would be to use Python to do calculation for you. Python is a programming language that you can use in NiceLabel to extend the functionality of NiceLabel. You mostly use it for calculations. You would have to install Python on a computer with NiceLabel. The instructions are in this KB article.

The necessary Python code is this:

Code: Select all

import hashlib
Result.Value = hashlib.md5(Variable.Value).hexdigest()
That's all you need. The hash for value from variable "Variable" will be calculated using MD5 algorithm and the result provided to the label.

NOTE: Yes, NiceLabel 2017 comes with the embedded Python support (.NET variant of Python called IronPython). You can use that for calculations and decision making out-of-the-box. However, whenever you want to use some external modules in Python (this is what we do with "import hashlib" above), you have to install Python on your computer.

See the attached sample label.
Attachments
MD5.nlbl
(3.37 KiB) Downloaded 11 times
Saso Fleiser
Senior Technical Product Specialist

cedmik
Enthusiast
Posts: 11
Joined: Tue Sep 30, 2014 9:46 am

Re: Calculated value

Post by cedmik » Wed Sep 05, 2018 5:23 pm

Interesting!
This solution is possible also if i print through "Automation enterprise 1.5" ?
Thanks

User avatar
Kyleodonnell
NiceLabel Support
NiceLabel Support
Posts: 169
Joined: Mon Aug 28, 2017 3:07 pm

Re: Calculated value

Post by Kyleodonnell » Wed Sep 05, 2018 11:03 pm

Cedmik,

Unfortunately, .NLBL files can only be used with Nicelabel 2017. Automation 1.5 is from version 6 and not compatible with .NLBL files.

User avatar
Saso
NiceLabel
NiceLabel
Posts: 2933
Joined: Mon Sep 04, 2006 8:09 am
Contact:

Re: Calculated value

Post by Saso » Thu Sep 06, 2018 8:30 am

You can use the same Python script in LBL file for Automation 1.5.
Here is a sample LBL file. :)
Attachments
MD5.lbl
(85.5 KiB) Downloaded 18 times
Saso Fleiser
Senior Technical Product Specialist

cedmik
Enthusiast
Posts: 11
Joined: Tue Sep 30, 2014 9:46 am

Re: Calculated value

Post by cedmik » Mon Sep 10, 2018 5:03 pm

Hi Saso.
I have checked this procedure, but i have a problem.

My situation:
Automation enterprise 1.5 is installed on a server win2008 r2 64bit.
I have installed on the server Python 2.7 32 bit and Python for windows extension 32 bit.
On the same server i have also a Nicelabel pro 6 to develop new label.
Normal printing is trough automation script (web service).

If i open your example with nicelabel pro (located on the server) and i print, the label is printed correctly.
I suppose this is the signal what python is installed correctly on the server and is on-line.

But if i print trough the automation script, i have the error:
An error occurred during data processing.
Contents of item "MD5" can not be set, because its value is invalid.
An error occurred while trying to execute script. System error message: sequence item 0: expected bytes or byte array, str found

I don't understand where the problem is.
Could you help me ?
Thanks

cedmik
Enthusiast
Posts: 11
Joined: Tue Sep 30, 2014 9:46 am

Re: Calculated value

Post by cedmik » Wed Sep 12, 2018 12:16 pm

I have solved by myself.
the Triggers on automation enterprise has a scripting language assigned to it.
vbscript or python
i already have a lot of label that use vbscript and the trigger is only one.
i cannot mix labels that have vbscript with labels that have python.

The only solution is to realize the md5 algorithm with vbscript, but at the moment i don't have found examples of this.

Post Reply