# Extract vertex from a svg file

**URL:** https://discourse.processing.org/t/extract-vertex-from-a-svg-file/39414
**Category:** Coding Questions
**Created:** [October 24, 2022, 2:16pm UTC](https://discourse.processing.org/t/extract-vertex-from-a-svg-file/39414 "2022-10-24T14:16:47Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![DrHooDoo](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@DrHooDoo](https://discourse.processing.org/u/DrHooDoo)
#### Post date: [October 24, 2022, 2:16pm UTC](https://discourse.processing.org/t/extract-vertex-from-a-svg-file/39414/1 "2022-10-24T14:16:47Z")

</div>

Hello all ! 🙂

In short, I’m trying to extract vertex from a svg but no matter how I do I always get an error:  
**“getVertexCount() only works with PATH or GEOMETRY shapes”**  
What I did was:

1. create a little sketch to draw on the screen and save it in a file as SVG ( I also tried with Inkscape)
2. I try to open it as explained here [https://processing.org/reference/PShape\_getChild\_.html](https://processing.org/reference/PShape_getChild_.html)

```auto
void setup() {
  size(1000, 1000);
  PShape ps = loadShape("test.svg");
  shape(ps);

  int children = ps.getChildCount();
  for (int i = 0; i < children; i++) {
    PShape child = ps.getChild(i);
    int total = child.getVertexCount();
    println(total);
  }
}

```

If anyone has an idea, I’m curious to know …  
TIA 😉

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [October 24, 2022, 10:15pm UTC](https://discourse.processing.org/t/extract-vertex-from-a-svg-file/39414/2 "2022-10-24T22:15:25Z")

</div>

> [@DrHooDoo](#):
>
> `child.getVertexCount();`

Did you try

ps.getVertexCount(); instead?

Maybe, there are no children?

---

<div class="post-metadata">

### Author: ![DrHooDoo](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@DrHooDoo](https://discourse.processing.org/u/DrHooDoo)
#### Post date: [October 25, 2022, 9:38am UTC](https://discourse.processing.org/t/extract-vertex-from-a-svg-file/39414/3 "2022-10-25T09:38:44Z")

</div>

I’ve tried but the problem stays the same …

---

<div class="post-metadata">

### Author: ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)
#### Post date: [October 25, 2022, 11:39am UTC](https://discourse.processing.org/t/extract-vertex-from-a-svg-file/39414/4 "2022-10-25T11:39:49Z")

</div>

Perhaps the `child` is a GROUP shape (this is valid), itself having multiple children – you may need to recurse over the shape to find all non-group shapes.

---

<div class="post-metadata">

### Author: ![DrHooDoo](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@DrHooDoo](https://discourse.processing.org/u/DrHooDoo)
#### Post date: [October 25, 2022, 1:32pm UTC](https://discourse.processing.org/t/extract-vertex-from-a-svg-file/39414/5 "2022-10-25T13:32:28Z")

</div>

This is the content of the svg file exported by processing (it’s nothing fancy 😉 )

```auto

<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN'
          'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>
<svg xmlns:xlink="http://www.w3.org/1999/xlink" style="fill-opacity:1; color-rendering:auto; color-interpolation:auto; text-rendering:auto; stroke:black; stroke-linecap:square; stroke-miterlimit:10; shape-rendering:auto; stroke-opacity:1; fill:black; stroke-dasharray:none; font-weight:normal; stroke-width:1; font-family:'Dialog'; font-style:normal; stroke-linejoin:miter; font-size:12px; stroke-dashoffset:0; image-rendering:auto;" width="1000" height="1000" xmlns="http://www.w3.org/2000/svg"
><!--Generated by the Batik Graphics2D SVG Generator--><defs id="genericDefs"
  /><g
  ><g style="fill:rgb(225,225,225); stroke:rgb(225,225,225);"
    ><rect x="0" width="1000" height="1000" y="0" style="stroke:none;"
    /></g
    ><g
    ><path style="fill:none;" d="M328 259 L300 606 L464 619 L480 432 L516 330 L824 456 L634 785"
    /></g
  ></g
></svg
>

```
