Using center of rotation in Python extension
Hi all,
How does one obtain the center of rotation of an object from within a Python script/extension? Is it perhaps a property of BaseElement (I don't see it mentioned here — https://inkscape.gitlab.io/inkscape/doxygen-extensions/classinkex_1_1element... )?
Best, Pieter
On Wed, 2018-10-24 at 15:23 +0200, Pieter Barendrecht wrote:
Hi all,
How does one obtain the center of rotation of an object from within a Python script/extension? Is it perhaps a property of BaseElement (I don't see it mentioned here — https://inkscape.gitlab.io/inkscape/doxygen-extensions/classinkex_1_1element... )?
We might not have implemented this feature yet.
Would you like to try and add it to the index/svg functionality? It would be useful to other extensions too.
Best Regards, Martin Owens
Hi Martin,
On Wed, 24 Oct 2018 at 19:42, <doctormo@...400...> wrote:
We might not have implemented this feature yet.
Would you like to try and add it to the index/svg functionality? It would be useful to other extensions too.
I'd be happy to take a look at it, but I'm not quite sure how to approach this. My use of C++ is usually restricted to programming graphical environments in Qt/OpenGL — there are a lot of C++ aspects I'm not familiar with.
Best, Pieter
I am assuming that you would like to do this in Python, not C++. There are some existing Python extensions in this general area. For example there is an extension that will calculate and display the center of mass. See the menu item Extensions->Visualize Path->Measure Path, and the file: share\extensions\measure.py
hth, Alvin
-- Sent from: http://inkscape.13.x6.nabble.com/Inkscape-Dev-f2781808.html
Hi Alvin,
Thanks for the suggestions, but I'm after the center of rotation, not the centroid of the object. Although they often coincide, the former can be changed by the user, whereas the latter can't.
Best, Pieter
On Fri, 26 Oct 2018 at 23:46, alvinpenner <penner@...1856...> wrote:
I am assuming that you would like to do this in Python, not C++. There are some existing Python extensions in this general area. For example there is an extension that will calculate and display the center of mass. See the menu item Extensions->Visualize Path->Measure Path, and the file: share\extensions\measure.py
hth, Alvin
-- Sent from: http://inkscape.13.x6.nabble.com/Inkscape-Dev-f2781808.html
Inkscape-devel mailing list Inkscape-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/inkscape-devel
so, do you mean that you wish to use Python code to find the value of these existing variables? The variables that you are probably looking for are: inkscape:transform-center-x inkscape:transform-center-y These are present in the svg file, so you should be able to find them in Python just by walking the tree and searching for these parameters. You might need to know the object ID in order to do this. The only problem I can see is that this variable has a default value that is not reported in the svg file when you first create the object. So you might need to duplicate in Python the code that is currently executed in C in order to define the original default value. This code is probably somewhere like the file 'sp-item.cpp' which appears to be defining the variable 'item->transform_center_x' which is probably what you would need to emulate.
hth, Alvin
-- Sent from: http://inkscape.13.x6.nabble.com/Inkscape-Dev-f2781808.html
Hi Alvin,
Indeed, those are the values I'm after. I should've opened the XML editor straight away :). Thanks!
Best, Pieter
On Mon, 29 Oct 2018 at 12:23, alvinpenner <penner@...1856...> wrote:
so, do you mean that you wish to use Python code to find the value of these existing variables? The variables that you are probably looking for are: inkscape:transform-center-x inkscape:transform-center-y These are present in the svg file, so you should be able to find them in Python just by walking the tree and searching for these parameters. You might need to know the object ID in order to do this. The only problem I can see is that this variable has a default value that is not reported in the svg file when you first create the object. So you might need to duplicate in Python the code that is currently executed in C in order to define the original default value. This code is probably somewhere like the file 'sp-item.cpp' which appears to be defining the variable 'item->transform_center_x' which is probably what you would need to emulate.
hth, Alvin
-- Sent from: http://inkscape.13.x6.nabble.com/Inkscape-Dev-f2781808.html
Inkscape-devel mailing list Inkscape-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/inkscape-devel
Note that inkscape:transform-center-x/y are relative *offsets* from the center in desktop coordinates. You still have to compute the center yourself. On Mon, Oct 29, 2018 at 1:39 PM Tavmjong Bah <tavmjong@...8...> wrote:
On Mon, 2018-10-29 at 13:21 +0100, Pieter Barendrecht wrote:
Hi Alvin,
Indeed, those are the values I'm after. I should've opened the XML editor straight away :). Thanks!
These values should eventually be replaced by the CSS property 'transform-origin'.
Inkscape-devel mailing list Inkscape-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/inkscape-devel
participants (5)
-
unknown@example.com
-
alvinpenner
-
Pieter Barendrecht
-
Tavmjong Bah
-
Thomas Holder