how to generate sequential numbers as my script saves screen grabs

Asked by grey grey

Thanks to all you genius developers!
is there a tutorial or some instructions demonstrating how to get sikuli to generate sequential page numbers as it captures screen grabs of a multi page doc.? I am sure this is a task that has been programmed thousands of times somewhere, just not at my house! I have the program doing many tasks very well, I just dont know how to tell it to ...for instance, take the last page number I had it save a doc page as,.,...take that number and increase it by one, and insert it into the code for the next page.

also, how can I get it to loop and keep doing this for a few hundred repetitions?

thanks, GG

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Since I do not know, where you want to put your page number, this is a skeleton

current = 10 # last used page number
max = 15

while current < max:
    current += 1 # next page number
    print "Current page number:", current
    currentText = "- %d -"%(current) # a formatted text version
    print "Formatted current page number:", currentText
    # coding follows, that might use current/currentText
    if endCondition: break # end loop, if some endCondition is met

Revision history for this message
grey grey (greyg100) said :
#2

Hi, thanks for your answer, but I have no idea what you are explaining. I am not a programmer, think of me as a 6 year old.

below is a 23 line sikuli thing....it will work for my purpose ...if this can be looped with an escape after about 400 times...and if you can show me how to make the "001" and "002" change in sequence ...003,004,005 etc........... this would be great. I am sure you know that the stuff in ( ) are all screen grabs on my sikuli java thing on my comp.

Thanks again, GG

click("READING-5.png")
click("1330391579704-3.png")
click("new-2.png")
wait(1)
dragDrop("READING-5.png", "1330385440306-2.png")
click("IIDDIS-2.png")
wait(1)
doubleClick("Filename-2.png")
type("001")
click("Cancel-2.png")
wait(1)
doubleClick("1330388006782-2.png")
click("1330388368635-2.png")
click("new-2.png")
wait(1)
dragDrop("READING-5.png", "1330385440306-2.png")
click("IIDDIS-2.png")
wait(1)
doubleClick("Filename-2.png")
type("002")
click("Cancel-2.png")
wait(1)
doubleClick("1330388006782-2.png")

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

trying hard ;-) to identify the code block, that should be repeated, I suggest the following:

click("READING-5.png")
for pnum in range(1,400): # see comment
    click("1330391579704-3.png")
    click("new-2.png")
    wait(1)
    dragDrop("READING-5.png", "1330385440306-2.png")
    click("IIDDIS-2.png")
    wait(1)
    doubleClick("Filename-2.png")
    type("%03d"%pnum)
    click("Cancel-2.png")
    wait(1)
    doubleClick("1330388006782-2.png")

--- comment: when testing, you should put 3 or 4 instead of 400

After copying it to the IDE (you need to copy it into your current script and delete the old stuff, so the pictures are found), take care, that the indentation (blanks at the beginning of the line following the line "for ....")

If you get any indentation errors, look faq 1800

BTW: Seems to be on a Mac. Might be, that there are easier ways to accomplish your target. If you want to know, talk about it in detail, what you are clicking and dragging there.

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

Forgot to mention:
The above loop starts with 1 and counts to the given second value -1 (in this case 399)

Revision history for this message
grey grey (greyg100) said :
#5

hi, thanks ...I seem to not quite get your help...

the whole 23 lines I sent you is supposed to run and then all 23 repeat. What I have the script doing is this

clicking to the next page in an adobe reader, it then uses the windows 7 screen capture(it is a Dell by the way) it saves the screen cap, numbers it(193) , then clicks to scroll to the bottom of the page( I have it showing in large type so it takes 2 screen caps ...top and bottom to get the whole of one page...then it screen caps this bottom part then saves this, numbers it (194) closes the screen cap window...this is the end of one whole loop(that is if you can help me make it loop)

thanks,, GG

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

ok, thanks for the info.

Then put the following line in the first line of your script (this counts from 1 and steps by 2):

for pnum in range(1, 400, 2):

then select all your current script lines below this first line and press tab (this indents your code one level, to make it the body of the loop).

the first type statement has to be:
    type("%03d"%pnum)

and the second type statement has to be:
    type("%03d"%(pnum+1))

All the other comments above (#3, #4) still apply.

Revision history for this message
grey grey (greyg100) said :
#7

Once again, many thanks!,

I have done as you described and it now works perfectly.

here is a slightly different question.

Since I am, as I described before, scanning and capturing 2 times for each page of text(top and bottom of page) it would be great if you could help me with a more accurate way of numbering....something like ...when I capture the top of page 37 the script names it 37 and then the next capture being the bottom of page 37, the script names it 37a. Then upon repeat of the loop it calls the next capture 38(since the actual page being captured is number 38), then the next is 38a...I am sure you can explain this to me, but I have tried a few variations on the working loop you helped me fix, but I cant figure it out....like I said, I am no programmer.

thanks!

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

But I am sure, you will get at least a scripter, if you stay tuned with Sikuli and such kind of non trivial problems ;-)

--1. we reset the loop
to stepping 1 at a time:

for pnum in range(1, 200):

--2. the first type stays as it is

    type("%03d"%pnum)

--3. the second type becomes

    type(("%03d"%pnum)+"a")

Revision history for this message
grey grey (greyg100) said :
#9

Yes, Thank you very much.

can you point me toward a tutorial or something that will educate me so I can understand how to code this way on my own?

thanks, GG

Revision history for this message
RaiMan (raimund-hocke) said :
#10
Revision history for this message
grey grey (greyg100) said :
#11

Thanks for all your help.

GG