Getting started with scripting Synfig

A place to share and discuss your python scripts (only since 0.64.0 version)
User avatar
cameralibre
Posts: 31
Joined: Thu Aug 07, 2014 10:02 am

Getting started with scripting Synfig

Postby cameralibre » Wed Dec 14, 2016 12:16 pm

Hello, I somewhat of a beginner when it comes to programming, but I'm very happy using the command line, and have some basic understanding of python and bash scripting.

I would like to learn to write python scripts to edit/replace elements within a .sif file, for example to change all instances of a colour to something different, replace multiple strings of text with others, and various other things.

Is there a tutorial or some documentation available to help me get started?
I couldn't find anything in the manual. I have been looking into XML parsing with Python (beginner tutorials etc) but the structure of synfig files seems to make it a little more complicated.

Any suggestions?
http://www.cameralibre.cc
Free Culture videos made with Free/Libre/Open Source Software about Open Hardware, Open Data, Open Everything

Advertisement

User avatar
darkspace65
Posts: 551
Joined: Mon Feb 25, 2013 6:22 pm
Location: Belgium, Flanders.

Re: Getting started with scripting Synfig

Postby darkspace65 » Fri Dec 16, 2016 4:16 pm

Hi!
You can do a lot of exciting stuff with scripting, but it requires some knowledge of Python 3, and of python xml parsing like ET and PyQt4 for GUI integration AND a lot of patience going thru the sif files and learn their layout. My advice is to start small. Make a sif scene with one shape, like a circle and try to change its color or size, etc...
Greetz!

User avatar
caryoscelus
Posts: 79
Joined: Wed Nov 11, 2015 9:10 am
Contact:

Re: Getting started with scripting Synfig

Postby caryoscelus » Mon Dec 19, 2016 4:53 pm

First of all, it's usually best to not resort to scripting when the task can be accomplished using value nodes. E.g. instead of replacing all colours, better idea is to "export" colour and connect all instances to that node. Then changing colour in one place will result in changing everywhere.

User avatar
BobSynfig
Posts: 224
Joined: Sat Aug 15, 2015 6:08 am

Re: Getting started with scripting Synfig

Postby BobSynfig » Mon Dec 19, 2016 10:05 pm

Synfig files format is changing quite often and is not consistent.
The plugin system is "offline" and is only working by tricks ;)
Always check Wiki/FAQ first! - Use last builds (Stable 1.2.0/Dev 1.3.3), avoid older versions!
Official Synfig Training Course - Buttons too big in Linux? - Google Translate may help

User avatar
darkspace65
Posts: 551
Joined: Mon Feb 25, 2013 6:22 pm
Location: Belgium, Flanders.

Re: Getting started with scripting Synfig

Postby darkspace65 » Thu Dec 22, 2016 2:58 am

Hi!
I sometimes find juggling with value nodes more time consuming and more difficult then scripting, although I use my own character maker template that is based on juggling with value nodes, but of course the color example was just a simple example and my way of saying that you have to understand the layout of sif file first before you start messing with it and you can do that by analyzing simple and small files first. I usually use self made scripts to import stuff that synfig normally does not allow me to import such as fully rigged characters with skeletons without the need that the original file has to stay open and multiple particle layers based on Genete's particles template, just to name two. That does not necessarily mean I use an intern python script. It also works with for example with an extern perl script.
Greetz!

User avatar
cameralibre
Posts: 31
Joined: Thu Aug 07, 2014 10:02 am

Re: Getting started with scripting Synfig

Postby cameralibre » Fri Dec 23, 2016 8:47 am

Thanks for all your responses!

To give you an idea of my use case, I'm adapting a synfig animation for many different websites and languages and I eventually want people to be able to make basic changes (text, colour etc) without needing my intervention, and without having to know anything about animation or synfig, and without having to install software on their own computer. That is, they can do all these things, but they don't have to.

I would like to get into python as it seems like it will be more useful and flexible for me in the long term than bash alone, as its also useful for blender and krita, and if there's already some kind of setup for python scripting in synfig, then great!


The current state of experimentation:
So far, I have been doing very simple experiments with bash scripts - see this folder. I am new to this so don't judge my clumsy scripting too harshly ;)

The script 'honkforreform-Client' is run by the user, and sends their translation of the words 'HONK FOR REFORM' to the server where hupen.sif sits, with synfig and ffmpeg installed. On the server, the 'honkforreform-Server' script creates a copy of hupen.sif, changes the words, renders a PNG sequence, wraps the PNGs into a video file, and deletes the PNGS. (I didn't use the synfig ffmpeg export option because I want the possibility of having an alpha channel sometimes, and this was the only way that I could get a video+alpha out of synfig).

honkforreform-Client
then secure copies the completed video file from the server to the user's machine.

I don't really know what I'm doing, so any constructive suggestions would be great!


Exported Value Nodes
caryoscelus, just for clarification on your suggestion:
To adapt the video to work with (for example) an 8-colour palette, I would create 8 exported value nodes, one for each colour, and then link every object in the animation to the most appropriate of those nodes for that object.
Then for a different version of the animation, I would simply need to change the colour of Colour A, Colour B, etc, and the entire animation would be updated. Right?
That sounds like it will work a lot better and more flexibly than my current method, which is to use sed to replace existing RGB values with new values.


Colour (somewhat related)
Two things I can't work out about colour in synfig are
a) why synfig's hex codes are completely different to browsers, inkscape, and everything else,
and b) how should I best take a hex code and convert it to the RGB values seen within a .sif file?

Any ideas?
http://www.cameralibre.cc
Free Culture videos made with Free/Libre/Open Source Software about Open Hardware, Open Data, Open Everything

User avatar
caryoscelus
Posts: 79
Joined: Wed Nov 11, 2015 9:10 am
Contact:

Re: Getting started with scripting Synfig

Postby caryoscelus » Fri Dec 23, 2016 9:37 am

Then for a different version of the animation, I would simply need to change the colour of Colour A, Colour B, etc, and the entire animation would be updated. Right?


Yeah, that's correct.

a) why synfig's hex codes are completely different to browsers, inkscape, and everything else


Hmm, you mean those on "rgb" tab? I never noticed them cause i use "hsv". That's weird really. Probably a bug. But then the whole colour dialogue should be rewritten. For now you can use hexcodes from hsv tab.

b) how should I best take a hex code and convert it to the RGB values seen within a .sif file?


Needs inspecting source, i guess. I'd think it should be as simple as dividing by 0xff, but apparently not.


Return to “Scripting”

Who is online

Users browsing this forum: No registered users and 2 guests