Inkscape.org
  1. #1
    saucewaffle saucewaffle @saucewaffle

    Hi!

    What's the proper approach to making a copy of a path and offsetting it with the inset/outset tools via Python? For the end result, I'm looking to keep the original path, but add an offset copy. 

    I can't decipher the documentation to figure out the standard approach to making copies of paths, and it looks like the only way to access the inset/outset methods is by making a new Inkscape instance through `inkscape_command` with the `SelectionOffset` verb.

    How would the copy be made? And is there a more efficient way of doing the offset? How would the copy be merged back into the original?

    Thanks!

  2. #2
    Martin Owens Martin Owens @doctormo🌹🧀
    *

    To make a copy, you can use path_element.copy() but for offsetting, I don't believe we have any python code to do that yet. You'd have to call back to Inkscape to do it for you. (And that code's not great either, but that's another story)

  3. #3
    saucewaffle saucewaffle @saucewaffle

    Thanks for the quick reply! Is this the copy() function you're referring to? https://inkscape.gitlab.io/extensions/documentation/inkex.html#inkex.paths.Path.copy The docs just say "Make a copy" and the source just does a deep copy of itself. Presumably I'll need to inject the copy into the SVG somehow? (Is there a working example of this somewhere?)

    For the offset, yes the code seems a bit clunky, but I've not been able to find a better implementation. Trying to make due with what I've got... Say I need to make 1000 offsets, would I need to create 1k instances of Inkscape through inkscape_command? Is there a way to batch process this in a single instance?

    Thanks again for the help!

  4. #4
    Martin Owens Martin Owens @doctormo🌹🧀

    No I think you need Element copy (or duplicate) see the code here: https://gitlab.com/inkscape/extensions/-/blob/master/inkex/elements/_base.py#L352 For some reason the elements module is empty in the docs you linked to.

    I don't believe there's a way to batch process it, unless the objects are all in the same document. It's all furiously clunky, but we're moving slowly to a better world.

    Jam tomorrow!