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.
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.
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'sd
attribute), appending [command, new_arguments] pairs to a list, and finally invokingsimplepath.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
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()
, invokespath.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 withcmd.__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 tonode.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 acrossinkex.paths
types.