I have some SVG images which I'm exporting to various formats by means of Inkscape's command-line interface, driven by a custom Rake task. This is working beautifully, but I'd like to be able to programmatically tell Inkscape to omit certain elements from the output. I can see command-line options that only include certain elements, but I have not found an option that only excludes certain elements.

Another way of accomplishing this might be to use CSS to tell Inkscape to hide the elements, but I haven't found a good way of doing that programmatically either.

Any ideas on how to accomplish this? I'm perfectly happy to use some other SVG manipulation tool if necessary to achieve this. (Ideally I want this to work on Mac OS and other Unix-like systems, and hopefully on Windows as well.)

My use case is that I'm trying to get two outputs from a single source, one with some visual guidelines in the output and one without.

  • 1
    On reflection, since I'm using Ruby anyway because of driving this from Rake, I suppose I could use Nokogiri or some other Ruby XML library to parse the SVG XML DOM and remove particular elements from it. But I think I'd really rather use a tool that understands SVG... – Marnen Laibow-Koser Jan 18 '17 at 21:10
  • What attribute do all those guidelines have in common? Would it be much work, to add a common feature? This could be a color, or the id like in path id=g3348. Afaik, the id has to be unique, but you could rename all guidelines to gl3348, gl3349 etc. which would allow you to supress elements with this pattern later, like Marman said, with an XML tool or even with sed/awk/grep etc. (search for patterns, replace). – user unknown Jan 20 '17 at 9:41
  • The guidelines are already named in such a way that programmatically identifying them is easy. The problem is how to exclude them from the output once identified. – Marnen Laibow-Koser Jan 22 '17 at 16:28
  • For a concrete answer, I would need a sample section of such a file. Since SVG is a XML-Format, it program for manipulation of xml would be most appropriate, like xmlstarlet, which I'm not used too. For most practical purposes I would try it with sed, a free, GNU commandline tool, which is available for windows as well. – user unknown Jan 23 '17 at 13:05
  • @userunknown Sed is the wrong tool for this: regex-type processing isn't suitable for XML. As I said above, I could use Nokogiri or something to parse the XML, but I was wondering if there was a way to do this with Inkscape or some other SVG utility. Sounds like not. – Marnen Laibow-Koser Jan 24 '17 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.