You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Clean, readable code is one of the most important aspects of a useful design. In that respect, it can often be useful to break your code into simple function that do part of the work for your design:
51
35
```javascript
52
-
import { primitives } from'@jscad/modeling'
53
-
const { cylinder } = primitives
36
+
import { cylinder } from'@jscad/modeling'
54
37
55
38
consthex= (radius, height) => {
56
39
returncylinder({radius, height, segments:6})
@@ -63,8 +46,7 @@ export const main = () => {
63
46
## Re-usable Designs
64
47
A valuable practise when creating models is to store all but the most trivial values as parameters in the code, rather than using the numerical values directly. This can be done by storing them in constants in your file...
65
48
```javascript
66
-
import { primitives } from'@jscad/modeling'
67
-
const { cylinder } = primitives
49
+
import { cylinder } from'@jscad/modeling'
68
50
69
51
constoptions= {
70
52
height:5.1,
@@ -78,10 +60,10 @@ export const main = () => {
78
60
79
61
... or, even better, to include runtime parameters in your design. This is done using the getParameterDefinitions function:
80
62
```javascript
81
-
import { primitives } from'@jscad/modeling'
82
-
const { cylinder } = primitives
63
+
import { cylinder } from'@jscad/modeling'
83
64
84
65
// Declare a function named "getParameterDefinitions". It will return an array of parameter definitions.
66
+
// You must also export the getParameterDefinitions function.
Copy file name to clipboardExpand all lines: jsdoc/tutorials/05_importingFiles.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,11 @@
1
1
Importing files in JSCAD is a simple case of loading them using the same import statement used to load javascript modules. The files you load need to be part of a multifile project, so that JSCAD can access them:
0 commit comments