vishpat / svg2gcode

Python script to convert svg to gcode for Marlin firmware
GNU General Public License v3.0
92 stars 37 forks source link

Keep getting "IndexError: list index out of range" #2

Open davidwachs opened 8 years ago

davidwachs commented 8 years ago

Hey, AWESOME code, but I have an issue...

when it parses my svgs, I keep getting index out of range... any idea what I can do to fix this?

I get this even with simple SVGs:

<svg xmlns="http://www.w3.org/2000/svg" width="6120" height="7920" version="1.1">

 <path d="M 6.078125 -9.390625 C6.078125 -9.9375 6.265625 -11.046875 6.015625 -11.59375 L 5.96875 -11.59375C5.796875 -11.953125 5.296875 -12.09375 4.859375 -12.421875C4.640625 -12.59375 4.421875 -12.953125 4.140625 -12.953125C3.890625 -12.953125 3.3125 -12.703125 2.765625 -12.28125C1.578125 -11.375 0.109375 -9.75 0.109375 -8.671875C0.109375 -8.28125 0.4375 -7.953125 0.859375 -7.78125C2.484375 -7.0625 4.6875 -9.390625 6.078125 -9.390625ZM8.09375 -5.796875C6.4375 -5.65625 5.96875 -6.734375 6.046875 -8.921875C6.078125 -9.9375 6.265625 -11.625 6.265625 -12.34375L6.015625 -12.34375M8.09375 -5.796875" transform="translate(72, 100.8)"/>

</svg>

I've been struggling with this... any help you can lend would be amazing... thanks so much in advance.

Harvie commented 6 years ago

Does this still happen? update: yes it does:

Traceback (most recent call last):
  File "svg2gcode.py", line 60, in <module>
    generate_gcode()
  File "svg2gcode.py", line 51, in generate_gcode
    for x,y in p:
  File "/home/harvie/Temp/svg3gcode/shapes.py", line 184, in point_generator
    cspsubdiv.subdiv( sp, flatness)
  File "/home/harvie/Temp/svg3gcode/cspsubdiv.py", line 22, in subdiv
    p2 = sp[i][0]  
IndexError: list index out of range

It happens with your SVG, but not with mine SVGs... There's probably something that triggers it.

Harvie commented 6 years ago

I've used inkscape to break your svg into subpaths and one of the paths it created was empty:

  <path
     d="M 7.984375,7.15625"
     id="path2"
     inkscape:connector-curvature="0" />

probably svg2gcode should detect this and avoid processing such zero length shape?

davidwachs commented 6 years ago

I don’t use the code anymore so I can’t say. Thanks for asking though.

David Wachs Chief Robot Mechanic, Handwrytten T: 602.792.7221 | M: 312.282.0912 E: david@handwrytten.commailto:david@handwrytten.com | W: www.handwrytten.comhttp://www.handwrytten.com/ Schedule a Meetinghttps://app.hubspot.com/meetings/davidwachs/meet

On Jul 13, 2018, at 7:18 PM, Tomas Mudrunka notifications@github.com<mailto:notifications@github.com> wrote:

Does this still happen?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/vishpat/svg2gcode/issues/2#issuecomment-404991849, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ALnLJ5NAZqTmtOCt3ooQYA0Faus56Ytyks5uGVT1gaJpZM4J5Udp.

davidwachs commented 6 years ago

Oh gotcha. Thank you!

David Wachs Chief Robot Mechanic, Handwrytten T: 602.792.7221 | M: 312.282.0912 E: david@handwrytten.commailto:david@handwrytten.com | W: www.handwrytten.comhttp://www.handwrytten.com/ Schedule a Meetinghttps://app.hubspot.com/meetings/davidwachs/meet

On Jul 13, 2018, at 7:24 PM, Tomas Mudrunka notifications@github.com<mailto:notifications@github.com> wrote:

I've used inkscape to break your svg into subpaths and one of the paths it created was empty:

<path d="M 7.984375,7.15625" id="path2" inkscape:connector-curvature="0" />

probably svg2gcode should detect this and avoid processing such zero length shape?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/vishpat/svg2gcode/issues/2#issuecomment-404992160, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ALnLJ8VIcv9IcOm-W-BL71I8ZJbYGzB4ks5uGVZYgaJpZM4J5Udp.

r3a2t10 commented 5 years ago

I also met this problem when running svg

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="50px" height="50px" viewBox="0 0 50 50" version="1.1" fill="#000000">
  <g id="surface279232">
    <path style=" stroke:none;fill-rule:nonzero;fill:#000000;fill-opacity:1;" d="M 7.8125 7.8125 L 7.8125 42.1875 L 42.1875 42.1875 L 42.1875 7.8125 Z M 10.9375 10.9375 L 39.0625 10.9375 L 39.0625 39.0625 L 10.9375 39.0625 Z M 25 17.1875 C 21.546875 17.1875 18.75 19.984375 18.75 23.4375 L 18.75 26.5625 C 18.75 30.015625 21.546875 32.8125 25 32.8125 C 28.453125 32.8125 31.25 30.015625 31.25 26.5625 L 31.25 23.4375 C 31.25 19.984375 28.453125 17.1875 25 17.1875 Z M 25 20.3125 C 26.863281 20.3125 28.125 21.574219 28.125 23.4375 L 28.125 26.5625 C 28.125 28.425781 26.863281 29.6875 25 29.6875 C 23.136719 29.6875 21.875 28.425781 21.875 26.5625 L 21.875 23.4375 C 21.875 21.574219 23.136719 20.3125 25 20.3125 Z M 25 20.3125 "/>
  </g>
</svg>

and I delete the last Z M 25 20.3125 in d and generate successfully but loss some stroke How to fix this problem? Please help me >< Thanks a lot