# Get all the vertices from a general path

**URL:** <https://forum.inductiveautomation.com/t/get-all-the-vertices-from-a-general-path/100184>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [December 24, 2024, 3:30am UTC](https://forum.inductiveautomation.com/t/get-all-the-vertices-from-a-general-path/100184 "2024-12-24T03:30:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 24, 2024, 3:30am UTC](https://forum.inductiveautomation.com/t/get-all-the-vertices-from-a-general-path/100184/1 "2024-12-24T03:30:51Z")

</div>

I'm working with a [PathBasedVisionShape](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.44/com/inductiveautomation/vision/api/client/components/shapes/PathBasedVisionShape.html). I want to get the coordinates for all of the points on the line. It doesn't matter if the coordinates are relative to the shape object or the container.

I can get the general path from the component using a test button like this:

```python
path = event.source.parent.getComponent('Test Path').shape
print type(path)

```

**Output:**

```python
java.awt.geom.GeneralPath

```

`path.currentPoint` accurately gives me the last point in the path relative to the content container: `Point2D.Float[995.0, 690.0] `  
If I get the iterator and cycle through the segments, I see the correct number of iterations:

```python
iterator = path.getPathIterator(None)

iDontTrustWhileLoops = 0
while not iterator.done and iDontTrustWhileLoops < 50:
	iDontTrustWhileLoops += 1
	iterator.next()

print iDontTrustWhileLoops

```

**Output:** `5`

According to [the documentation](https://docs.oracle.com/javase//9/docs/api/index.html?java/awt/geom/class-use/PathIterator.html) for the Path2D iterator, I should be able to get the coordinates by passing a double into the currentSegment method, but the script blew up when I did this.

```python
TypeError: currentSegment(): 1st arg can't be coerced to float[], double[]

```

A bit of trial and error revealed that a list of length 2 or a tuple of floats works:

```python
coords = (0.0, 0.0) # or [0.0, 0.0]
while not iterator.done:
	print iterator.currentSegment(coords)
	print coords
	iterator.next()

```

...but the input values are not modifed.

**Output:**

```python
0
(0.0, 0.0)
1
(0.0, 0.0)
1
(0.0, 0.0)
1
(0.0, 0.0)
1
(0.0, 0.0)

```

I'm stumped at the moment. Does anybody know how to do this?

**Edit:**  
Here is a screenshot of the test line:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/b/eb86eee46a17167761b9349e8f9dbf916f6fd692.png)

`iterator.currentSegment(coords)` returns the type of movement, so:

```python
# iterator.SEG_MOVETO = 0
# iterator.SEG_LINETO = 1
# iterator.SEG_QUADTO = 2
# iterator.SEG_CUBICTO = 3
# iterator.SEG_CLOSE = 4

```

...according to the outputs in my case, the iterator simply moves to the starting position and then uses LINETO to paint each segment of the line.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 24, 2024, 5:14am UTC](https://forum.inductiveautomation.com/t/get-all-the-vertices-from-a-general-path/100184/2 "2024-12-24T05:14:45Z")

</div>

I figured it out. The argument needs to be Java array.instead of a Python list

**Example:**

```python
from jarray import zeros # for creating an array.array

# Get the iterator from the general path within the shape
iterator = event.source.parent.getComponent('Test Path').shape.getPathIterator(None)

# Create a list to hold the coordinates,
# ...and generate a Java array for the iterator's currentSegment method
allCoordinates = []
coords = zeros(2, 'd') #(number of zeros to create, type 'd' for double)

# Iterate through all of the segments and get the ending points
# iterator.currentSegment(coords) returns the type:
#	iterator.SEG_MOVETO = 0 # Array size 2 
#	iterator.SEG_LINETO = 1 # Array size 2 
#	iterator.SEG_QUADTO = 2 # Array size 4 (2 coordinate sets)
#	iterator.SEG_CUBICTO = 3 # Array size 6 (3 coordinate sets)
#	iterator.SEG_CLOSE = 4 # Array size 2 
while not iterator.done:
	iterator.currentSegment(coords)
	allCoordinates.append(list(coords))
	iterator.next()

for coordinate in allCoordinates:
	print coordinate

```

**Output:**

```python
[80.0, 660.0]
[100.0, 640.0]
[525.0, 660.0]
[950.0, 640.0]
[995.0, 690.0]

```

If there is a more intuitive way to accomplish this, please let me know.

**Edit:** Added a list to contain the currentSegment outputs, so they can actually be used in the script somewhere, and added comments that include useful stuff I learned while researching the problem that could come in handy with other applications of this code.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 25, 2024, 3:39am UTC](https://forum.inductiveautomation.com/t/get-all-the-vertices-from-a-general-path/100184/3 "2024-12-25T03:39:31Z")

</div>

I had a bit of fun while developing my path mapping function...

...and I'll betcha didn't know that you could do this usng a PathBasedVisionShape:  
 ![MerryChrismas](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/2/02ce5b7cbddbca93b7b3240f8c0c8e6d37574244.gif)

Merry Christmas everybody!  
[ChristmasTemplate.zip](https://forum.inductiveautomation.com/uploads/short-url/4XOWCYTZSxckDCaaYVH4v1CTCll.zip) (15.8 KB)
