{"id":12905,"date":"2016-05-11T08:53:48","date_gmt":"2016-05-11T12:53:48","guid":{"rendered":"http:\/\/scruss.com\/blog\/?p=12905"},"modified":"2016-05-11T08:53:48","modified_gmt":"2016-05-11T12:53:48","slug":"scripting-inkscape-kinda","status":"publish","type":"post","link":"https:\/\/scruss.com\/blog\/2016\/05\/11\/scripting-inkscape-kinda\/","title":{"rendered":"Scripting Inkscape &#8211; kinda"},"content":{"rendered":"<p>A couple of months back at the <a href=\"https:\/\/gtalug.org\/\">GTALUG<\/a> Graphics session, someone asked if Inkscape &#8211; the 2D vector graphics workhorse that everyone seems to use &#8211; could be scripted. We pretty much said that it couldn\u00e2\u20ac\u2122t. Recently, I found out that it does support a limited form of scripting, and wish to pass this on.<\/p>\n<p>The key to it is understanding Inkscape\u00e2\u20ac\u2122s command verbs. These can be listed using:<\/p>\n<pre><code>inkscape --verb-list\r\n<\/code>\r\n<\/pre>\n<p>These verbs map to Inkscape commands, and often have names linked to the menu they live in (such as \u00e2\u20ac\u0153FileQuit\u00e2\u20ac\u009d doing what you\u00e2\u20ac\u2122d expect).<\/p>\n<p>I had a task I had to repeat on many files: convert all the stroked lines to filled paths. You\u00e2\u20ac\u2122d need to do this if you are laser engraving a simple drawing, but there are other applications for this too. Here\u00e2\u20ac\u2122s a command that would do this for all objects in a drawing, and <em>overwrite<\/em> the input file:<\/p>\n<pre><code>inkscape --verb EditSelectAll --verb SelectionUnGroup \\\r\n        --verb EditSelectAll --verb SelectionUnGroup \\\r\n        --verb EditSelectAll --verb SelectionUnGroup \\\r\n        --verb EditSelectAll --verb ObjectToPath \\\r\n        --verb EditSelectAll --verb SelectionCombine \\\r\n        --verb EditSelectAll --verb StrokeToPath \\\r\n        --verb FileSave --verb FileClose \\\r\n        --verb FileQuit input.svg\r\n<\/code>\r\n<\/pre>\n<p>What this does:<\/p>\n<ol>\n<li>Selects everything, and ungroups all objects (\u00c3\u20143, to break up most nested groups);<\/li>\n<li>Selects everything, and converts all objects to paths (so text, circles, polygons, spirals become paths, the lowest-level SVG object);<\/li>\n<li>Selects everything, and combines everything into one path;<\/li>\n<li>Selects everything, and converts all strokes to filled paths (so a two node straight line 1 mm wide would become a four node filled rectangle 1 mm thick);<\/li>\n<li>Overwrite the input file, close it, and quit.<\/li>\n<\/ol>\n<p>The process has some disadvantages:<\/p>\n<ol>\n<li>It opens a window <em>every<\/em> <em>time<\/em>. You can\u00e2\u20ac\u2122t execute verbs without the GUI opening.<\/li>\n<li>You can\u00e2\u20ac\u2122t have another copy of Inkscape open while you do this.<\/li>\n<li>Realistically, you can\u00e2\u20ac\u2122t really do <em>anything<\/em> at your computer until this is done, as it\u00e2\u20ac\u2122s popping up windows and shifting focus like crazy. (ssh types can say \u00e2\u20ac\u0153<em>heh<\/em>!\u00e2\u20ac\u009d in a smug manner now)<\/li>\n<li>You can\u00e2\u20ac\u2122t set parameters to verbs.<\/li>\n<li>It will overwrite the input file.<\/li>\n<li>It clogs up your \u00e2\u20ac\u0153File \/ Recent\u00e2\u20ac\u009d menu with all of the files you scripted.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>A couple of months back at the GTALUG Graphics session, someone asked if Inkscape &#8211; the 2D vector graphics workhorse that everyone seems to use &#8211; could be scripted. We pretty much said that it couldn\u00e2\u20ac\u2122t. Recently, I found out that it does support a limited form of scripting, and wish to pass this on. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7],"tags":[2294],"class_list":["post-12905","post","type-post","status-publish","format-standard","hentry","category-computers-suck","tag-inkscape"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pQNZZ-3m9","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/12905","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/comments?post=12905"}],"version-history":[{"count":1,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/12905\/revisions"}],"predecessor-version":[{"id":12906,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/12905\/revisions\/12906"}],"wp:attachment":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/media?parent=12905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/categories?post=12905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/tags?post=12905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}