Python Forum
inkscape plugin write in python error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
inkscape plugin write in python error
#1
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 path
i 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 range
if 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
Reply
#2
what is your question?
Reply
#3
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 path
after 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
Reply
#4
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-ind...range-mean

But i not find how resolve this!
Reply
#5
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
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#6
Now working!
Now pass over exception and create gcode file!
here is exceptin debug:
Quote:Type: <type 'list'>
Len: 2
Content: ['Z', []]
Type: <type 'list'>
Len: 2
Content: ['Z', []]
{http://www.w3.org/2000/svg}path --- m 140.56641,264.72759 h -3.65235 v -2.32422 q -0.48828,0.33203 -1.32812,0.9375 -0.82031,0.58594 -1.60156,0.9375 -0.91797,0.44922 -2.10938,0.74219 -1.19141,0.3125 -2.79297,0.3125 -2.94922,0 -5,-1.95313 -2.05078,-1.95312 -2.05078,-4.98047 0,-2.48047 1.05469,-4.0039 1.07422,-1.54297 3.04687,-2.42188 1.99219,-0.8789 4.78516,-1.1914 2.79297,-0.3125 5.99609,-0.46875 v -0.56641 q 0,-1.25 -0.44922,-2.07031 -0.42968,-0.82032 -1.25,-1.28907 -0.78125,-0.44921 -1.875,-0.60546 -1.09375,-0.15625 -2.28515,-0.15625 -1.44531,0 -3.22266,0.39062 -1.77734,0.37109 -3.67187,1.09375 h -0.19532 v -3.73047 q 1.07422,-0.29297 3.10547,-0.64453 2.03125,-0.35156 4.00391,-0.35156 2.30469,0 4.00391,0.39062 1.71875,0.3711 2.96875,1.28907 1.23046,0.89843 1.875,2.32421 0.64453,1.42579 0.64453,3.53516 z m -3.65235,-5.3711 v -6.07421 q -1.67968,0.0977 -3.96484,0.29296 -2.26563,0.19532 -3.59375,0.56641 -1.58203,0.44922 -2.5586,1.40625 -0.97656,0.9375 -0.97656,2.59766 0,1.875 1.13281,2.83203 1.13282,0.9375 3.45704,0.9375 1.93359,0 3.53515,-0.74219 1.60157,-0.76172 2.96875,-1.81641 z --- 0.0

[(140.56641, 264.72759), (136.91405999999998, 264.72759), (136.91405999999998, 262.40337), (136.42577999999997, 262.73539999999997), (134.76562999999996, 263.92681), (133.06640999999996, 264.72759), (130.68358999999998, 265.33306), (126.13280999999998, 265.33306), (122.03124999999997, 261.42681), (122.03124999999997, 255.91898999999998), (124.16015999999996, 252.85259), (128.12499999999997, 251.09478000000001), (133.71093999999997, 250.46978000000001), (136.91405999999998, 249.74712000000002), (136.91405999999998, 248.49712000000002), (136.03516, 246.85649), (134.43358999999998, 245.93853000000001), (132.24608999999998, 245.62603000000001), (129.60938, 245.62603000000001), (126.05469, 246.38774000000004), (123.96484, 247.11040000000003), (123.96484, 243.37993000000003), (125.03905999999999, 243.08696000000003), (129.10156, 242.38384000000002), (133.37891, 242.38384000000002), (136.79688, 243.14556000000005), (139.27733999999998, 244.96196000000003), (140.56641, 247.81353000000004), (136.91405999999998, 259.35649), (136.91405999999998, 253.28228000000001), (135.23438, 253.37998000000002), (130.68358999999998, 253.77056000000002), (127.77343999999997, 254.59087), (125.82030999999996, 256.4854), (125.82030999999996, 260.02056), (128.08593999999997, 261.91508999999996), (132.34374999999997, 261.91508999999996), (135.54687999999996, 260.41117999999994)]
and here is result:
Quote:G01 F300
G01 X140.566 Y264.728 Z0.0 E0.0
G01 X136.914 Y264.728 Z0.0 E0.0
G01 X136.914 Y262.403 Z0.0 E0.0
G01 X136.426 Y262.735 Z0.0 E0.0
G01 X134.766 Y263.927 Z0.0 E0.0
G01 X133.066 Y264.728 Z0.0 E0.0
G01 X130.684 Y265.333 Z0.0 E0.0
G01 X126.133 Y265.333 Z0.0 E0.0
G01 X122.031 Y261.427 Z0.0 E0.0
G01 X122.031 Y255.919 Z0.0 E0.0
G01 X124.160 Y252.853 Z0.0 E0.0
G01 X128.125 Y251.095 Z0.0 E0.0
G01 X133.711 Y250.470 Z0.0 E0.0
G01 X136.914 Y249.747 Z0.0 E0.0
G01 X136.914 Y248.497 Z0.0 E0.0
G01 X136.035 Y246.856 Z0.0 E0.0
G01 X134.434 Y245.939 Z0.0 E0.0
G01 X132.246 Y245.626 Z0.0 E0.0
G01 X129.609 Y245.626 Z0.0 E0.0
G01 X126.055 Y246.388 Z0.0 E0.0
G01 X123.965 Y247.110 Z0.0 E0.0
G01 X123.965 Y243.380 Z0.0 E0.0
G01 X125.039 Y243.087 Z0.0 E0.0
G01 X129.102 Y242.384 Z0.0 E0.0
G01 X133.379 Y242.384 Z0.0 E0.0
G01 X136.797 Y243.146 Z0.0 E0.0
G01 X139.277 Y244.962 Z0.0 E0.0
G01 X140.566 Y247.814 Z0.0 E0.0
G01 X136.914 Y259.356 Z0.0 E0.0
G01 X136.914 Y253.282 Z0.0 E0.0
G01 X135.234 Y253.380 Z0.0 E0.0
G01 X130.684 Y253.771 Z0.0 E0.0
G01 X127.773 Y254.591 Z0.0 E0.0
G01 X125.820 Y256.485 Z0.0 E0.0
G01 X125.820 Y260.021 Z0.0 E0.0
G01 X128.086 Y261.915 Z0.0 E0.0
G01 X132.344 Y261.915 Z0.0 E0.0
G01 X135.547 Y260.411 Z0.0 E0.0

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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how include a python code in notpad++ plugin akbarza 2 580 Sep-25-2023, 08:25 PM
Last Post: deanhystad
  how to write exception error into logger mg24 3 949 Nov-15-2022, 04:20 PM
Last Post: insharazzak
  I have an index error inline 76 but I write the program in a way that cant reach tha abbaszandi 2 2,016 Nov-13-2020, 07:43 AM
Last Post: buran
  ERROR: Cannot load plugin dbwest1 0 1,650 Sep-15-2020, 04:28 PM
Last Post: dbwest1
  getting error "exec_proc.stdin.write(b'yes\n') IOError: [Errno 32] Broken pipe" Birju_Barot 0 2,904 Jul-23-2019, 11:50 AM
Last Post: Birju_Barot
  plugin:xxx.py hasfailed to load 1204eray 1 2,071 Jun-26-2019, 09:23 PM
Last Post: micseydel
  Running python code meant for Notepad++ plugin independently greektranslator 3 2,937 Jan-28-2019, 06:03 PM
Last Post: maxtimbo
  Error building trac hacks plugin lapjunior 1 2,669 Apr-06-2018, 08:49 PM
Last Post: nilamo
  UML plugin for Python in Eclipse user2103 1 5,798 Mar-16-2018, 11:14 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020