2021-10-17 18:26:00 +02:00
|
|
|
---
|
|
|
|
title: Part.getId()
|
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2021-10-17 18:26:00 +02:00
|
|
|
A part's `getId()` method will return an integer the can be used as an
|
2021-09-25 17:53:09 +02:00
|
|
|
ID Points/Paths/Snippets. This method will ensure the ID is unique be
|
2021-10-17 18:26:00 +02:00
|
|
|
keeping an internal record of the ID that have been used.
|
2021-09-25 17:53:09 +02:00
|
|
|
It is typically used when programatically adding points, paths, or snippets.
|
|
|
|
|
|
|
|
## Part.getId() signature
|
|
|
|
|
2021-08-25 16:09:31 +02:00
|
|
|
```js
|
|
|
|
int part.getId(prefix='')
|
|
|
|
```
|
|
|
|
|
2021-09-25 17:53:09 +02:00
|
|
|
This methiod takes an optional parameter that will be used as a prefix for the ID.
|
|
|
|
|
|
|
|
## Part.getId() example
|
|
|
|
|
|
|
|
```js
|
|
|
|
export default function (part) {
|
|
|
|
const { Point, points } = part.shorthand()
|
|
|
|
|
|
|
|
for (let i=0;i<10;i++) {
|
|
|
|
const id= part.getId()
|
|
|
|
points[id] = new Point(i*10, i*10)
|
|
|
|
}
|
|
|
|
|
|
|
|
// You would do more useful stuff before returning
|
|
|
|
return part
|
|
|
|
}
|
|
|
|
```
|
2021-10-17 18:26:00 +02:00
|
|
|
|
|
|
|
|