Giter VIP home page Giter VIP logo

inkscape-purge-short-lines's People

Contributors

eneroth3 avatar vmario89 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

inkscape-purge-short-lines's Issues

PlugIn does not work for me

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?)

grafik

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.