Image Management vision 8.1

How to print image management image path and image using script

Going to need a little more information.

Where is this image? In an image component on a window?
Where do you want to print it?

What have you tried and what didnā€™t work?

Have you looked at system.print.createPrintJob()?
https://docs.inductiveautomation.com/display/DOC81/system.print.createPrintJob

I have stored two company logo (T1.png) and (T2.png) format uploaded on Image management in ignition vision 8.1.19 version.

Locally Stored image this location : C:/Users/T1280675/PycharmProjects/Python_Code/ss.png ( it shows full path of image)

But in ignition vision client running in office server:
image

path shows : Ignition Server.png

but i need C:/Users/ like that location

strong textif any function available in ignition directly read image from Image Management **
strong textso please revert me** .

for reference code:

ws.insert_image(ā€˜A1ā€™, ā€˜C:/Users/T1280675/PycharmProjects/Python_Code/ss.pngā€™,{ā€˜x_offsetā€™:0, ā€˜y_offsetā€™:0,ā€˜x_scaleā€™: x_scale, ā€˜y_scaleā€™: y_scale}) # Locally stored Image location in PC

ws.insert_image(ā€˜A1ā€™, ā€˜ss.pngā€™,{ā€˜x_offsetā€™:0, ā€˜y_offsetā€™:0,ā€˜x_scaleā€™: x_scale, ā€˜y_scaleā€™: y_scale}) # ignition Image Mangement location

The whole point of image management is that you upload files from your development machine onto the Gateway, which then makes them accessible to all clients.

Lets start over.

What are you trying to accomplish?

What I think youā€™re trying to do is to take an image from a client machine and insert it into the image management.

What I donā€™t understand is why. What is the end goal?

no i want fetch image from image management during the export excel image will be visible in excel company logo

and also upload and download image from image management but script (using ignition function)

What I think youā€™re trying to do is to take an image from a client machine and insert it into the image management.
NO

Simple ā€¦ way ā€¦
I uploaded image into image management , so i want to read path from image management image.
(it is not copied full path from image management image )

