Inkscape.org
Creating New Extensions Having trouble learning the 1.0 API
  1. #1
    Scott Pakin Scott Pakin @pakin

    I'm struggling with converting my Snap Object Points extension to the 1.0 API.  It's not a complicated extension.  It essentially just adjusts all of a path's control points and/or endpoints.  Pre-1.0, the extension iterated over simplepath.parsePath(d) (a path's d attribute), appending [command, new_arguments] pairs to a list, and finally invoking simplepath.formatPath on the list.  What's the nearest equivalent of that pattern using the 1.0 API?  For convenience, I'd prefer the arguments to be in absolute, non-shorthand form.

    Thanks,
    — Scott

  2. #2
    Scott Pakin Scott Pakin @pakin

    As follow-up, I managed to find something that works, but I don't know if it's the best approach.  My code loops over each path node in self.svg.selection.filter(inkex.PathElement).values(), invokes path.to_absolute() on each node to convert to absolute coordinates, and iterates over each path command in the result.  The key is then to create a new path command with cmd.__class__(*new_args), which the code appends to a new-path list.  At the end of the node loop, the code replaces the path by assigning the new-path list to node.path.

    Does that sound reasonable?  The invocation of cmd.__class__(*new_args) feels a bit sloppy to me, but I haven't yet found an alternative that works across inkex.paths types.

Inkscape Inkscape.org Inkscape Forum Creating New Extensions Having trouble learning the 1.0 API