Python script using database variables.

Label printing integration (NiceWatch middleware and ActiveX programming interface)

Moderators: Georges, milos, NiceLabel Support Team

Post Reply
Candlescience
Newcomer
Posts: 4
Joined: Mon Mar 28, 2016 9:41 pm

Python script using database variables.

Post by Candlescience » Fri Mar 23, 2018 4:13 pm

Hello all,

I am trying to get a Python script to work using a database variable. We are using NiceLabel 6, I tried executing the same script with NiceLabel 2017 and it does work; however, when trying to execute the same script with NiceLabel 6, I'm unable to do so.
I have attached screenshots of my script. Please let me know if there's anything else you need from me.

I followed the instructions on how to install Python to be used with NiceLabel 6 as well https://www.nicelabel.com/support/knowl ... ing-python
The attachment NiceLabel 2017.png is no longer available
The attachment NiceLabel 2017.png is no longer available
The attachment NiceLabel 2017.png is no longer available
Thank you!
Attachments
NiceLabel 2017.png
NiceLabel 2017.png (149.69 KiB) Viewed 7060 times
NiceLabel6-label_large.png
NiceLabel6-label_large.png (196.82 KiB) Viewed 7061 times

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

Re: Python script using database variables.

Post by Saso » Mon Mar 26, 2018 8:55 am

When using variables in Python, you have to refer to their name as variable_name.Value.

If the variable_name itself contains dots in its name, your Python syntax will not be correct.
Python does not know how to handle the following.:

Code: Select all

variable.name.Value
NiceLabel will always construct database variables out of two components: table name <dot> field name. You cannot really get rid of the dot in the middle or replace it with some other character. :?

There is, however, another workaround.
You could use a Concatenate function, configure one "database variable" as input and use the custom name of the output variable. Such Concatenate function will just be used to rename the variable.

You will have to create as many Concatenate functions as you have database variables that you intend to use inside Python script.
Saso Fleiser
Senior Technical Product Specialist

Candlescience
Newcomer
Posts: 4
Joined: Mon Mar 28, 2016 9:41 pm

Re: Python script using database variables.

Post by Candlescience » Mon Mar 26, 2018 6:02 pm

Thank you so much Saso! That is exactly what I needed to know. =D> =D> =D>
Now the database variables work as expected in Python.

lalo
Newcomer
Posts: 5
Joined: Thu Jun 22, 2017 2:29 pm

Re: Python script using database variables.

Post by lalo » Mon Jan 07, 2019 11:58 am

Saso wrote:
Mon Mar 26, 2018 8:55 am
When using variables in Python, you have to refer to their name as variable_name.Value.

If the variable_name itself contains dots in its name, your Python syntax will not be correct.
Python does not know how to handle the following.:

Code: Select all

variable.name.Value
NiceLabel will always construct database variables out of two components: table name <dot> field name. You cannot really get rid of the dot in the middle or replace it with some other character. :?

There is, however, another workaround.
You could use a Concatenate function, configure one "database variable" as input and use the custom name of the output variable. Such Concatenate function will just be used to rename the variable.

You will have to create as many Concatenate functions as you have database variables that you intend to use inside Python script.
My customer has 120 columns, most of them are required for printing.

Does this mean, that I need create an additional function for EACH database field of the table if I want to use them in pyhton scripting?

Is there any improvement in NL 2019 to provide "Python Friendly" database field names?

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

Re: Python script using database variables.

Post by Saso » Mon Jan 07, 2019 12:17 pm

Well, there is another (simpler) way, but it also requires some manual work.

You can update the "field alias" value for each field. NiceLabel will use "table_name.field_name" syntax. You can manually replace the period "." with some other character, such as underline "_".

Yes, you will have to do this 120 times. :?

Do the following:
  1. In Dynamic Data Manager, expand the connection to your database.
  2. Select each field to display its properties.
  3. Update the Field alias field. Replace period with some other character.
    screenshot.png
    screenshot.png (70.19 KiB) Viewed 5660 times
Saso Fleiser
Senior Technical Product Specialist

lalo
Newcomer
Posts: 5
Joined: Thu Jun 22, 2017 2:29 pm

Re: Python script using database variables.

Post by lalo » Tue Jan 08, 2019 8:57 am

Saso wrote:
Mon Jan 07, 2019 12:17 pm
Well, there is another (simpler) way, but it also requires some manual work.

You can update the "field alias" value for each field. NiceLabel will use "table_name.field_name" syntax. You can manually replace the period "." with some other character, such as underline "_".

Yes, you will have to do this 120 times. :?
Thank you, that is a much quicker solution, but it would be really an improvement to have some kind of automatic pyhton support.

Post Reply