using script ( if any ignition vision functions available , please reply (like system function )

If youā€™re trying to program upload and download functionality, then you are probably wanting a file explorer component.

Then, you will probably use code that looks similar to this to guide your user:

import getpass
stringPath = "C:\\User\\"+getpass.getuser()+"\\Pictures\\"
event.source.parent.getComponent('File Explorer').rootDir = stringPath
event.source.parent.getComponent('Text Field').text = stringPath

image

Hello justin edwards

Requirement : Image read from image Management not in local directory

Please go through this code :slight_smile: (use code in button and check )

from xlsxwriter import Workbook
#import getpass
#wb = xlsxwriter.Workbook(ā€˜hello.xlsxā€™)
path = system.file.saveFile(ā€˜hello.xlsxā€™)
wb = Workbook(path)
ws = wb.add_worksheet(ā€œLoading_Robot_infoā€)
cell_format = wb.add_format({ā€˜alignā€™: ā€˜centerā€™,ā€˜valignā€™: ā€˜vcenterā€™,ā€˜borderā€™:2, ā€˜border_colorā€™:ā€˜blackā€™, ā€˜font_sizeā€™:50,})
ws.merge_range(ā€˜A1:H1ā€™, ā€œā€, cell_format)
image_width = 50.0
image_height = 58.0
###############
image_width1 = 60.0
image_height1 = 110.0
###############
cell_width = 64.0
cell_height = 20.0
x_scale = cell_width/image_width
y_scale = cell_height/image_height

#######################
x_scale1 = cell_width/image_width1
y_scale1 = cell_height/image_height1
#######################
ws.insert_image(ā€˜A1ā€™, ā€˜C:/Users/T1280675/PycharmProjects/Python_Code/ss.pngā€™,{ā€˜x_offsetā€™:0, ā€˜y_offsetā€™:0,ā€˜x_scaleā€™: x_scale, ā€˜y_scaleā€™: y_scale})
ws.insert_image(ā€˜H1ā€™, ā€˜C:/Users/T1280675/PycharmProjects/Python_Code/ss2.pngā€™,{ā€˜x_offsetā€™:25, ā€˜y_offsetā€™:0,ā€˜x_scaleā€™: x_scale1, ā€˜y_scaleā€™: y_scale1})

#stringPath = ā€œC:\User\comp_logo.png\ā€
#stringPath1 = ā€œC:\User\offline_logo.png\ā€
#ws.insert_image(ā€˜A1ā€™, stringPath,{ā€˜x_offsetā€™:0, ā€˜y_offsetā€™:0,ā€˜x_scaleā€™: x_scale, ā€˜y_scaleā€™: y_scale})
#ws.insert_image(ā€˜H1ā€™, stringPath1,{ā€˜x_offsetā€™:25, ā€˜y_offsetā€™:0,ā€˜x_scaleā€™: x_scale1, ā€˜y_scaleā€™: y_scale1})

ws.set_column(ā€˜A1:H1ā€™, 50)
ws.set_column(ā€˜A2:H2ā€™, 30)
f0=wb.add_format({ā€˜boldā€™:True, ā€˜borderā€™:2, ā€˜border_colorā€™:ā€˜blackā€™,ā€˜bg_colorā€™:ā€˜#FFFFFFā€™, ā€˜font_sizeā€™:50,ā€˜alignā€™:ā€˜centerā€™})
f1=wb.add_format({ā€˜boldā€™:True, ā€˜borderā€™:2, ā€˜border_colorā€™:ā€˜blackā€™,ā€˜bg_colorā€™:ā€˜#C0C0C0ā€™, ā€˜font_sizeā€™:20,ā€˜alignā€™:ā€˜centerā€™})
f2=wb.add_format({ā€˜borderā€™:2, ā€˜border_colorā€™:ā€˜blackā€™,ā€˜bg_colorā€™:ā€˜#FAF5EFā€™,ā€˜font_sizeā€™:14,ā€˜alignā€™:ā€˜centerā€™})
head = [ā€˜History Alarmā€™]
headings = [ā€œScanned_DateTimeā€, ā€œFiche_Idā€, ā€œParent_Lengthā€, ā€œParent_Widthā€, ā€œVolumeā€,ā€œRack_Sideā€,ā€œStatusā€,ā€œScanned_Byā€]
data = [[ā€˜Janā€™, ā€˜Febā€™, ā€˜Marā€™, ā€˜Aprā€™, ā€˜Mayā€™, ā€˜Juneā€™],[10, 40, 50, 20, 10, 50],[30, 60, 70, 50, 40, 30],[40, 60, 70, 50, 40, 30],[50, 60, 70, 50, 40, 30],[60, 60, 70, 50, 40, 30],[70, 60, 70, 50, 40, 30],[80, 60, 70, 50, 40, 30],]

ws.write_row(ā€˜A1ā€™, head, f0)
ws.write_row(ā€˜A2ā€™, headings, f1)
ws.write_column(ā€˜A3ā€™, data[0],f2)
ws.write_column(ā€˜B3ā€™, data[1],f2)
ws.write_column(ā€˜C3ā€™, data[2],f2)
ws.write_column(ā€˜D3ā€™, data[3],f2)
ws.write_column(ā€˜E3ā€™, data[4],f2)
ws.write_column(ā€˜F3ā€™, data[5],f2)
ws.write_column(ā€˜G3ā€™, data[6],f2)
ws.write_column(ā€˜H3ā€™, data[7],f2)
wb.close()

comp_logo
offline_logo

use image

Please use the </> code formatting button when posting code. It will indent properly (important for Python) and give syntax highlighting. You can use the šŸ–‰ edit link to fix your post.

Here is his code properly formatted for the forum:

#print #event.source.startDate
from xlsxwriter import Workbook
#import getpass
#wb = xlsxwriter.Workbook(ā€˜hello.xlsxā€™)
path = system.file.saveFile('hello.xlsx')
wb = Workbook(path)
ws = wb.add_worksheet("Loading_Robot_info")
cell_format = wb.add_format({'align': 'center','valign': 'vcenter','border':2, 'border_color':'black', 'font_size':50,})
ws.merge_range('A1:H1', "", cell_format)
image_width = 50.0
image_height = 58.0
###############
image_width1 = 60.0
image_height1 = 110.0
###############
cell_width = 64.0
cell_height = 20.0
x_scale = cell_width/image_width
y_scale = cell_height/image_height

#######################
x_scale1 = cell_width/image_width1
y_scale1 = cell_height/image_height1
#######################
ws.insert_image('A1', 'C:/Users/T1280675/PycharmProjects/Python_Code/ss.png',{'x_offset':0, 'y_offset':0,'x_scale': x_scale, 'y_scale': y_scale})
ws.insert_image('H1', 'C:/Users/T1280675/PycharmProjects/Python_Code/ss2.png',{'x_offset':25, 'y_offset':0,'x_scale': x_scale1, 'y_scale': y_scale1})

#stringPath = ā€œC:\User\comp_logo.png\ā€
#stringPath1 = ā€œC:\User\offline_logo.png\ā€
#ws.insert_image(ā€˜A1ā€™, stringPath,{ā€˜x_offsetā€™:0, ā€˜y_offsetā€™:0,ā€˜x_scaleā€™: x_scale, ā€˜y_scaleā€™: y_scale})
#ws.insert_image(ā€˜H1ā€™, stringPath1,{ā€˜x_offsetā€™:25, ā€˜y_offsetā€™:0,ā€˜x_scaleā€™: x_scale1, ā€˜y_scaleā€™: y_scale1})

ws.set_column('A1:H1', 50)
ws.set_column('A2:H2', 30)
f0=wb.add_format({'bold':True, 'border':2, 'border_color':'black','bg_color':'#FFFFFF', 'font_size':50,'align':'center'})
f1=wb.add_format({'bold':True, 'border':2, 'border_color':'black','bg_color':'#C0C0C0', 'font_size':20,'align':'center'})
f2=wb.add_format({'border':2, 'border_color':'black','bg_color':'#FAF5EF','font_size':14,'align':'center'})
head = ['History Alarm']
headings = ["Scanned_DateTime", "Fiche_Id", "Parent_Length", "Parent_Width", "Volume","Rack_Side","Status","Scanned_By"]
data = [['Jan', 'Feb', 'Mar', 'Apr', 'May', 'June'],[10, 40, 50, 20, 10, 50],[30, 60, 70, 50, 40, 30],[40, 60, 70, 50, 40, 30],[50, 60, 70, 50, 40, 30],[60, 60, 70, 50, 40, 30],[70, 60, 70, 50, 40, 30],[80, 60, 70, 50, 40, 30],]

ws.write_row('A1', head, f0)
ws.write_row('A2', headings, f1)
ws.write_column('A3', data[0],f2)
ws.write_column('B3', data[1],f2)
ws.write_column('C3', data[2],f2)
ws.write_column('D3', data[3],f2)
ws.write_column('E3', data[4],f2)
ws.write_column('F3', data[5],f2)
ws.write_column('G3', data[6],f2)
ws.write_column('H3', data[7],f2)
#wb.close()

Thanks you

yes justin edwards

Hope you my question understand !

One thing that will have to be tackled here is that the images in Image management are stored on the gateway and so this will have to be done in the gateway scope. Unless you only have a single or only a handful of Vision clients and then you could locally put copies of these images on their machines but it would have to be in an identical path directory to make sure the client script works. I wouldnā€™t trust the clients to not move these around though so I donā€™t recommend this method.

I was just looking to see where the images of image management are stored but I canā€™t find them. However, you donā€™t really need them in image management to do this.

I think the following steps would be sufficient:

  1. Put the images you want somewhere on the server your gateway is on
  2. Create a gateway message handler. This is where you will run the script. The paths to the images are where you just put them on your gateway server.
  3. Append the following to your new gateway message handler script
filePath = "hello.xlsx" # or whatever the real path is - this surely can't be the full path
fileData = system.file.readFileAsBytes(filePath) # This gets the file data
project="YourProjectNameHere"
# It's important that both Gateway and Client versions of this message handler have been created
messageHandler="FileCreated"
scope="C"
myDict = {'fileData': fileData}
results=system.util.sendMessage(project,messageHandler,myDict,scope) # This sends the file data to the client directly
  1. Create a client message handler called FileCreated (or whatever you want but what you call it should match messageHandler="FileCreated"). This message handler will get triggered when the gateway sends the file data to your client. So here you probably want something like
fileData = payload['fileData'] # This is the file bytes that the gateway sent back to the client after making the file
path = system.file.saveFile("myFile.xlsx") # allows client user to select path where they want to save the file
if path is not None:
   system.file.writeFile(path, fileData)

So the whole sequence of events here is the client does something, a button press or similar (I am assuming is triggered by a client for this example), tells the Gateway hey make this XLSX file, the Gateway, which has access to these images (so the clients donā€™t need them), creates your XLSX file, and then sends that file data back to the client, who can then save it where they want.

The last thing you would need to change in your script would be

ws.insert_image(ā€˜A1ā€™, ā€˜C:/Users/T1280675/PycharmProjects/Python_Code/ss.pngā€™,{ā€˜x_offsetā€™:0, ā€˜y_offsetā€™:0,ā€˜x_scaleā€™: x_scale, ā€˜y_scaleā€™: y_scale})
ws.insert_image(ā€˜H1ā€™, ā€˜C:/Users/T1280675/PycharmProjects/Python_Code/ss2.pngā€™,{ā€˜x_offsetā€™:25, ā€˜y_offsetā€™:0,ā€˜x_scaleā€™: x_scale1, ā€˜y_scaleā€™: y_scale1})

To point to where the images are located on your Gateway server.

1 Like

They are stored in the gateway's internal database as blobs, IIRC.

2 Likes

I thought that might be the case. Probably easier than to do what he needs with them if he just leaves them as images on his gateway server in some folder as it seems his script expects a path to the images.

1 Like