Scripting the message to different line and show in ignition

i have one message in Chinese with \n to divide them to different lines:

Message is
‘计划编号: 5000288049 箑号: 19G106965\n 物资编码: R581250011 物品: 74NT9500NT扶手带\n 硛度: 33.1米 数量: 2条 ATO:TXZ153100\n 箱头制造\n PO:4531430139\n REV#: -\n 出口包装\n Ching Long Shopping Centre\n H K\n’
i want to show this message in the ignition in different lines

so i do a test in scripting


if i first store the data in the tag(string or text), and read the value from that tag, then i trigger print
image
i found \n still inside, all the data in 1 line

if i just give the data to Message directly
image

image
the data are in different line and the \n disappear

  1. I don’t know the difference between these two scripting?

  2. if i have the data in different line, how can i disappear them in the ignition interface?

If you want the message to be shown in a label or something, try use HTML.
So, you have to put < HTML > before your message and replace the /n with < br >.

PS: Inside the Scripting Console you’ll see the message as a single line, but if you put your message in a label it will be formatted correctly.

1 Like

It has nothing to do with Chinese. In python string constants, the backslash is an escape character that causes the next character to be interpreted as a control code. So when you supply the string as a constant in the script console, python is changing those \n entries to an actual ASCII LineFeed code. If you want string tag to behave the same, you must supply line feed codes in the string tag.

A TextArea component can do this (and display the separate lines properly).


I have try to follow your advise, binding it to a label , it works
image

image
i have 1 Chinese word CSV document


i following the ignition 8 manual to import the csv to a power table
image
i found the power table can’t show Chinese, do i have some solution to let power table to show the Chinese?
Many thanks in advance

I would expect the problem to be jython’s csv module, not the power table. jython is built on python 2.5 (2.7 for Ignition v8), which doesn’t do multibyte character sets properly.

If you can restructure your CSV file slightly to follow Ignition’s dataset import/export format, I would expect that to handle the characters correctly. Use system.file.readFileAsString() with utf-8, then use system.dataset.fromCSV() to yield the dataset.

If you cannot modify the CSV format, or do not want a dataset result, you can directly use Ignition’s underlying CSV parser/writer package.


I following the manual
path = system.file.openFile(“CSV”)
if path != None:
contents = system.file.readFileAsString(path)
event.source.parent.getComponent(‘Text Area’).text= contents
these four line , i can see the text Area is showing Chinese

After step 1 success, i follow step 2
image
data = system.dataset.fromCSV(event.source.parent.getComponent(‘Text Area’).text)
event.source.parent.getComponent(‘Power Table’).data=data

image
i suppose the red line high light is the Name

@yifeiliu08 You didn't do that. There is extra data at the top that needs to exist in order to use system.dataet.fromCSV().

1 Like

image
I Follow the manual instruction, create a csv document, you can see the upside picture
when i use notepad open, it will have the same structure as manual
image

then i scripting


image
it still fault, expected names on line 1, i am confused , it seems my csv document totally the same as the manual , why still report fault ?

post your csv file here. I suspect there are extra characters in there.

yes, you are right, when i copy and paste again , it works, thanks a lot

i have check the first action use the special csv format , it works


but as a new user, i think this page is much easy to understanding and test
https://docs.inductiveautomation.com/display/DOC80/Exporting+and+Importing+a+CSV
also i have try to use CSV.reader as the manual shows, Chinese can’t be show in powertable and in the console
image
image
thanks for your suggestion.

If you post or pm me a sample of your csv file, I can take a closer look. There is likely an encoding issue going on.

test2.csv (256 Bytes)
Here is the document, i can’t find any difference
But if i following the manual use the notepad copy and paste create a new csv document it will have no issue
i have also try to first create a excel , then convert it to a csv


after i covert the excel to csv, i will found this will be a double’,’ after the names, and i have to delete the ‘,’ and save as again.
So currently i will use the example.csv as a demo, i will base on this document do some modification

Creating a csv file in Excel here does not give an import issue, even with the extra commas after #NAMES.

Post a file that will not work, and let’s check for extra bytes before #NAMES. A BOM (byte order marker) comes to mind.

1 Like

I meet another problem with the csv import issue

ansi.csv (264 Bytes) UTF8.csv (292 Bytes)
i have create a csv document with ansi encoding method


i will success import them with no fault
but my content have chinese , some computer will have issue with the ansi encoding
so i try to save as utf-8


then i use notepad to open them and i can’t see any difference between these two encoding method
but if i import the UTF8 CSV , it will report fault
![image|690x435]
(upload://ndvxv3OKcxhUfKLx2F1kdMqojOi.png)
can you help me download the utf8 to verify what’s wrong?


here is my scripting

path = system.file.openFile(“csv”)
data_string = system.file.readFileAsString(path)

Convert the string to a dataset and store in a variable

data = system.dataset.fromCSV(data_string)

Assign the dataset to a table

#event.source.parent.getComponent(‘Power Table 3’).data = data
query=""" INSERT INTO [dbo].[SalesText1]
([SaleOrder]
,[Date]
,[Pos]
,[Remark]
,[UpdateTime])
VALUES
(?,?,?,?,SYSDATETIME())
“”"
py_TableData = system.dataset.toPyDataSet(data)
system.gui.messageBox(u’请注意,数据在上传中, 请稍后’)
for row in py_TableData:
args = [row[0], row[1],row[2],row[4]]
system.db.runPrepUpdate(query, args)
system.gui.messageBox(u’数据传送完毕’)

many thanks in advance