store captured image as variable into a py file

Asked by Ben Dix on 2021-05-18

Hey Folks,

capture() works fine with the "_" in front of the name. I've seen in another post this happens to be sure, it will not bei deleted in further progress.

I am trying to achieve a few captures by executing a sikuli script and I want the captured images of every region be stored as individual variables at the end of another existing python file...

Still searching for the way to achieve this and also remove the "_" of the png name.
Even if this is a general python case, I would appreciate your help, maybe you have an idea.

thx for reading!

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Ben Dix
Solved:
Last query:
Last reply:
Revision history for this message
Ben Dix (bendix80) said :
#1

yeah, I got it how to rename the file 😄

fyi

import os

a = "name"
capture(Region(99,90,133,119),a)

os.rename(r'/Users/MYNAME/Desktop/Sikulix/scripts/AAANewScripts/screen_capture_test.sikuli/_' + str(a) + '.png',r'/Users/MYNAME/Desktop/Sikulix/scripts/AAANewScripts/screen_capture_test.sikuli/'+ str(a) + '.png')

first I failed using shortcuts, but now I think I get it 😄

here_it_is = (getBundlePath() + '/')
print(here_it_is)
os.rename(r'' + str(here_it_is) + '_' + str(a) + '.png',r'' + str(here_it_is) + str(a) + '.png')

so looks like this question is solved, still looking for the way to write the image with its name as variable at the end of an existing py file 😄

Revision history for this message
RaiMan (raimund-hocke) said :
#2

Uuuups, why so complicated:

img = "_someName.png"
capture(someRegion, img)

and you have your variable to do with it, whatever your want:

imgFilename = os.path.join(getBundlePath(), img)

a statement:
line = 'variable = "%s"' % imgFilename

... and now you could append this line to an images.py file using the normal File-I/O

in turn you now can import this images.py using
from images.py import *

and you have your variable names available (even with absolute filenames, so no imagepath needed)

... now the _ takes care, that your images are never deleted.

Revision history for this message
Ben Dix (bendix80) said :
#3

Thx RainMan 👍😉