Custom Components

Creating Components via Markup

It’s easy to create custom components via the HFD markup language. Simply add a custom_component attribute to any component. The new component will be available via the import attribute on the document

Example:

Here is a simple line component:

It requires the attributes to and from when being imported

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 {
     "parts": [
         {
             "components": [
                 {
                     "type": "draw",
                     "custom_component": {
                         "type": "line"
                     },
                     "commands": [
                         {
                             "command": "move",
                             "to": "from"
                         },
                         {
                             "command": "line",
                             "to": "to"
                         }
                     ]
                 }
             ]
         }
     ]
 }

Then to access the new component, simply import it and use it.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 {
     "imports": [
         {"path": "designs/common/line.hfd"}
     ],
     "params": {
         "material_width": 20,
         "material_height": 12,
         "material_thickness": 0.2,
         "width": 2,
         "height" 3
     },
     "parts": [
         {
             "id" : "line_example",
             "components": [
                 {
                     "type": "line",
                     "from" : "width,height",
                     "to" : "width / 2,height / 2"
                 }
             ]
         }
     ]
 }