1
0
Fork 0
freesewing/markdown/dev/reference/api/part/getid/en.md
2022-02-19 08:04:25 +01:00

753 B

title
Part.getId()

A part's 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.

Part.getId() signature

int part.getId(prefix='')

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

Part.getId() example

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
}