![]() |
inkscape plugin write in python error - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: inkscape plugin write in python error (/thread-15620.html) |
inkscape plugin write in python error - costycnc - Jan-24-2019 def transformPath(self, p): """ Transforms path to machine coordinates This takes a path as returned by simplepath.parsePath and returns a list of (x, y) coordinated in the machine frame of reference """ inkex.debug(p) #For the moment we just take coordinates path = [] for point in p: path.append((point[1][0], point[1][1])) return pathi get a error Traceback (most recent call last): File "polyshaper1.py", line 129, in <module> e.affect() File "E:\InkscapePortable\App\Inkscape\share\extensions/inkex.py", line 283, in affect self.effect() File "polyshaper1.py", line 112, in effect path = self.transformPath(svgPath) File "polyshaper1.py", line 55, in transformPath path.append((point[1][0], point[1][1])) IndexError: list index out of rangeif insert a debug line i can see al value ... but at finish of list of value i get this error i thing that this function for point in p: read all value but need to read until p-1 but i dont know hoew maketo read until p-1 RE: inkscape plugin write in python error - Larz60+ - Jan-24-2019 what is your question? RE: inkscape plugin write in python error - costycnc - Jan-24-2019 def transformPath(self, p): """ Transforms path to machine coordinates This takes a path as returned by simplepath.parsePath and returns a list of (x, y) coordinated in the machine frame of reference """ #For the moment we just take coordinates path = [] for point in p: path.append((point[1][0], point[1][1])) inkex.debug(point[1][0]) inkex.debug(point[1][1]) return pathafter path.append i insert a debug line for view where crash and can see that when read ultimate value crashes i dont know where can be the problem 170.54871 280.08774 144.08789 280.08774 144.08789 263.24903 140.55034 265.65456 128.52269 274.28617 116.21204 280.08774 98.94883 284.47429 65.978925 284.47429 36.263559 256.17394 36.263559 216.27045 51.687249 194.05468 80.412102 181.31952 120.8816 176.79147 144.08789 171.5559 144.08789 162.49979 137.72031 150.61365 126.11716 143.96306 110.26897 141.69904 91.166234 141.69904 65.412918 147.2176 50.272232 152.45317 50.272232 125.42634 58.054827 123.30381 87.487189 118.20975 118.47607 118.20975 143.23887 123.72832 161.2096 136.88798 170.54871 157.54723 Traceback (most recent call last): File "polyshaper1.py", line 130, in <module> e.affect() File "E:\InkscapePortable\App\Inkscape\share\extensions/inkex.py", line 283, in affect self.effect() File "polyshaper1.py", line 113, in effect path = self.transformPath(svgPath) File "polyshaper1.py", line 55, in transformPath path.append((point[1][0], point[1][1])) IndexError: list index out of range RE: inkscape plugin write in python error - costycnc - Jan-25-2019 I see that mybe is not understand well my question! So ... i explain... The function "for point in p:" Read all values of points from 0 to len p So in another words mean: I proposed that len p is 10. So i have 10 values to read. But problem is with index ... the function read from 0 to 10 so from 0 to 10 is 11 values 0 1 2 3 4 5 6 7 8 9 10 ->> 11 Normally the function need to read until at 9 (no 10) because at 10 is not value and give me this error IndexError: list index out of range here is explain better https://www.quora.com/What-does-list-index-out-of-range-mean But i not find how resolve this! RE: inkscape plugin write in python error - DeaD_EyE - Jan-25-2019 Just use exception handling to catch the error and add more debug information to output. It will still return the points, he already appended to path .IndexError means, that you try to access an index, which does not exist.Maybe the yielded element is too short (list, tuple or other sequence) or it is None .In both cases you should investigate deeper, why you get this element. Maybe it's a bug at another place. def transformPath(self, p): """ Transforms path to machine coordinates This takes a path as returned by simplepath.parsePath and returns a list of (x, y) coordinated in the machine frame of reference """ #For the moment we just take coordinates path = [] for point in p: try: path.append((point[1][0], point[1][1])) except IndexError: inkex.debug('Type: {}'.format(type(point))) # inkex.debug('Len: {}'.format(len(point))) inkex.debug('Content: {}'.format(point)) return path RE: inkscape plugin write in python error - costycnc - Jan-25-2019 Now working! Now pass over exception and create gcode file! here is exceptin debug: Quote:Type: <type 'list'>and here is result: Quote:G01 F300 The response of debug is high because haved two lines under program. i close these 2 extra lines with debug and now response at error is only Type: <type 'list'> Len: 2 Content: ['Z', []]but important is that program not blocking more at this line is execute all and create the gcode Anyway ... is not perfect mode ... but for mine is perfect i lost 3 days for find a way to make program working ... and i not find any response! Thanks again! |