Inkscape.org
Using Inkscape with Cutters/Plotters Obtaining original SVG file name from within extention
  1. #1
    unclecalli unclecalli @unclecalli

    How does one obtain the file name of the the currently being edited SVG from within an extention?

    TLDR;

    I am attempting to use Inkscape for printing on my Universal Laser cutter/engraver.  This laser machine is controlled via a Microsoft Windows based print driver.  Lines that are printed in RED with a width of < 0.001 in (0.025 mm) will be cut by the laser; blue lines that are < 0.001 in (0.025 mm) will be vector engraved, and all others (regardless of color) will be raster engraved.   I am unable to successfully use Inkscape's built in printing support to get correct output for the laser - everything comes across as raster engraved (I assume due to line width issues).  To work around this I have crafted a C# based extension (in the form of an EXE file) to properly print the SVG in such a way that the laser machine properly sees thin red and blue lines so that cuts and vector engravings are performed correctly.  As part of the Universal Laser's printer driver (and its UCP) printed documents are stored and made available to re-printing in some future time.  Printed documents are identified by the software that sourced the print job, and are usually based on the original document's file name.  This is very similar to how all printed documents in Windows appear in the print queues. 

    I know to to set this Print Document name if I knew the original SVG file name.  As an extension, I am only provided a temporary file name.  Is there an API or some internal document field that might make this information available to me.

  2. #2
    Tyler Durden Tyler Durden @TylerDurden

    I can't answer your specific question, but will mention that MANY Inkscape users with lasers (e.g. Epilog) save a copy as PDF and use the Adobe reader print dialog and laser's "print" driver.

  3. #3
    inklinea inklinea @inklinea⛰️

    Welcome to Inkscape’s Extension Docs - https://inkscape-extensions-guide.readthedocs.io/

    This is Python, I don't know how this would be retrieved using C#

    When the extension system launches. 

    Temp filename is at self.options.input_filename

    IF the svg has been saved (or opened from a saved file)

    SVG filename is at self.svg.name

     

     

     

     

  4. #4
    unclecalli unclecalli @unclecalli

    @TylerDurden as do many Universal laser owners - that does however involve many extra steps.  I am attempting to stream line my processes.  Simply "Printing" from within Inkscape is what I'm after and I believe I've now got it.

    @inklinea - thanks for the pointers.  As a point of clarification, I believe the filename is at self.options.input_file

    In the end I was able craft a simple python based extension that simply invokes my C# based SVGViewer.exe that has Windows GDI based printing support for SVG files.  Here is what it looks like:

    #!/usr/bin/env python 
    '''
    Thin Python Inkscape extension to invoke SVGViewer.exe for purposes of accurate Windows GDI based printing.
    '''
    # local library
    import inkex
    
    import os
    import subprocess
    
    if not inkex.sys.platform.startswith('win'):
        exit(_("sorry, this will run only on Windows, exiting..."))
    
    class MyEffect(inkex.Effect) :
        def __init__(self):
            inkex.Effect.__init__(self)
            self.visibleLayers = True       # print only visible layers
    
        def effect(self):
            SVGViewerPath = os.path.realpath('SVGViewer.exe')
            if (len(self.svg.name) > 0) :
                subprocess.run([SVGViewerPath, '-P','-Display_Name', self.svg.name, self.options.input_file])
            else :
                subprocess.run([SVGViewerPath, '-P', self.options.input_file])
            
    
    if __name__ == '__main__':
        e = MyEffect()
        e.run()
    
    # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99
    
    

     

Inkscape Inkscape.org Inkscape Forum Using Inkscape with Cutters/Plotters Obtaining original SVG file name from within extention