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:
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
Hello justin edwards
Requirement : Image read from image Management not in local directory
Please go through this code (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()
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:
- Put the images you want somewhere on the server your gateway is on
- 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.
- 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
- Create a client message handler called
FileCreated
(or whatever you want but what you call it should matchmessageHandler="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.
They are stored in the gateway's internal database as blobs, IIRC.
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.