Align origin to centre of region/group

I’ve imported a drawing of cogs from inkscape to synfig. I want to animate them rotating, however I’ve noticed that origin is set to the centre of the canvas, which means that when I rotate them they’re rotating off-centre.

Peek 2021-01-27 20-51

To get them rotating about their centre I’d need to put the origin into the exact centre, as illustrated below:

Screenshot from 2021-01-27 21-09-32

I can move the origin to the centre but moving it manually isn’t accurate and they’re still off-centre by a bit.

Peek 2021-01-27 20-52

Is there a way to automatically align the origin to the centre of the region/group?

image While creating circles just keep this property checked.

That option only appears when creating objects in Synfig, not on objects imported from svg files.

I’ve included an updated version of the example file. As specified in the original post I want the origin of each object to be in the exact centre of each object. I tried importing into Synfig via the import menu and by saving it as an .sif file from Inkscape and got the same result each time.

cogs

Using the Origin parameter and setting it value to reflect the coordinates found in Inkskape?
Or using a Group layer and/or Translate Layer?

I tried your suggestions on both synfig 1.4.0 and I compiled it myself a couple of days ago.

The first issue is that synfig’s coordinates system has 0,0 in the centre of the screen (with no way to change it) and Inkscape’s 0,0 is either top left or bottom left. So I had to do a bit of maths to convert them. For the top-left cog the centre is approximately located at -288.5px, 277.5px

Clicking on the cog region layer itself and changing the origin coordinates will change it but it’ll move the cog as well. I can’t move just the origin and not have it move the cog. I can highlight the cog’s node and attempt to move them manually but this isn’t accurate.

Peek 2021-01-28 21-15

I put the cog region layer into a group and it immediately made the origin go to the centre of the screen.

Screenshot from 2021-01-28 21-20-17

The group layer has an offset node I can move and attempt to get it into the middle of the cog but, again, this is inaccurate, and given how many decimal places are in the parameter editor getting the value to exactly -288.5, 277.5 just by clicking and dragging will be near impossible!

Still on the group layer if I try entering those values manually it moves the cog. I tried entering the values directly into the Origin and Offset parameters and both times it moved the the cog.

I tried your final suggestion of using a Translate layer and changing the origin parameter either by clicking and dragging or entering it manually just resulting the the cog moving.

Unless I’m missing something really obvious I can’t see a way to get the origin of an imported shape to its centre accurately.

If someone knows how to do this and is able to do a screen recording I’d really appreciate it!

As a work around, I’ll suggest you use grids and grid snap features.

Here’s a solution for finding the centre of an object which uses inkscape in combination with synfig. I will be using this vector file.

cogs

If you’ve already prepared your scene in another program e.g. inkscape this becomes easier. If not then you’re on your own! Make sure you have your units in Synfig set to px (probably can be done using synfig’s units but I’m not going to work that out).

In inkscape turn on “Snapping centres of bounding boxes”. Draw guides on the x and y axis and snap them to the centre of the object. Double-click on the guide and it’ll tell you the x/y position of the centre of the object (332.296,332.708px).

Screenshot from 2021-01-29 16-25-25

Write this down somewhere, but also note that inkscape’s 0,0 point is at the top-left of the screen. Now save it as an .sif file from Inkscape.

In Synfig first put your cog in a group layer. We can’t type in new origin values without it moving the whole group so we’ll use guides, enable snapping to guides, and then move the origin handle the grid point.

Synfig’s 0,0 point is at the centre of the screen, so we need convert the x/y placement of the guides in inkscape to match the coordinates system of Synfig. I don’t know if there’s an automated way of doing this so I did it manually by drawing guides in Inkscape to get the centre of the document and measuring the distance from them to the cog’s centre.

The updated guide positions for Synfig are at -119.38x200.08px. However, even though my units in Synfig are set to px the guides are still set to be in units. See here for more details: https://wiki.synfig.org/Canvas_MetaData_Panel . 1 unit = (image width in pixels)/(image area width) (see here for more details https://wiki.synfig.org/Unit_System). The document is 903x1065 and has an image area from -7.52689 - 7.52689, so 1 unit is 903/15.05378 = 59.984934017 .

With that info we can find out where to place our guides! The x guide should be at 200.08/59.984934017 = 3.334666667 and the y guide at -119.381÷59.984934017 = -1.989683333.

With the guides now showing where the middle of the cog is I should be able to drag the origin offset handle (the light purple handle) to the guides and it’ll snap to them. Well, yes and no. The origin offset handle itself will snap to the guides but of course the one we want to snap is the position handle itself (the green one). However if it is moved the whole group, objects and all, are moved.

Screenshot from 2021-01-29 17-43-16

I remember that in earlier versions of synfig I could hold Ctrl and click on the position handle to move it but I think the offset handle/light purple dot has replaced it(?).

So, I can now use this quite long method to get the centre of an object. I’d just have to repeat this for every object that I wanted to find the centre of…

Here’s my file if you want to try yourself

cogs_compressed.sifz (121.7 KB)

1 Like

Of course this solution doesn’t scale well at all. I’ve read the relevant documentation and ave tried lots of different things but it just seems this isn’t possible. Really happy to be proven wrong. Post a tutorial if you can!

In the meantime I’ve created a bug report here https://github.com/synfig/synfig/issues/2005 . This align & distribute report also seems very relevant https://github.com/synfig/synfig/issues/1704

Why not create a plugin so that it gets all the information from the .sif file and then center the origin.
It seems there is a property to change the origin, it only moves the object.

One approach would be to move the vertices such that the origin becomes center of the object and then move the whole object back to the position where it belongs.

Here a visual representation for what I want to say


(Just for representation)

I would like to work on a feature like this, I have programming experience but not in C++, that’s why I want to create a plugin using python. I will start working on it soon.

1 Like

I have created a python script that will do what I have previously explained.

Set the orgin to center.zip (1.3 KB)

Here is explanation of how the code works.
Gets the vertexes of the a region (only works for region), finds the highest and lowest point for x axis and y axis.

And then considering a imaginary rectangle with highest and lowest point of x and y axis. Finds the mid point of the diagonal. And this it will be our original center what user is expecting.

After finding the original center all the vertices are it will calculate the distance from origin (which is green dot in Synfig, mostly hooked at 0,0).

The distance will be used to move all the vertices according to the origin (look at previous post for visual explanation).

After this step the origin will be placed back to the original center(what user expects).

I need some information about GUID in Synfig and how they works.

:slightly_smiling_face:I would be thankful for any help

1 Like

Here a final script that will work for all layer which will have bline and origin. (Still need to implement for Group)

Set the orgin to center.zip (3.8 KB)

If you face any issues then tell me and we will solve it.

@hellocatfood

Here’s a plugin which might help you,

It will center the origin and also now works for group layers. Your detailed information about every reply to this thread was helpful for creating the plugin hope it helps you.

2 Likes

I know it’s too much to ask, but if you can create a plugin to select all the outline and advance outline layers at once in a composition, it would be of an immense help. I’ve got no programming background, so i really can’t do it myself. So, i wonder if you can help.

Thanks so much for making this plugin. I haven’t used Synfig since I originally faced this problem but if I use it again this will be very useful.

Is there any chance you could upload this to github? I’d like to link it to this bug report/feature request Align origin to centre of layer/group · Issue #2005 · synfig/synfig · GitHub and a good place to report bugs in the plugin too.

Thanks again!