I’d like to use Krita for animating a sprite that has multiple animation clips (e.g. walk cycle, jump, etc.) for a game. Storyboards seem like the right tool for this, as I can specify the length of each clip as a storyboard scene. I can then easily render all of my frames, but it does not seem possible to export the storyboard data that defines which frames are associated with which clip (e.g. walk = frames 0-24, jump = frames 25-32, …).
PDF and SVG export are not helpful in this situation, I need some kind of raw data that can be processed as part of my asset pipeline. Maybe a CSV or other plaintext format would be appropriate.
I read through the Python API documentation to see if I could write a script that would do this, but I can’t seem to find the storyboard scene name and duration data anywhere in the API. Is it possible to access this data via Python? If so, can someone point me to which class exposes it?
On a semi-related note, it might be worth considering a “isolate scene” option in the storyboard scene context menu that would set the start and end frame numbers of the timeline to the corresponding start and end times of the selected scene. This would allow me to easily loop playback around a single scene without having to manually enter the frame numbers.
For that I would recommend you trying project pages instead. It fixes the document length automatically and the export acts on the entire project on all frames available. And since it acts on documents instead of the time line you can adjust the timing of any documents animation and export it after again without moving frames out of the way or needing to tag the section of animation.
There is no direct access via python api, so you have to use PyQt
from krita import *
qdock = next((w for w in Krita.instance().dockers() if w.objectName() == 'StoryboardDocker'), None)
wobj = qdock.findChild(QListView,'sceneView')
model = wobj.model()
for index in range(model.rowCount()):
pitem = model.index(index,0)
name_item = model.index(2,0,pitem)
dur_item = model.index(1,0,pitem)
print ( name_item.data(), dur_item.data() )
@KnowZero awesome, it works! Thank you! Not very intuitive for someone unfamiliar with PyQt to figure out that this is possible.
@KnowZero I was able to get this script running from kritarunner but Krita.instance().dockers() is an empty array when running in the kritarunner environment. Thus, I can’t automate this script by running it from the command line. Any ideas?
Krita Python Developer Tools gets you most of what you need for PyQT, only thing I haven’t added yet is a Model inspector which I planned to at one point but haven’t had the time.
I haven’t played around with kritarunner, so not sure how much of the GUI stuff is available there. You can try maybe the dockers from Krita.instance().activeWindow() but I can’t guarantee that will work
If not you may have to resort to alternative methods. Such methods include saving a copy of a kra file, then open it as a zip file and reading the xml
If you are trying to extract that data from non-modified kra files though, you don’t even need Kritarunner, you can access it via opening the KRA like a zip file and extact it directly
MUCH better and more straightforward to just parse the kra file as a zip! I’m new to Krita, so thank you for your help!
To any weary traveler who passes by looking to solve the same thing, here’s a working Makefile rule that exports the storyboard data to a plain text file. Requires xmlstarlet.
%.frames: %.kra
@mkdir -p $(@D)
# export storyboard data
@set -e ;\
DOCTITLE=$$(unzip -p $< documentinfo.xml | xmlstarlet fo -D | xmlstarlet sel -t -v '//_:about/_:title') ;\
FPS=$$(unzip -p $< $$DOCTITLE/animation/index.xml | xmlstarlet fo -D | xmlstarlet sel -t -v '//_:framerate/@value') ;\
unzip -p $< $$DOCTITLE/storyboard/index.xml | xmlstarlet fo -D | xmlstarlet sel -t -m '//_:storyboarditem' -v '@item-name' -o ' ' -v 'number(@frame)' -o ' ' -v "number(@duration-second) * $$FPS + number(@duration-frame)" -nl > $@
# export images
krita --export-sequence --export-filename $@.png $<