1
0
Fork 0
freesewing/sites/dev/docs/tutorials/pattern-design/part2/our-first-part/readme.mdx

89 lines
2.3 KiB
Text
Raw Normal View History

---
2023-09-28 09:11:06 +02:00
title: Creating a part
sidebar_position: 20
---
2022-02-20 14:35:50 +01:00
Much like garments themselves, patterns are made up of _parts_.
Most patterns will have multiple parts. A sleeve, a back part, the collar, and
2023-09-28 09:11:06 +02:00
so on. The pattern you create today is very simple, and only has one part: the bib.
:::tip
2023-09-28 09:11:06 +02:00
It's a good idea to keep each part in its own file. You don't _have to_ do
this, but it's a good habit to get into.
2023-09-28 09:11:06 +02:00
:::
## bib.mjs
I am going to use the **From scratch** template. So the files I want to edit live
2023-09-30 14:04:18 +02:00
in `design/from-scratch`.
2023-09-30 14:04:18 +02:00
Our part lives in `design/from-scratch/src/bib.mjs`, and it currently looks like this:
2023-09-30 14:04:18 +02:00
```src/bib.mjs
function draftBib({ part }) {
return part
}
2023-08-08 13:20:46 -05:00
2023-09-28 09:11:06 +02:00
export const bib = {
2023-09-30 14:04:18 +02:00
name: 'fromscratch.bib',
2023-09-28 09:11:06 +02:00
draft: draftBib,
}
```
2022-02-19 08:04:25 +01:00
2023-09-30 14:04:18 +02:00
## The part object
2023-09-28 09:11:06 +02:00
Each part in FreeSewing is an object that describes the part, and has a `draft`
method to do the actual work of drafting the part.
The only mandatory keys on a part object are `name` and `draft`.
2022-02-19 08:04:25 +01:00
:::note RELATED
2023-09-28 09:11:06 +02:00
Refer to [the part reference documentation](/reference/api/part) for
all details about configuring the part object
:::
:::note
2023-09-28 09:11:06 +02:00
A design in FreeSewing is a thin wrapper around a collection of parts.
Each parts stands on its own, and parts from various designs can be combined
to create other designs.
:::
2023-09-28 09:11:06 +02:00
2023-09-30 14:04:18 +02:00
### The part name
2023-09-30 14:04:18 +02:00
```src/bib.mjs
name: 'fromscratch.bib',
```
2023-09-30 14:04:18 +02:00
A part's `name` should be unique in a design. I used `fromscratch.bib` as the
2023-09-28 09:11:06 +02:00
name, because that makes sense.
:::warning
2023-09-28 09:11:06 +02:00
I **strongly** recommend that you apply the same `designName.partName` naming scheme in all your parts.
This avoids naming conflicts when mixing parts from various designs to create a new design.
:::
2023-09-30 14:04:18 +02:00
### The part's draft method
2023-09-30 14:04:18 +02:00
```src/bib.mjs
draft: draftBib,
```
The second mandatory key on the part object is `draft` which should hold the method that drafts the part.
2023-09-28 09:11:06 +02:00
In the example above, it refers to the `draftBib` function that was defined at the top of the same `bib.mjs` file.
For now this function doesn't do much, but that will change soon enough.
:::note
This structure of putting the draft method at the top of the file and
the part object at the bottom is a bit of a convention in FreeSewing.
:::
We'll take a deeper look at our part's draft method soon. For now, let's look at adding measurements to our part.