eneroth3 / inkscape-purge-short-lines Goto Github PK
View Code? Open in Web Editor NEWInskcape extension for purging short lines. Useful for cleaning up SketchUp 2D exports.
License: MIT License
Inskcape extension for purging short lines. Useful for cleaning up SketchUp 2D exports.
License: MIT License
Dear Julia,
i am interested to get the plugin working but i had no luck. Neither with InkScape 0.91, 092.0, 0.92.3 or 0.92.4. I tried with simple triangle as well as huge graphics.
I guess your plugin maybe worked/works for you because the "d" from node might not have more than 2 points each node/path (=pdf export from SketchUp?)
The stacktrace thrown is always
Traceback (most recent call last):
File "eneroth_purge_short_edges.py", line 64, in <module>
EnerothPurgeShortEdges().affect()
File "C:\Users\mario\Downloads\Inkscape-0.91-1-win64\inkscape\share\extensions\inkex.py", line 268, in affect
self.effect()
File "eneroth_purge_short_edges.py", line 30, in effect
self.iterate_node(node)
File "eneroth_purge_short_edges.py", line 33, in iterate_node
self.do_node(node)
File "eneroth_purge_short_edges.py", line 51, in do_node
coords[0] += prev_coords[0]
TypeError: 'NoneType' object is unsubscriptable
I just did some experiments with it but it won't work
#!/usr/bin/env python
import sys
sys.path.append('/usr/share/inkscape/extensions')
# Purge short lines
# This script is designed to be used to clean up/simplify 2D vector exports from
# SketchUp. It ignores everything but paths between exactly 2 points.
import inkex
import math
from simplestyle import *
debug = False
class EnerothPurgeShortEdges(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
self.OptionParser.add_option('-w', '--length', action = 'store',
type = 'float', dest = 'length', default = 10.0)
def effect(self):
length = self.options.length
svg = self.document.getroot()
if len(self.selected)==0:
self.iterate_node(self.document.getroot())
else:
for id, node in self.selected.iteritems():
self.iterate_node(node)
def iterate_node(self, node):
self.do_node(node)
for child in node:
self.iterate_node(child)
def do_node(self, node):
if node.attrib.has_key('d'):
points = []
instruction = None
prev_coords = [0,0]
words = node.get('d').split(' ')
for i, word in enumerate(words):
if len(word) == 1:
instruction = word
# inkex.debug(word)
else:
# Sometimes there is the case that "coords" returns only an array like [-1.29] (only one coordinate) instead of XY coordinates. Reason is the type "map"
coords = map(lambda c: float(c), word.split(','))
# inkex.debug(coords)
if instruction.lower() == instruction:
# inkex.debug("coords len=" + str(len(coords)) + "prev_coords len=" + str(len(prev_coords)))
coords[0] += prev_coords[0]
coords[1] += prev_coords[1]
# if len(coords) == 2:
# coords[1] += prev_coords[1]
prev_coords = coords
# Assume all coordinates are points of straight lines (instructor being M, m, L or l)
inkex.debug("X=" + str(coords[0]) + "Y=" + str(coords[1]))
points.append(coords)
inkex.debug("pointsCount=" + str(len(points)))
if len(points) == 2:
length = math.sqrt((points[0][0]-points[1][0])**2 + (points[0][1]-points[1][1])**2)
inkex.debug("length=" + str(length))
if debug:
inkex.debug(length)
if length < self.options.length:
inkex.debug("delete")
node.getparent().remove(node)
EnerothPurgeShortEdges().affect()
Do you have some idea on how to fix it?
regards and thanks for your work, Mario
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.