Welcome, Guest
Python Scripts for ComicRack
  • Page:
  • 1
  • 2

TOPIC: Help with first script

Help with first script 8 years 3 months ago #3931

  • wonderboy
  • wonderboy's Avatar
  • Offline
  • Fresh Boarder
  • Posts: 6
  • Karma: 0
I am trying to create a script that will mark pages 1,3,&4 as Deleted on a large group of comic book files. I have the script working on one file at a time, but I would like to make it work on a group in sequence. Here is the script that I am using:

import clr

clr.AddReferenceByPartialName('ComicRack.Engine')
from cYo.Projects.ComicRack.Engine import ComicPageType

def GitCorpCleanup(books):
for book in books:
book.UpdatePageType(0,ComicPageType.Deleted)
book.UpdatePageType(1,ComicPageType.FrontCover)
book.UpdatePageType(2,ComicPageType.Deleted)
book.UpdatePageType(3,ComicPageType.Deleted)
return

Any help that can be provided would be really appreciated.
The administrator has disabled public write access.

Re:Help with first script 8 years 3 months ago #3933

  • perezmu
  • perezmu's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 1114
  • Thank you received: 64
  • Karma: 51
Hi, maybe this is stupid, but the only thing I can think of is that you are not "hooking" it to books correctly in the xml file... this is the code from one of my scripts:
  <Command xsi:type="PythonCommand" Hook="Books" Key="SaveTagsToNotes">
    <Name>Toolbox : Save Tags to Notes...</Name>
    <Method>SaveTagsToNotes</Method>
    <ScriptFile>SaveTagsToNotes.py</ScriptFile>
  </Command>
The administrator has disabled public write access.

Re:Help with first script 8 years 3 months ago #3935

  • wonderboy
  • wonderboy's Avatar
  • Offline
  • Fresh Boarder
  • Posts: 6
  • Karma: 0
Here is my xml code:

<Command xsi:type="PythonCommand" Hook="Books" Key ="GitCorpCleanup">
<Name>Git Corp Cleanup</Name>
<Method>GitCorpCleanup</Method>
<ScriptFile>GitCorpCleanup.py</ScriptFile>
</Command>

</ArrayOfCommand>

It appears to be in the same format as your example.
The administrator has disabled public write access.

Re:Help with first script 8 years 3 months ago #3936

  • perezmu
  • perezmu's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 1114
  • Thank you received: 64
  • Karma: 51
Yeah, that seems to be ok...

Maybe I did not understand your question, because I think the code you are using should work on ALL SELECTED comics...
The administrator has disabled public write access.

Re:Help with first script 8 years 3 months ago #3937

  • wonderboy
  • wonderboy's Avatar
  • Offline
  • Fresh Boarder
  • Posts: 6
  • Karma: 0
Thanks for the feedback Perezmu. Unfortunately the script only works on one of the selected comics regardless of how many comics are selected.
The administrator has disabled public write access.

Re:Help with first script 8 years 3 months ago #3938

  • perezmu
  • perezmu's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 1114
  • Thank you received: 64
  • Karma: 51
It works for me!

I just copied/pasted your code and it works... Maybe it is working and you are not seeing it: ComicRack may be lazy updating the thumbnails in the comics, and also, to make these changes permanent you may need to "update e-comics". To make sure it is working you may want to go to the "pages" view and set the "Pages Filter" in that view not to show the pages marked as deleted!
The administrator has disabled public write access.

Re:Help with first script 8 years 3 months ago #3939

  • perezmu
  • perezmu's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 1114
  • Thank you received: 64
  • Karma: 51
Forgot the file :P

File Attachment:

File Name: perezmu.zip
File Size:1 KB
The administrator has disabled public write access.

Re:Help with first script 8 years 3 months ago #3940

  • wonderboy
  • wonderboy's Avatar
  • Offline
  • Fresh Boarder
  • Posts: 6
  • Karma: 0
Thanks, I'll revisit the script when I get back home tonight.
The administrator has disabled public write access.

Re:Help with first script 8 years 3 months ago #3947

  • wonderboy
  • wonderboy's Avatar
  • Offline
  • Fresh Boarder
  • Posts: 6
  • Karma: 0
Well, I don't know what was different in your version Perezmu, but it worked where mine didn't. I will have to compare them line by line to see if I had some extraneous code hidden somewhere. Thanks a bunch for the help. Plus 1 to your Karma seems so inadequate!
Last Edit: 8 years 3 months ago by wonderboy.
The administrator has disabled public write access.

Re:Help with first script 8 years 3 months ago #3949

  • perezmu
  • perezmu's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 1114
  • Thank you received: 64
  • Karma: 51
It might be the indentation? It is the only difference I find... but I thought the python interpreter would complain about it:

Your code:
def GitCorpCleanup(books):
for book in books:
book.UpdatePageType(0,ComicPageType.Deleted)
book.UpdatePageType(1,ComicPageType.FrontCover)
book.UpdatePageType(2,ComicPageType.Deleted)
book.UpdatePageType(3,ComicPageType.Deleted)
return 

My code:
def GitCorpCleanup(books):
for book in books:
    book.UpdatePageType(0,ComicPageType.Deleted)
    book.UpdatePageType(1,ComicPageType.FrontCover)
    book.UpdatePageType(2,ComicPageType.Deleted)
    book.UpdatePageType(3,ComicPageType.Deleted)
return

Indentation is part of the syntax in python, it is not optional (here spaces, in the code it should be a tab)... if you don't indent the for-loop, then your instructions are out of the loop and only take effect on the last book in the loop... I did not mention this before because (a) I thought you were aware of this and your code was not indented in your post because of copying/pasting issues and (b) I would expect python to complain when finding an empty loop...

This is the only explanation I can find!

Enjoy!
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Time to create page: 0.430 seconds

Who's Online

We have 203 guests and 5 members online