1
0
Fork 0

fix(markdown): Restructure part reference. See #2981

This commit is contained in:
Joost De Cock 2022-10-18 21:00:50 +02:00
parent b4eb7e7b00
commit ac7b5befce
10 changed files with 105 additions and 110 deletions

View file

@ -0,0 +1,37 @@
---
title: Part.getId()
---
The `Part.getId()` methid 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).
</Tip>
## Part.getId() signature
```js
int|string getId(prefix='')
```
This methiod 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
}
}
```