# Get position of PShape

**URL:** <https://discourse.processing.org/t/get-position-of-pshape/32362>\
**Category:** Coding Questions\
**Created:** [September 22, 2021, 3:05am UTC](https://discourse.processing.org/t/get-position-of-pshape/32362 "2021-09-22T03:05:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shishironeal](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@shishironeal](https://discourse.processing.org/u/shishironeal)\
**Post date:** [September 22, 2021, 3:05am UTC](https://discourse.processing.org/t/get-position-of-pshape/32362/1 "2021-09-22T03:05:51Z")

</div>

I’m loading an SVG using loadShape and I want to get the position of a child PShape so I can draw a bounding box around it. I tried looking through the PShape class and also tried getVertexX (which results in a NPE since there are no vertices in a SVG).  
I’m also curious about finding the width and height of a PShape. I have tested this for the loaded SVG (parent shape) and it works well (spits out actual numbers), but when I try and find the values for a child, I get 0.0 for both.

Thanks again!

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [September 22, 2021, 5:02pm UTC](https://discourse.processing.org/t/get-position-of-pshape/32362/2 "2021-09-22T17:02:43Z")

</div>

> [@shishironeal](#):
>
> since there are no vertices in a SVG

There are sometimes vertices in an SVG. It depends on the original SVG data and how you create it / load it. Can you provide an example?

---

<div class="post-metadata">

**Author:** ![shishironeal](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@shishironeal](https://discourse.processing.org/u/shishironeal)\
**Post date:** [September 22, 2021, 10:59pm UTC](https://discourse.processing.org/t/get-position-of-pshape/32362/3 "2021-09-22T22:59:45Z")

</div>

Yes,  
[SVG in question](http://svgur.com/s/aSx)

```auto
PShape s;
void setup(){
  size(1000,1000);
  s = loadShape("tex.svg");
  s = s.getChild("eq");
  s.disableStyle();
}

void draw(){
  background(0);
  translate(width/2,height/2);
  noStroke();
  PShape ch = s.getChild(7);
  println(ch.width);
  shape(ch);
}

```

I am using JLatexMath to generate these SVG’s, if there is a specific attribute that I must add in the creation of the SVG, I believe I can do that! (Not sure if processing supports pulling extraneous attributes from an SVG)

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [September 23, 2021, 1:13am UTC](https://discourse.processing.org/t/get-position-of-pshape/32362/4 "2021-09-23T01:13:00Z")

</div>

Looking at your SVG markup in a text editor (it is just a text file, after all), it looks like your SVG generator uses a heavily nested style, and you need to go down one level further to get the vertex data you want.

I tried a debugging sketch like this:

```auto
/**
 * SVGpositions -- debugging a nested SVG file to get vertex data
 * 2021-09-22 Jeremy Douglass - Processing 3.5.4
 * https://discourse.processing.org/t/get-position-of-pshape/32362/4
 */
void setup(){
  size(1000,1000);
  background(0);
  stroke(255);
  strokeWeight(2);
  noFill();

  PShape tex = loadShape("tex.svg");
  printShape(tex);

  // tex.disableStyle();

  translate(width/5,height/5);
  PShape tex_eq = tex.getChild("eq");
  printShape(tex_eq);

  translate(width/5,height/5);
  PShape tex_eq_7 = tex_eq.getChild(7);
  printShape(tex_eq_7);

  translate(2*width/5,2*height/5);
  PShape tex_eq_7_0 = tex_eq_7.getChild(0);
  printShape(tex_eq_7_0);

  for(int i=0; i<tex_eq_7_0.getVertexCount(); i++) {
    PVector pv = tex_eq_7_0.getVertex(i);
    point(pv.x, pv.y);
  }
  
  saveFrame("SVGpositions.png");

}

void printShape(PShape s) {
  rect(0, 0, s.width, s.height);
  shape(s);
  println("w: ", s.width, " child#: ", s.getChildCount(), " vertex#: ", s.getVertexCount());
}

```

The console output is:

> getVertexCount() only works with PATH or GEOMETRY shapes  
> w: 453.0 child#: 2 vertex#: 0  
> w: 453.0 child#: 13 vertex#: 0  
> w: 0.0 child#: 1 vertex#: 0  
> w: 0.0 child#: 0 vertex#: 35

Notice that we get a complaint about trying to get vertices at all on the top level, but there are 35 vertices at the fourth level down.

Notice also that the third level doesn’t have a width – notice that it is rendered at the same size, but in an odd location compared to the origin (white dot).

The fourth level we can see the point data – and when we draw the point data manually, it appears on top of the font character – but the character is no longer scaled according to its parent shapes.

Hope this helps get you on the right track.

 ![SVGpositions](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/5d531245424095ce6c8f1dcc021f113affc775f4.png)
