---
title: PathData
---

PathData is an indexed collection of [PathCommand](/scripting/api-reference/path/path-command) objects.
Both Path and PathData behave like arrays of commands and support iteration via ipairs.


## Methods

### `__len`

{/* function __len(self): number */}
<div class="signature">
```lua
__len() -> number
```
</div>

Each entry is a [PathCommand](/scripting/api-reference/path/path-command) describing one segment or action in the path.
```lua
for i, command in ipairs(pathData) do
  print(i, command.type)
end
```
Returns the number of commands in the path.
```lua
local count = #pathData
print(count)
```


### `contours`

{/* contours: (self: PathData) -> ContourMeasure? */}
<div class="signature">
```lua
contours() -> ContourMeasure?
```
</div>

Returns a [ContourMeasure](/scripting/api-reference/path/contour-measure) for the first contour in the path. A contour is a
sequence of path segments starting at a `moveTo` and ending before the next
`moveTo` (or end of path). Use the `next` property on the returned
[ContourMeasure](/scripting/api-reference/path/contour-measure) to iterate through subsequent contours. Returns `nil` if the
path has no contours.
```lua
local contour = pathData:contours()
while contour do
  print(contour.length)
  contour = contour.next
end
```


### `measure`

{/* measure: (self: PathData) -> PathMeasure */}
<div class="signature">
```lua
measure() -> PathMeasure
```
</div>

Returns a [PathMeasure](/scripting/api-reference/path/path-measure) that measures the entire path across all contours.
This provides the total length and allows operations on the path as a whole.
```lua
local measure = pathData:measure()
print(measure.length)
```


