2021-10-17 18:26:00 +02:00
---
2023-01-06 19:29:29 -08:00
title: Our first part
2021-08-25 16:09:31 +02:00
order: 120
2021-10-17 18:26:00 +02:00
---
2021-08-25 16:09:31 +02:00
2022-02-20 14:35:50 +01:00
Much like garments themselves, patterns are made up of _parts_ .
2022-10-09 23:47:32 +02:00
Most patterns will have multiple parts. A sleeve, a back part, the collar, and
so on. Our pattern is very simple, and only has one part: the bib.
2021-08-25 16:09:31 +02:00
2023-01-06 19:29:29 -08:00
It's a good idea to keep each part in its own file. We don't *have to* do
this, but it's a good habit to get into. When we create more elaborate designs
2022-10-09 23:47:32 +02:00
with multiple parts, keeping each in its own file makes for a more tidy
2023-01-06 19:29:29 -08:00
and approachable code base.
2021-08-25 16:09:31 +02:00
2022-10-09 23:47:32 +02:00
## bib.mjs
2021-08-25 16:09:31 +02:00
2022-10-09 23:47:32 +02:00
The previous step has already set everything up for us. Our design's main file
lives in `design/src/index.mjs` , and our part lives in `design/src/bib.mjs` .
2021-08-25 16:09:31 +02:00
2023-08-06 14:00:10 +00:00
This `bib.mjs` is where we'll do all our work. The file includes a basic guide on how to use it. We removed it for clarity in our example. It currently looks like this:
2021-08-25 16:09:31 +02:00
2022-10-09 23:47:32 +02:00
```design/src/bib.mjs
2023-08-06 14:00:10 +00:00
function draftBib ({
part, // Your draft method must return this
})
{
// Work your magic here
2022-10-09 23:47:32 +02:00
return part
}
export const bib = {
2023-08-06 14:00:10 +00:00
2022-10-09 23:47:32 +02:00
name: 'tutorial.bib',
2023-08-06 14:00:10 +00:00
draft: draftBib,[],
from: false,
hide: {
self: false,
from: false,
after: false
},
options: {},
measurements: [],
optionalMeasurements: [],
plugins: []
2022-10-09 23:47:32 +02:00
}
2021-08-25 16:09:31 +02:00
```
2022-02-19 08:04:25 +01:00
2022-10-09 23:47:32 +02:00
### The part object
2021-08-25 16:16:51 +02:00
2022-10-09 23:47:32 +02:00
Each part in FreeSewing is an object that describes everything there is to know about the part.
2021-08-25 16:09:31 +02:00
2022-10-09 23:47:32 +02:00
The only mandatory keys on a part object are `name` and `draft` .
2022-02-19 08:04:25 +01:00
2022-10-09 23:47:32 +02:00
< Related >
Refer to [the part reference documentation ](/reference/api/part ) for
all details about configuring the part object
< / Related >
2021-08-25 16:09:31 +02:00
2022-10-09 23:47:32 +02:00
#### The part name
2021-08-25 16:09:31 +02:00
2022-10-09 23:47:32 +02:00
```design/src/bib.mjs
name: 'tutorial.bib',
2021-08-25 16:09:31 +02:00
```
2022-10-09 23:47:32 +02:00
A part's `name` should be unique in a pattern. Apart from that, anything goes.
2023-01-06 19:29:29 -08:00
Although we probably want to give it a sensible name.
2021-08-25 16:09:31 +02:00
2023-01-06 19:29:29 -08:00
As we can see in the example above, we're using `tutorial.bib` as the name.
2021-08-25 16:09:31 +02:00
< Tip >
2023-01-06 19:29:29 -08:00
We **strongly** recommend that you follow this `design.part` naming scheme to avoid
2022-10-09 23:47:32 +02:00
naming conflicts when mixing parts from various designs to create new designs.
< / Tip >
2021-08-25 16:09:31 +02:00
2022-10-09 23:47:32 +02:00
#### The part's draft method
2021-08-25 16:09:31 +02:00
2022-10-09 23:47:32 +02:00
```design/src/bib.mjs
draft: draftBib,
```
2021-08-25 16:09:31 +02:00
2022-10-09 23:47:32 +02:00
The second mandatory key on the part object is `draft` which should hold the method that drafts the part.
2021-08-25 16:09:31 +02:00
2022-10-09 23:47:32 +02:00
In our example above, it refers to the `draftBib` function we defined at the top of the file.
For now this function doesn't do much, but that will change soon enough.
2021-08-25 16:09:31 +02:00
2023-01-06 19:29:29 -08:00
< Note >
2022-10-09 23:47:32 +02:00
This structure of putting the draft method at the top of the file and
2023-01-06 19:29:29 -08:00
the part object at the bottom is a bit of a convention in FreeSewing.
2022-10-09 23:47:32 +02:00
< / Note >
2021-08-25 16:09:31 +02:00
2022-10-09 23:47:32 +02:00
## index.mjs
2021-08-25 16:09:31 +02:00
2022-10-09 23:47:32 +02:00
< Tip >
Feel free to skip to [Adding
measurements](/tutorials/pattern-design/adding-measurements) if you're itching
to get started. Or, read on for an explanation of what's going on in the
`index.mjs` file.
< / Tip >
2022-01-19 11:31:39 +01:00
2022-10-09 23:47:32 +02:00
The `index.mjs` file is already complete and we won't be making any changes to
it. But for those who are curious about what's going on inside `index.mjs` ,
we're including a version with comments below:
```design/src/index.mjs
/*
2023-01-06 19:29:29 -08:00
* Import the `Design` constructor
2022-10-09 23:47:32 +02:00
* from the FreeSewing core library
*
2023-01-06 19:29:29 -08:00
* This Design constructor is a method
* (also known as a function)
2022-10-09 23:47:32 +02:00
* that creates a new Design
*/
import { Design } from '@freesewing/core '
/*
* Import the `bib` part from the bib.mjs file
* in the same folder as this index.mjs file
*
2023-01-06 19:29:29 -08:00
* This is the part we'll be working on
2022-10-09 23:47:32 +02:00
* in this tutorial
*/
import { bib } from './bib.mjs'
/*
2023-01-06 19:29:29 -08:00
* Create a new Pattern by passing
2022-10-09 23:47:32 +02:00
* a configuration object
2022-12-03 16:34:38 +01:00
* to the Design constructor
2022-10-09 23:47:32 +02:00
*/
const Pattern = new Design({
/*
2023-01-06 19:29:29 -08:00
* This `data` key is optional, but we
2022-10-09 23:47:32 +02:00
* typically add a name and version here
*/
data: {
2023-08-06 14:00:10 +00:00
name: "Tutorial",
2022-10-09 23:47:32 +02:00
},
/*
* This `parts` key is the most important thing
* It holds a list of `parts` for our Design.
2023-01-06 19:29:29 -08:00
* A Pattern/Design is in the end not much more
* than a collection of parts.
2022-10-09 23:47:32 +02:00
*/
parts: [ bib ],
})
/*
* We are exporting our Pattern
* (so others can use it)
* but we also (re-)export our bib part
2023-01-06 19:29:29 -08:00
* this allows others to re-use it
2022-10-09 23:47:32 +02:00
* in their own designs
*/
export { bib, Pattern }
```