Inkscape.org
Creating New Extensions How to clear node selection?
  1. #1
    chris371 chris371 @chris371

    Hi all,

    I'm writing an effect extension using phython3, inkex and Inkscape v1.0.2. Reading through this forum already helped me a lot, thanks for that!

    My extension is expected to be called with some nodes of a path being selected. The extension does some modifications to the path and its nodes, create some more objects, and finally groups all that together in a new group. All this works already: the new group is there and contains the objects just like I wanted. The only bad thing is that after the execution of the extension, the original selection of the individual nodes is still there. I'd like to change this at the very end of my code by calling:

    self.svg.set_selected(group)

    ...but sadly, this does not seem to have any effect. Most probably, because inkscape still thinks that some individual nodes from the original path are selected.

    Is there a way to make inkscape forget about the selected nodes from inside an extension?

    Thanks & best regards.

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

    Hi Chris,

    Inkscape doesn't have an API for changing it's selection (node or element) after an extension is run. I made a patch last year that could do something like this, but it wasn't really refined enough to be accepted into Inkscape. So for now, the limitation is that Inkscape can't remember what was selected in a file, and can't send that information back to inkscape when run.

  3. #3
    chris371 chris371 @chris371

    Hi Martin,

    thanks for the information and your help!

    At least I found a workaround for just removing the entire selection: Instead of applying the changes to the originally selected path, I do all the modification stuff to a duplicate of it (elem.duplicate()) and delete the original one (elem.delete()). This way, Inkscape is not able to find the originally selected element in the modified svg any longer. And apparently, it clears the selection in this case. (I've just tried this and it seems to work)