1
0
Fork 0
freesewing/sites/dev/docs/reference/api/part/getid
Joost De Cock ab3204f9f1 chore: Port FreeSewing.dev to docusaurus
The replaces the NextJS site powering FreeSewing.dev with a Docusaurus
setup. It's part of my efforts to simplify FreeSewing's setup so we can
focus on our core value proposition.
2024-09-28 13:13:48 +02:00
..
readme.mdx

---
title: Part.getId()
---

The `Part.getId()` method will return an integer the can be used as an
for ID Points/Paths/Snippets. This method will ensure the ID is unique by
keeping an internal incremental counter of the IDs that have been used.
It is typically used when programatically adding points, paths, or snippets.

:::tip
This method can be destructured as `getID` 
in [a part's draft method](/reference/api/part/draft).
:::


## Part.getId() signature

```js
int|string getId(prefix='')
```

This method takes an optional parameter that will be used as a prefix for the ID.

## Part.getId() example

```js
cont part = {
  name: 'examples.getid',
  draft: ({ Point, points, getId, part }) => {
    for (let i=0;i<10;i++) {
      points[getId()] = new Point(i*10, i*10)
    }

    return part
  }
}
```