Inkscape.org
Creating New Extensions Basic Operations in extension
  1. #1
    mapacarta mapacarta @mapacarta
    *

    Hello,

    I am trying to develop a simple extension for the things I do a lot. Basically I just need to read the width, height of the selected group object, change the dimensions, coordinates etc.

    I searched on internet, asked chatgpt :) but couldn't find how to do it yet. After talking with chatgpt something like an hour I was able to make it work kinda, it only works for rectangles :D I need to make it work on group objects. For example how can I change the x coordinate of a group object?

    elem.set('x', '100')

    this works for rectangle but not for group sadly. It would be good if you can direct me to a documentation or something like that.

    Note: I am using inkscape 1.1 but I can upgrade to final version if necessary

  2. #2
    mapacarta mapacarta @mapacarta

    After a lot of tries I was able to center it but the image is upside down :D Here is the code I used

    new_transform = f'translate({new_x},{new_y}) scale({factor},{factor})'
    group.set("transform", str(new_transform))

    if I give -factor to scaleY, then the translationY doesn't work as expected. It is soooo weird that I and chatgpt couldn't find a proper way to change just the x coordinate without affecting scale :/

  3. #3
    mapacarta mapacarta @mapacarta

    Thanks, after spending many hours on this, I am kind of made it work. I used the transform matrix, it calculates correctly most of the time but flips the images. I flip them back in the editor, set the location if it is wrong. After all it speeds me up, so it worth the effort :)

  4. #4
    inklinea inklinea @inklinea⛰️

    If you are doing this in an extension, maybe look at this page:

    https://inkscape.gitlab.io/extensions/documentation/source/inkex.transforms.html

    add_scale, add_rotate, add_matrix  etc.