Inkscape.org
Beyond the Basics Defining an Incrementing Object Properties ID when Duplicating or Copying/Pasting
  1. #1
    Ed Ed @eneuman93

    Hello!

    Is it possible to pre-define the object properties ID's when creating new paths?

    For example, if I want to create many circles, is it possible that new circles be defined as +1 than the one it was copied/duplicated from? Like if the first circle has an ID of "Circle 1" and you copy/paste it, the second circle will automatically be named "Circle 2"? 

    Thank you in advance for any help.

  2. #2
    inklinea inklinea @inklinea⛰️

    It's very easy using an extension, but not a feature which exists in Inkscape Itself.

  3. #3
    Ed Ed @eneuman93

    @inklinea Do you have a link to any tutorials using a free extension? Thanks in advance!

  4. #4
    inklinea inklinea @inklinea⛰️

    In inkscape, the handling of ellipse shapes sometimes results in an id = ellipse and a label called path. This just bases it off the path.

    It finds the last number at the end of the id, then increments it by one. 

    It just uses the ID of the currently selected object.

    It does not check for existing ids which conflict. 

    You would have to expand on this.

    .inx

    <?xml version="1.0" encoding="UTF-8"?>
    <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
        <name>Duplicate Increment</name>
        <id>org.inkscape.duplicate_increment</id>
        
        <effect>
            <object-type>path</object-type>
            <effects-menu>
                <submenu name="AAA"/>
            </effects-menu>
        </effect>
        <script>
            <command location="inx" interpreter="python">duplicate_increment.py</command>
        </script>
    </inkscape-extension>

     

    .py

    import inkex
    import re
    
    
    def contains_numbers(my_string):
        return any(char.isdigit() for char in my_string)
    
    def get_attributes(self):
        for att in dir(self):
            inkex.errormsg((att, getattr(self, att)))
    
    class DuplicateIncrement(inkex.EffectExtension):
    
        def effect(self):
    
            if len(self.svg.selected) < 1:
                return
    
            my_object = self.svg.selected[0]
    
            my_object_id = my_object.get_id()
    
            my_dupe_object = my_object.duplicate()
    
    
            if contains_numbers(my_object_id):
    
                my_dupe_id_number = re.search(r'(\d*)\D*$', my_object_id).group(1)
                my_dupe_id_name = my_object_id.replace(my_dupe_id_number, '')
    
                my_dupe_id_number = int(my_dupe_id_number)
    
                my_dupe_object.set_id(f'{my_dupe_id_name}{my_dupe_id_number + 1}')
    
                my_dupe_object.label = f'{my_dupe_id_name}{my_dupe_id_number + 1}'
    
    if __name__ == '__main__':
        DuplicateIncrement().run()
    
  5. #5
    Ed Ed @eneuman93

    @inklinea I'm so sorry, but I am a newbie with XML editor and Python. What exactly do I do with these scripts? Thank you very much for your time.

  6. #6
    inklinea inklinea @inklinea⛰️

    save the first one as 

    duplicate_increment.inx

    and the second one as 

    duplicate_increment.py

    and drop them both into your inkscape extensions folder

  7. #7
    Ed Ed @eneuman93

    @inklinea In the AppData\Roaming\inkscape\extensions folder?

    Do I create the .inx and .py files in notepad?

    Is that it? Do I need to run this extension somehow in Inkscape?

  8. #8
    inklinea inklinea @inklinea⛰️

    Yes, if you reopen inkscape, it will appear under a menu labelled AAA at the top of the extensions menu.

    It requires Inkscape 1.1

     

  9. #9
    Ed Ed @eneuman93
    *

    @inklinea It is not working. The extension pops up on the menu but the object ID's still do not grow incrementally as paths are copied/pasted or duplicated

  10. #10
    inklinea inklinea @inklinea⛰️

    Sorry, you have to select an object, then run the extension.

    You can assign it to a shortcut key,

    If you go into Edit>Preferences>Interface>Keyboard as in the picture, I have assigned it to Shift+Ctrl+I

     

    Screenshot From 2021 08 09 13 10 23
  11. #11
    Ed Ed @eneuman93

    @inklinea I tried and it does not work. Did it work for you?

  12. #12
    inklinea inklinea @inklinea⛰️

    Yes, I have tested the code above in Inkscape 1.1 on Linux and Windows 10. 

    Works for me, but sorry if it doesn't for you.

  13. #13
    Ed Ed @eneuman93
    *

    @inklinea I think i got it to work. thank you!

  14. #14
    inklinea inklinea @inklinea⛰️

    hmm, I'm not sure perhaps I should have designed it for 1.0 onwards instead of 1.1.

Inkscape Inkscape.org Inkscape Forum Beyond the Basics Defining an Incrementing Object Properties ID when Duplicating or Copying/Pasting