Inkscape.org
Creating New Extensions Updating Selection after running extension
  1. #1
    OptimusPrime OptimusPrime @OptimusPrime
    *

    Hello all. I am beyond burn-out and have sunk days into this. I can't do it alone :(

    Inkscape 3.2, newest stable python release, libraries installed in python directory via pycharm. So i wanna create a very simple extension that selects a small number out of my entire selection. I have got it part-working, but soon as the extension closes, the selection still or again contains all objects i originally sent INTO the extension.

    I have a surface texture simulated in smal path objects, but i need to distribute them. So as not to select hundres by hand, i wanted the extension to just do the selection for me. Status: Ojects ARE being grayed out. A log file IS created and DOES contain valid ids - i verified those in the XML view inside inkscape. But, for some ungodly reason, neither clearing, setting nor filtering the selection does it. I noticed that in my

    Directory:
    C:\Program Files (User)\Python\Python312\Lib\site-packages\inkex
    ...there is a _selected.py, not a selection.py.

    Other than that, i'm just...spent...Code is fairly short...please, help... :(((

  2. #2
    inklinea inklinea @inklinea⛰️

    It can't be done.

    The selection list in the GUI cannot be changed via the extension system*

    The reason the selection list can be changed in the extension system, is to allow for reusable code I suppose.

    -----

    * it can be done via dbus from an extension, but it's quite complicated.

    The extension launches a subprocess with a slight delay which contains an id list and dbus code.

    The extension then returns and then the reselection takes place via the dbus subprocess.

    https://inkscape.org/~inklinea/%E2%98%85selection-plus

  3. #3
    OptimusPrime OptimusPrime @OptimusPrime

    Well...First, thank you! At least i know i didn't grossly overlook sth. Would it instead be possible to delete 80 radom % of the selection entirely?

    Alternatively...i can set the opacity for a subsection to ..20% or so, and leave the chosen paths alone. I think inkscape can filter for opacity...

  4. #4
    inklinea inklinea @inklinea⛰️

    Did the SelectionPlus extension work on your system ? 

    If so, it may be possible to use a couple of the files from that extension.

    That would enable you to send a list of ids to the extension code and it will select for you .

  5. #5
    OptimusPrime OptimusPrime @OptimusPrime

    I plan on trying that in a while. Right now, the opacity and filter option works good enough. I'll get back to you when I've tried! :)

  6. #6
    OptimusPrime OptimusPrime @OptimusPrime
    *

    @inklinea Okay, i installed your extension and tried to embed it in my own. It runs through clean but i failed to update the selection. Items are grayed out as before, and i can see that another instance of sth starts up and vanishes again. But after all is done, the selection is the same as the one i input.

    I'll attach the file here - maybe you could help tying it properly to your scripts? :)

  7. #7
    inklinea inklinea @inklinea⛰️

    I've attached a zipped example.

    It's just simpler to drop 1 file into your extension folder: ink_dbus.py

    Referencing external paths in python is a bit of headache.

    I've edited the code of your extension in a couple of places.

    I made an .inx to go with it ( my name is in the .inx, just ignore that, it's just to prevent id collisions if you have already chosen a name )

    **Please note:

    in the .py code, there are two lines and two functions: 

    # set_stdout(None, 'off')
    # set_stderr(None, 'off')

    These are important, they make the python error messages silent. 

    If you don't do that, when the user clicks the ok button after the message box pops up - the selection focus is lost !

    For testing if you scroll the canvas to the left first, you can still see the effects of the extension before you click okay.

    However - for normal use, uncomment the two lines so it can work normally.

    I have tested it on Ubuntu and Windows 11. Inkscape 1.4

  8. #8
    OptimusPrime OptimusPrime @OptimusPrime

    It's working!! I does exactly what i'd hoped! Thank you so so much. The need for this functionality kept me from working on my book for weeks. I didn't even attempt to manually do what i needed. I am beyond excited that i came so close, even found the dbus function you spoke of. That's so cool! Thank you for finishing it for me :) You helped me out SO much with this. You even built a proper GUI for it :D

    Many thanks. Have a wonderful evening :D

  9. #9
    OptimusPrime OptimusPrime @OptimusPrime

    Thought I was done huh? Well no. I just came back to share my current version of the extension. 

    1. It will now automatically enable error messages if svg parsing fails, warding against non-UTF-8 encoded Bytes. Otherwise messages stay off. 
    2. It also allows changing opacity of the random selection. 

     

    Many thanks for helping me. Hope you'll like the idea here and can maybe use it yourself. Best, Sky

Inkscape Inkscape.org Inkscape Forum Creating New Extensions Updating Selection after running extension