3.3 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			3.3 KiB
		
	
	
	
	
	
	
	
Inkscape
Save Selection to SVG extension
ink file
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
  <!-- _name must have same name as .py file but capitalise it. Shows on Menu this way-->
  <_name>Save Selection</_name>
  <!-- id should be unique. Associates entered values with this menu -->
  <id>org.inkscape.save_selection</id>
  <!-- mention a dependency here and will check for existence (optional)-->
  <dependency type="executable" location="inx">save_selection.py</dependency>
  <!-- start notebook -->
  <param name="param" type="float" min="0.1"  max="1000.0"  precision="5"  _gui-text="A floating value">1.0</param>
  <param name="achoice" type="bool" _gui-text="A boolean value">false</param>
  <effect>
    <object-type>all</object-type>
    <effects-menu>
      <submenu _name="Save Selection"/>
    </effects-menu>
  </effect>
  <!-- py file again -->
  <script>
    <command location="inx" interpreter="python">save_selection.py</command>
  </script>
</inkscape-extension>
py file
import os
import inkex
import inkex.command
class SaveSelection(inkex.OutputExtension): # choose a better name
    def add_arguments(self, pars):
        pars.add_argument("--param", type=float, dest="param", default=1.0)
        pars.add_argument("-x", "--achoice", type=inkex.Boolean, dest="achoice", default=False)
    def save(self, stream):
        # param2 = self.options.param
        # choice = self.options.achoice
        # inkex.command.inkscape_command(self.svg, verbs=['EditInvert']);
        # inkex.command.inkscape_command(self.svg, verbs=['EditDelete']);
        # filename = os.popen('rofi -dmenu -p "Filename"')
        # print(filename)
        # inkex.debug(self.svg.selected.svg)
        self.document.write(self.svg.selected)
        # Get selected objects
        # selection = self.svg.selected
        # selection = inkex.load_svg(
        #     inkex.command.inkscape_command(
        #         self.svg, verbs=['FitCanvasToDrawing']))
        # # Create a Canvas ovject
        # # Write File
        # # stream.write(b''.join(self.svg.selected.tostring()))
        # inkex.command.write_svg(selection, "/home/thomas/", "test.svg")
if __name__ == '__main__':
    SaveSelection().run()