Tweak docs and add a single blog post

This commit is contained in:
Kurt Hutten
2021-04-29 20:55:13 +10:00
parent 5bf8ab266a
commit dc4a7e06de
18 changed files with 451 additions and 182 deletions

View File

@@ -1,11 +0,0 @@
---
slug: hola
title: Hola
author: Gao Wei
author_title: Docusaurus Core Team
author_url: https://github.com/wgao19
author_image_url: https://avatars1.githubusercontent.com/u/2055384?v=4
tags: [hola, docusaurus]
---
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet

View File

@@ -1,17 +0,0 @@
---
slug: hello-world
title: Hello
author: Endilie Yacop Sucipto
author_title: Maintainer of Docusaurus
author_url: https://github.com/endiliey
author_image_url: https://avatars1.githubusercontent.com/u/17883920?s=460&v=4
tags: [hello, docusaurus]
---
Welcome to this blog. This blog is created with [**Docusaurus 2 alpha**](https://v2.docusaurus.io/).
<!--truncate-->
This is a test post.
A whole bunch of other information.

View File

@@ -1,13 +0,0 @@
---
slug: welcome
title: Welcome
author: Yangshun Tay
author_title: Front End Engineer @ Facebook
author_url: https://github.com/yangshun
author_image_url: https://avatars0.githubusercontent.com/u/1315101?s=400&v=4
tags: [facebook, hello, docusaurus]
---
Blog features are powered by the blog plugin. Simply add files to the `blog` directory. It supports tags as well!
Delete the whole directory if you don't want the blog features. As simple as that!

View File

@@ -0,0 +1,295 @@
---
slug: curated-code-cad
title: Curated Code CAD
author: Kurt Hutten
author_title: CadHub Core Team
author_url: https://github.com/Irev-Dev
author_image_url: https://avatars.githubusercontent.com/u/29681384?v=4
tags: []
---
# Curated Code Cad ⚙️ 👩‍🔧
<img src="https://raw.githubusercontent.com/Irev-Dev/repo-images/main/images/CURATED-CODE-CAD-BANNER2.jpg" />
### [See the web page version](https://kurthutten.com/blog/curated-code-cad/)
## What is Code-CAD?
It's software that allows you to define 3D CAD models with code. It's a niche popular amongst software devs for obvious reasons — it gives you parametric models almost by default and it's easy to maintain and extend models within a team over time when paired with git. The coding nature of it allows teams to build their own abstraction for re-use and quick prototyping. The [Cadhub](https://cadhub.xyz/) homepage has a good breakdown of the potential of the Code-CAD paradigm. Code-CAD is not to be confused with 3d geometry libraries, Code-CAD instead has opinionated abstractions for quickly developing mechanical parts.
## Which one should you use?
I recommend reading through the entire list below to see if one chimes with you and your needs, beyond that I can make the following recommendation and points:
<!--truncate-->
- My main recommendation is to use one of the packages that wrap OpenCascade (a mature C++ CAD library). Packages that do so are CadQuery, CascadeStudio, DeclaraCAD and pythonOCC. My reasons for recommending these are as follows:
- Most of Code-CAD tools are plagued with a CSG mindset (that is unions, subtractions and intersections of primitive shapes; cubes spheres etc). This is an inherently limited paradigm (one simple example of this is how internal fillets, which are important for reducing stress concentrations in parts, become very difficult). While CadQuery, CascadeStudio, DeclaraCAD and pythonOCC still offer CSG functionality, you're also able to move beyond it with concepts like lofts and sweeps.
- OpenCascade uses a B-rep (boundary representation) kernel, In my opinion, this means you'll be learning a future-proof tool that won't limit the types of applications you can model for, which is likely the case for mesh kernels, which will cause trouble in for some applications like optics and injection moulding.
- OpenSCAD is tried and true, with lots of examples and tutorials floating around the internet. It also has a very intuitive syntax that many people without prior programming experience have been able to quickly pick up. However, some reasons you might want to look elsewhere are:
- It can be hard to build powerful abstractions since they've rolled their own language. Consequences of this include that it doesn't have a package manager like many modern languages, and the presence of quirks with the language, such as function definitions that aren't ergonomic.
- Performance can start to suffer with complex parts.
- Its mesh-based kernel has limitations if you want to move beyond 3d-printed parts.
- Check out the birdhouse example, while anecdotal, seeing the same part made with three different tools might help you decide which syntax you like the most.
- You might want to simply pick a tool based on your language of choice. Clojure, enaml, Go, Haskell, Lisp, Javascript and Python are all represented below.
- If you want to make 3D art, Curv is specifically trying to hit that niche.
No matter which one is your tool of choice, if you're here and you love Code-CAD and you'll want to checkout [Cadhub](https://cadhub.xyz/). Think of it as Codepen crossed with a thing repository, and it's our love letter to the Maker community. Currently, CascadeStudio is the only Code-CAD integration, but we're working on more. [Site](https://cadhub.xyz/), [repo](https://github.com/Irev-Dev/cadhub).
## Special mention
### [OpenScad](http://www.openscad.org/)
- [Repo](https://github.com/openscad/openscad)
- [Community](http://www.openscad.org/community.html)
- [Docs](http://www.openscad.org/documentation.html)
- License: GPL-2
- ~~Online editor~~
The rest of the packages are in alphabetical order, but OpenScad gets a special mention because it's the OG. Many of the projects below were inspired by OpenScad and is the most well-known choice. If you're new to code-cad this is the safest choice. The syntax is easy to pick up and there lots of guides around the internet.
### [OpenCascade](https://www.opencascade.com/)
- [Repo](https://github.com/tpaviot/oce)
- [Community](https://dev.opencascade.org/)
- [Docs](https://old.opencascade.com/doc/occt-6.9.1/refman/html/index.html)
- License: LGPL-2.1
- ~~Online editor~~
It's a c++ library that a number the projects below wrap. OpenCascade uses a Boundary representation (B-rep) kernel, which is a powerful way representing solid geometry, this is a point of difference for some many of the other projects that use a polygon mesh.
## Contributing
There are a couple of ways you can help:
- Know of a package that we missed? tell us with an issue or open up a PR.
- Contribute a birdhouse design in one of the tools that are missing.
- Do you think we missed an important point for one of the projects, suggest more details.
## Here they are:
### [AngelCAD](https://arnholm.github.io/angelcad-docs/)
- [Repo](https://github.com/arnholm/angelcad)
- [Community](https://forum.abmesh.com/index.php)
- [Docs](https://arnholm.github.io/angelcad-docs/)
- License: GPL-2 or GPL-3
- ~~Online editor~~
AngelCAD aim to do two things:
1) Offer an embedded, but general-purpose scripting language for Constructive Solid Geometry, via [AngelScript](https://www.angelcode.com/angelscript/). This allows for a natural programming style with true variables, user-defined functions and even classes. Programmers should feel at home. See [AngelCAD sample scripts](https://github.com/arnholm/angelcad-samples).
2) Offer a fast boolean engine, which is powered by [Carve](https://github.com/arnholm/carve) is used for this purpose. This means that AngelCAD is generally many times faster than other mesh-based systems.
AngelCAD is capable of running OpenSCAD script for interoperability and has features like text support and DXF import coming soon.
### [bitbybit](https://bitbybit.dev/home)
- [Repo](https://github.com/bitbybit-dev/bitbybit)
- [Community](https://discord.com/invite/GSe3VMe)
- [Docs](https://docs.bitbybit.dev/)
- License: MIT
- [Online editor](https://bitbybit.dev/app)
bitbybit is both a node editor and Code-CAD as they have exposed a [typescript](https://medium.com/@bitbybit/v0-3-0-release-typescript-in-monaco-editor-for-bit-by-bit-developers-46bcb1a3b91) interface that can be used in their app.
### [CadHub](https://cadhub.xyz/)
- [Repo](https://github.com/Irev-Dev/cadhub)
- [Community](https://discord.com/invite/SD7zFRNjGH)
- ~~Docs~~
- License: GPL-3
- [Online editor](https://cadhub.xyz/)
A community hub for sharing code-cad projects. Currently integrates with the excellent [CascadeStudio](https://zalo.github.io/CascadeStudio/). Built and maintained by yours truly.
### [CadQuery](https://cadquery.readthedocs.io/en/latest/intro.html)
- [Repo](https://github.com/CadQuery/cadquery)
- [Community](https://discord.gg/qz3uAdF)
- [Docs](https://cadquery.readthedocs.io/en/latest/intro.html)
- License: Apache, 2.0
- ~~Online editor~~
CadQuery is a Python library that wraps and extends [OpenCascade](https://github.com/tpaviot/oce). It has a philosophy of capturing design intent. The API has been designed to be as close as possible to how youd describe the object to a human. An example of this is its ability to "select" parts of the model's geometry to run operations on, such as the following code that selects only the edges running along the Z-axis and fillets them.
```python
result = cq.Workplane("XY" ).box(3, 3, 0.5).edges("|Z").fillet(0.125)
```
![z edge select example](https://raw.githubusercontent.com/Irev-Dev/repo-images/main/images/Z-edge-select.png)
### [CascadeStudio](https://zalo.github.io/CascadeStudio/)
- [Repo](https://github.com/zalo/CascadeStudio)
- [Community](https://github.com/zalo/CascadeStudio/discussions)
- ~~Docs~~
- License: MIT
- [Online editor](https://zalo.github.io/CascadeStudio/)
A javascript wrapper for [OpenCascade](https://github.com/tpaviot/oce) that runs in the browser. (OpenCascade can run in the browser when compiled to web-assembly). [CadHub](https://cadhub.xyz/) integrates with CascadeStudio.
### [Curv](http://www.curv3d.org/)
- [Repo](https://github.com/curv3d/curv)
- [Community](https://groups.google.com/d/forum/curv) (mailing list)
- [Docs](https://github.com/curv3d/curv/tree/master/docs)
- License: Apache, 2.0
- ~~Online editor~~
Curv is a programming language for creating art using mathematics. Its a 2D and 3D geometric modelling tool that supports full colour, animation and 3D printing. It was inspired by OpenScad and [shadertoy](https://www.shadertoy.com/).
### [DeclaraCAD](https://declaracad.com/)
- [Repo](https://github.com/codelv/declaracad)
- ~~Community~~
- [Docs](https://declaracad.com/docs/introduction/)
- License: GPL-3
- ~~Online editor~~
A declarative parametric 3D modelling program built using [OpenCASCADE](https://github.com/LaughlinResearch/pyOCCT)
and [enaml](https://github.com/nucleic/enaml/).
### [FreeCAD](https://www.freecadweb.org/)
- [Repo](https://github.com/FreeCAD/FreeCAD)
- [Community](https://forum.freecadweb.org/)
- [Docs](https://wiki.freecadweb.org/Getting_started)
- License: LGPLv2
- ~~Online editor~~
FreeCad is a more traditional CAD package that supports python scripting, Both for modelling as well as controlling the FreeCAD GUI itself. Not only that it has a built in [OpenScad workbench](https://wiki.freecadweb.org/OpenSCAD_Module) as well as an external [CadQuery workbench](https://wiki.freecadweb.org/CadQuery_Workbench), making it the best in this list at interoperability. FreeCAD uses OpenCascade under-the-hood.
### [ImplicitCAD](http://www.implicitcad.org/)
- [Repo](https://github.com/colah/ImplicitCAD)
- ~~Community~~
- [Docs](http://www.implicitcad.org/docs/tutorial)
- License: AGPL-3
- [Online editor](http://www.implicitcad.org/editor)
Inspired by OpenScad with a very similar language, implemented in Haskell and includes the ability to write definitions in Haskell, instead of just OpenSCAD, and is part of an 'almost stack' of tools including ExplicitCAD (for a GUI), and HSlice (for an STL slicer).
### [JSCAD](http://www.jscad.xyz/)
- [Repo](https://github.com/jscad/OpenJSCAD.org)
- [Community](https://openjscad.nodebb.com/)
- [Docs](https://openjscad.org/dokuwiki/doku.php?id=jscad_quick_reference)
- License: MIT
- [Online editor](https://openjscad.org/)
JSCAD (formally know as OpenJSCAD) provides a programmers approach to develop 3D models. In particular, this functionality is tuned towards creating precise models for 3D printing.
JSCAD provides the ability to:
- Create and manipulate 3D models, as well as 2D models
- Use JavaScript programming concepts, and libraries
- Save 3D models as STL (and other) formats
JSCAD is available as a:
- [Website](https://www.jscad.xyz/)
- Command line application for backend processing
- User application
- Set of packages (libraries) for building custom applications
JSCAD allows anyone to create 3D (or 2D) designs by combining simple shapes. And any shape can be rotated, moved, scaled, etc. Complex shapes can be saved as parts, which can used later. And the final design can be exported into various standard formats, i.e. STL, DXF, SVG, etc.
### [libfive](https://libfive.com/)
- [Repo](https://github.com/libfive/libfive)
- [Community](https://github.com/libfive/libfive/issues) (Github Issues)
- [Docs](https://libfive.com/examples/)
- License: Mozilla Public License 2.0 and GPL-2 or later
- ~~Online editor~~
Libfive is a software library and set of tools for solid modelling, especially suited for parametric and procedural design. Lisp based language, (so (you (((((can expect ) lots of parentheses))))).
### [pythonOCC](http://www.pythonocc.org/)
- [Repo](https://github.com/tpaviot/pythonocc-core)
- ~~Community~~
- [Docs](http://www.pythonocc.org/category/documentation/)
- License: LGPL-3
- [Online editor](https://mybinder.org/v2/gh/tpaviot/pythonocc-binderhub/7.4.0)
Python-based, Also uses [OpenCascade](https://github.com/tpaviot/oce).
### [RapCAD](https://gilesbathgate.com/category/rapcad/)
- [Repo](https://github.com/GilesBathgate/RapCAD)
- ~~Community~~
- ~~Docs~~
- License: GPL-3
- ~~Online editor~~
Another project inspired by OpenScad. The author considers key differences to be procedural vs functional programming language style, (i.e variables can be modified) and the use of arbitrary precision arithmetic throughout (meaning there are no unexpected double/float rounding errors). There is a handy [feature matrix](https://github.com/GilesBathgate/RapCAD/blob/master/doc/feature_matrix.asciidoc) between RapCAD, OpenScad and ImplicitCad.
### [scad-clj](https://github.com/farrellm/scad-clj)
- [Repo](https://github.com/farrellm/scad-clj)
- ~~Community~~
- ~~Docs~~ (No docs but mirrors openscad functions)
- License: EPL-1.0
- ~~Online editor~~
OpenSCAD DSL in Clojure. Functions generally mirror OpenSCAD, with a couple of notable exceptions.
### [scad-hs](https://github.com/farrellm/scad-hs)
- [Repo](https://github.com/farrellm/scad-hs)
- ~~Community~~
- ~~Docs~~ (No docs but mirrors openscad functions)
- License: BSD-3-Clause License
- ~~Online editor~~
Same author as scad-cji, he likes functional programming languages clearly.
### [sdfx](https://github.com/deadsy/sdfx)
- [Repo](https://github.com/deadsy/sdfx)
- [Community](https://github.com/deadsy/sdfx/issues)
- [Docs](https://godoc.org/github.com/deadsy/sdfx/sdf)
- License: MIT
- ~~Online editor~~
Go-based Code-CAD package that uses a signed distance functions (SDFs) kernel. Is capable of doing fillets and chamfering. The repo includes a [standard-library](https://github.com/deadsy/sdfx/tree/master/obj).
### [SolidPython](https://solidpython.readthedocs.io/en/latest/)
- [Repo](https://github.com/SolidCode/SolidPython)
- ~~Community~~
- [Docs](https://solidpython.readthedocs.io/en/latest/)
- License: GPL-2 or later
- ~~Online editor~~
Python-based library that wraps OpenScad, i.e. it outputs OpenScad code.
### [Tovero](https://www.gitlab.com/kavalogic-inc/tovero)
- [Repo](https://www.gitlab.com/kavalogic-inc/tovero)
- [Community](https://gitlab.com/kavalogic-inc/tovero/-/issues) (Gitlab Issues)
- [Docs](https://gitlab.com/kavalogic-inc/tovero/-/blob/master/README)
- License: LGPL-2.1 or later and GPL-2 or later
- ~~Online editor~~
Tovero is a binding of Libfive to Common Lisp, including a standalone REPL-based viewer. Tovero can be integrated with [Clive](https://www.gitlab.com/kavalogic-inc/clive), a Common Lisp scene graph and 3D GUI, to build more complex modelling applications.
## Node editors / other
Not quiet Code-Cad, but they do embody much of the same thought process.
### [BlocksCAD](https://www.blockscad3d.com)
Looks to be unmaintained.
- [Repo](https://github.com/einsteinsworkshop/blockscad)
- [Community](https://www.blockscad3d.com)
- [Docs](https://www.blockscad3d.com/training-resources)
- License: GPL-3
- [Online editor](https://www.blockscad3d.com)
### [Dynamo](https://github.com/infeeeee/DynFreeCAD)
- [Repo](https://github.com/DynamoDS/Dynamo)
- [Community](https://forum.dynamobim.com/)
- [Docs](https://primer.dynamobim.org/)
- License: Apache 2.0
- ~~Online editor~~
Dynamo is, quite literally, what you make it. Working with Dynamo may include using the application, either in connection with other Autodesk software or not, engaging a Visual Programming process, or participating in a broad community of users and contributors. Works with [FreeCad](https://github.com/infeeeee/DynFreeCAD)
### [MakeCode](https://makecode.buildbee.com/)
- [Repo](https://github.com/buildbee/makecode)
- ~~Community~~
- [Docs](https://makecode.buildbee.com/) (tutorials)
- License: MIT
- [Online editor](https://makecode.buildbee.com/)
MakeCode's block editor supplies many great deal of helpers that make it perfect for making functional 3d prints, for example, there are functions that help stack and layout parts, as well as fillet utils (called styled edges). It also has a fast hull function (called wrap shapes). MakeCode is sponsored by [BuildBee]( https://buildbee.com).
### [Sverchok](https://github.com/nortikin/sverchok)
- [Repo](https://github.com/nortikin/sverchok)
- ~~Community~~
- [Docs](http://nikitron.cc.ua/sverch/html/main.html)
- License: GPL-3
- ~~Online editor~~
Add-on for blender. Sverchok is a powerful parametric tool for architects, allowing geometry to be programmed visually with nodes.

View File

@@ -9,7 +9,7 @@ import clearancePivot from '../../static/img/openscad-tutorial/clearance-pivot.p
import rotate from '../../static/img/openscad-tutorial/rotate.png';
import readScad from '../../static/img/openscad-tutorial/read-scad.png';
Since we've started thinking about how the hinge will be assembled with the pin taper, we also need to think about tolerances and clearance gaps. Because we want this hinge to be a "print in place" which mean it prints pre-assembled, we need to add clearance gaps so that our part doesn't print solid!
Since we've started thinking about how the hinge will be assembled with the pin taper, we also need to think about tolerances and clearance gaps. Because we want this hinge to be "print in place" which mean it prints pre-assembled, we need to add clearance gaps so that our part doesn't print solid!
Let start by adding a `clearance` variable and first thing we need to do is extrude our `hingeBodyHalf` slightly less than `hingeLength/2` since there needs to be some play between the two halves.
@@ -30,6 +30,7 @@ Oh no! there now a gap between our `pin` and `hingeBodyHalf`
Here's the fix for that:
```cpp
// highlight-next-line
hingeHalfExtrudeLength=hingeLength/2-clearance/2;
module hingeBodyHalf() {
@@ -38,7 +39,9 @@ module hingeBodyHalf() {
}
module pin() {
// highlight-next-line
translate([0,pivotRadius,hingeHalfExtrudeLength]){
// highlight-next-line
cylinder(h=hingeLength/2+clearance/2, r1=pinRadius, r2=pinRadius+pinTaper);
}
}
@@ -73,7 +76,7 @@ pin2();
<Image img={rotate} style={{backgroundSize: 'contain'}} />
This is not where we want to leave our pin, but it's a good way to introduce `rotate` as well as using multiple modifiers, i.e. we're using both `translate` and `rotate` together here.
`rotate` is similar to `translate` in that it takes an argument `[x, y, z]` but instead of moving it rotates about each of those axes. In the above example of `[0, 45, 0]` it's as if were were to put a pin into the object along the `y` axis and then rotate 45 degrees around that pin.
`rotate` is similar to `translate` in that it takes an argument `[x, y, z]` but instead of moving, it rotates about each of those axes. In the above example of `[0, 45, 0]` it's as if were were to put a pin into the object along the `y` axis and then rotate 45 degrees around that pin.
## How To Read Chained Operations

View File

@@ -81,3 +81,6 @@ within both of the `linear_extrude`s, at first it might seem like we could remov
<Image img={noFillet} style={{backgroundSize: 'contain'}} />
As it needs to be within `offset` group for this fillet to work.
Okay so we leave it in both `linear_extrude`s but this leaves us in a situation similar to before we introduced variables, in that we have repeated code that would be difficult to determine why to someone reading our code.
Well similar to variables we can solve this with `module`s.

View File

@@ -63,7 +63,7 @@ module plateHoles() {
```
The reason we're using `[0:2]` and not `[0:3]` is because `0` counts so the code still runs 3 times.
I've also introduced another function `echo`, this function can be used to display text to the console, we've added it a a temporary measure to help demonstrate that the code in the `for` loop is run multiple times.
I've also introduced another function `echo`, this function can be used to display text to the console, we've added it as a temporary measure to help demonstrate that the code in the `for` loop is run multiple times.
You should see in the console the following:
```cpp
@@ -119,7 +119,7 @@ module plateHoles() {
<Image img={hole3} style={{backgroundSize: 'contain'}} />
Awesome, it obvious that the hole spacing is related to the length of the hinge now, we can even increase the amount of holes with mountingHoleCount=4; and it look correct:
Awesome, it obvious that the hole spacing is related to the length of the hinge now, we can even increase the amount of holes with mountingHoleCount=4; and it looks correct:
<Image img={hole4} style={{backgroundSize: 'contain'}} />

View File

@@ -97,7 +97,7 @@ And now we can use the pin as both the hole and the shaft, above is the hole, bo
<Image img={bothHalves} style={{backgroundSize: 'contain'}} />
We're still not done with `pin` though! one more thing. Technically we can use the same module `pin` for the hole and shaft, but practically we can't because we having added any clearance between the two.
We're still not done with `pin` though! one more thing. Technically we can use the same module `pin` for the hole and shaft, but practically we can't because we haven't added any clearance between the two.
If we tried to print these together they would print solid.
We can fix this with another argument that makes the hole a bit larger:

View File

@@ -6,8 +6,7 @@ import Image from '@theme/IdealImage';
import pivot from '../../static/img/openscad-tutorial/pivot.png';
Okay so we leave it in both `linear_extrude`s but this leaves us in a situation similar to before we introduced variables, in that we have repeated code that would be difficult to determine why to someone reading our code.
Well similar to variables we can also define our own `module`s to associate some code with a name. Here's what it looks like.
We can also define our own `module`s to associate some code with a name. Here's what it looks like.
```cpp
// highlight-start
@@ -70,7 +69,7 @@ hingeBodyHalf();
## 3D Primitives
Next lets work on the pin, ie. what the other half of the hinge will pivot about.
We're going to introduced a new function `cylinder` and to get in good habits lets put this immediately in a module that describes what we're making.
We're going to introduce a new module `cylinder` and to get in good habits lets put this immediately in a module that describes what we're making.
```cpp
// ... other variables above
@@ -94,6 +93,6 @@ pin();
A couple notes about the above.
- `cylinder` is the 3d version of `circle` when `h` for height is the length that we would need to extrude `circle` by. It can also take one or two radii, here we're using two because it allows us to add a taper to the pin. The reason why we want to add a taper is because we're stating to think about the assemble of this hinge and if we taper the pin it means the other half of the hinge will be locked on.
- `cylinder` is the 3d version of `circle` when `h` for height is the length that we would need to extrude `circle` by. It can also take one or two radii, here we're using two because it allows us to add a taper to the pin. The reason why we want to add a taper is because we're starting to think about the assemble of this hinge and if we taper the pin it means the other half of the hinge will be locked on.
- In order to add the taper we've defined two variables `pinRadius` and `pitTaper` when, the latter is extra we add to the second `cylinder` radius.
- The `translate` is there move the `cylinder` up so that it's centred with the hinge pivot and along so that it's protruding out of the hinge pivot.

View File

@@ -69,7 +69,7 @@ We definitely could, but all of the numbers makes it difficult because it's not
Have you ever walked into a room only to forget why?
You know you came here for a reason but it completely eludes you!? Well reading old code, even only a couple weeks later is a bit like that, you know you put these numbers here for a reason . . .right!
In programming expressing intent in one of the most important principles for making code understandable and remember what we were doing.
In programming expressing intent in one of the most important principles for making code understandable and to remember what we were doing.
Isolated values like the ones in our code so far are commonly called "magic numbers" since we can't tell what they do, they might as well be magical.
Luckily this can be solved by variables. Variables are a way of giving a number a name, so that we can reference that same number over and over again.
This what it looks like in action.

View File

@@ -0,0 +1,124 @@
---
title: Wrap Up
---
import Image from '@theme/IdealImage';
import parametric from '../../static/img/openscad-tutorial/parametric.png';
We're done coding and here's the final code in full:
```cpp
baseWidth=15;
hingeLength=30;
baseThickness=3;
pivotRadius=5;
pinRadius=2;
pinTaper=0.25;
mountingHoleRadius=1.5;
mountingHoleCount=3;
mountingHoleEdgeOffset=4;
clearance=0.2;
tiny=0.005;
// calculated values
hingeHalfExtrudeLength=hingeLength/2-clearance/2;
mountingHoleMoveIncrement=(hingeLength-2*mountingHoleEdgeOffset)/
(mountingHoleCount-1);
// modules
module hingeBaseProfile() {
translate([pivotRadius,0,0]){
square([baseWidth,baseThickness]);
}
}
module hingeBodyHalf() {
difference() {
union() {
linear_extrude(hingeHalfExtrudeLength){
offset(1)offset(-2)offset(1){
translate([0,pivotRadius,0]){
circle(pivotRadius);
}
square([pivotRadius,pivotRadius]);
hingeBaseProfile();
}
}
linear_extrude(hingeLength){
offset(1)offset(-1)hingeBaseProfile();
}
}
plateHoles();
}
}
module pin(rotateY, radiusOffset) {
translate([0,pivotRadius,hingeHalfExtrudeLength+tiny]){
rotate([0,rotateY,0]) {
cylinder(
h=hingeLength/2+clearance/2,
r1=pinRadius+radiusOffset,
r2=pinRadius+pinTaper+radiusOffset
);
}
}
}
module hingeHalfFemale() {
difference() {
hingeBodyHalf();
pin(rotateY=180, radiusOffset=clearance);
}
}
module hingeHalfMale() {
translate([0,0,hingeLength]) {
rotate([0,180,0]) {
hingeBodyHalf();
pin(rotateY=0, radiusOffset=0);
}
}
}
module plateHoles() {
for(i=[0:mountingHoleCount-1]){
translate([
baseWidth/2+pivotRadius,
-baseThickness,
i*mountingHoleMoveIncrement+mountingHoleEdgeOffset
]){
rotate([-90,0,0]){
cylinder(r=mountingHoleRadius,h=baseThickness*4);
}
}
}
}
// using high-level modules
hingeHalfFemale();
hingeHalfMale();
```
Lets reflect on what you've achieved
### Parametric
By diligently using variables instead of hardcoding values, you have create some code that is not only much easier to read and re-use, but it's now parametric by default, which means we can change the value of the variables and the model adjusts
Here are some variations:
<Image img={parametric} style={{backgroundSize: 'contain'}} />
### Composed of many small well named modules
By keeping modules small and making lots of them you've also done a great job of making the code easier to read.
### Included fillets
By taking extra steps to add fillets to you part, you've made the part stronger and already puts you head and shoulders above many OpenSCAD designs.
### Print in place
You've already tackled clearances for getting parts to fit together or print-in-place.
<!-- Now that you up to speed with openscad you might be interested to learn how to host an OpenSCAD project -->

View File

@@ -9,10 +9,6 @@ import plainCube from '../../static/img/openscad-tutorial/plain-cube.png';
import tallCube from '../../static/img/openscad-tutorial/tall-cube.png';
import parametric from '../../static/img/openscad-tutorial/parametric.png';
Ready to learn some openSCAD!?
In order to maximise our learning we're actually going to tackle 3 things, that is feed 3 birds with one scone.
We're going to learn:
@@ -25,11 +21,11 @@ We're going to achieve that by making this cute print-in-place hinge, print in p
<Image img={hinge} style={{backgroundSize: 'contain'}} />
This Tutorial makes no assumption about previous knowledge, which means it fine you you haven't done any programming before, we'll walk you through it.
This tutorial makes no assumption about previous knowledge, which means it's fine you you haven't done any programming before, we'll walk you through it.
If you have done some programming before and prefer a more concise guide that focuses more on OpenSCAD syntax you might prefer the Definitive OpenSCAD Primer instead.
If you came here from "getting started" then you would have already got a shape on screen with `cube([10,10,10]);`.
If you came from elsewhere, open the OpenSCAD desktop app or go to our online editor, and add `cube([10,10,10]);` to get the following cube:
If you came here from "[getting started](/docs)" then you would have already got a shape on screen with `cube([10,10,10]);`.
If you came from elsewhere, open the OpenSCAD desktop app or go to our [online editor](https://cadhub.xyz/dev-ide/openScad), and add `cube([10,10,10]);` to get the following cube:
<Image img={plainCube} style={{backgroundSize: 'contain'}} />
@@ -53,122 +49,3 @@ Before we go any further, now is a good time to mention a couple of principles t
6. If you code isn't working, 9 out of 10 times it's because you are missing a semi-colon `;`, all lines apart from ones with curly brace `}` need to end with a semi-colon.
We'll done, we're done coding and here's the final code in full:
```cpp
baseWidth=15;
hingeLength=30;
baseThickness=3;
pivotRadius=5;
pinRadius=2;
pinTaper=0.25;
mountingHoleRadius=1.5;
mountingHoleCount=3;
mountingHoleEdgeOffset=4;
clearance=0.2;
tiny=0.005;
// calculated values
hingeHalfExtrudeLength=hingeLength/2-clearance/2;
mountingHoleMoveIncrement=(hingeLength-2*mountingHoleEdgeOffset)/
(mountingHoleCount-1);
// modules
module hingeBaseProfile() {
translate([pivotRadius,0,0]){
square([baseWidth,baseThickness]);
}
}
module hingeBodyHalf() {
difference() {
union() {
linear_extrude(hingeHalfExtrudeLength){
offset(1)offset(-2)offset(1){
translate([0,pivotRadius,0]){
circle(pivotRadius);
}
square([pivotRadius,pivotRadius]);
hingeBaseProfile();
}
}
linear_extrude(hingeLength){
offset(1)offset(-1)hingeBaseProfile();
}
}
plateHoles();
}
}
module pin(rotateY, radiusOffset) {
translate([0,pivotRadius,hingeHalfExtrudeLength+tiny]){
rotate([0,rotateY,0]) {
cylinder(
h=hingeLength/2+clearance/2,
r1=pinRadius+radiusOffset,
r2=pinRadius+pinTaper+radiusOffset
);
}
}
}
module hingeHalfFemale() {
difference() {
hingeBodyHalf();
pin(rotateY=180, radiusOffset=clearance);
}
}
module hingeHalfMale() {
translate([0,0,hingeLength]) {
rotate([0,180,0]) {
hingeBodyHalf();
pin(rotateY=0, radiusOffset=0);
}
}
}
module plateHoles() {
for(i=[0:mountingHoleCount-1]){
translate([
baseWidth/2+pivotRadius,
-baseThickness,
i*mountingHoleMoveIncrement+mountingHoleEdgeOffset
]){
rotate([-90,0,0]){
cylinder(r=mountingHoleRadius,h=baseThickness*4);
}
}
}
}
// using high-level modules
hingeHalfFemale();
hingeHalfMale();
```
Lets reflect on what you've achieved
### Parametric
By diligently using variables instead of hardcoding values, you have create some code that is not only much easier to read and re-use, but it's now parametric by default, which means we can change the value of the variables and the model adjusts
Here are some variations:
<Image img={parametric} style={{backgroundSize: 'contain'}} />
### Composed of many small well named modules
By keeping modules small and making lots of them you've also done a great job of making the code easier to read.
### Included fillets
By taking extra steps to add fillets to you part, you've made the part stronger and already puts you head and shoulders above many OpenSCAD designs.
### Print in place
You've already tackled clearances for getting parts to fit together or print-in-place.
Now that you up to speed with openscad you might be interested to learn how to host an OpenSCAD project

View File

@@ -3,29 +3,33 @@ title: Getting Started
slug: /
---
To get started click the "+" button on the top right of CadHub
import Image from '@theme/IdealImage';
import plus from '../../static/img/getting-started/plus.png';
import plus from '../../static/img/getting-started/plus.jpg';
import openscadSelect from '../../static/img/getting-started/openscad-select.jpg';
import ide from '../../static/img/getting-started/ide.png';
import cube from '../../static/img/getting-started/cube.jpg';
import hinge from '../../static/img/getting-started/complete-hinge.png';
To get started click the "+" button on the top right of CadHub
<Image img={plus} style={{backgroundSize: 'contain', paddingBottom: '2rem'}} />
<Image img={plus} style={{backgroundSize: 'contain', paddingBottom: '2rem', width: '400px', margin: '0 auto'}} />
Then select OpenSCAD. Note that [CadQuery](https://cadquery.readthedocs.io/en/latest/) is available too, but OpenSCAD is recomended and the rest of this tutorial is based on OpenSCAD.
<Image img={openscadSelect} style={{backgroundSize: 'contain', paddingBottom: '2rem', width: '300px', margin: '0 auto'}} size={300} />
You should now see the OpenSCAD IDE (integrated development environment)
<Image img={ide} style={{backgroundSize: 'contain'}} />
Here we should see the default code in the editor on the left-hand-side, there editor is where we design our CAD parts and we'll cover that more soon. You will also see the result will show up on the right-hand-side along with the console which gives us extra information too. You can click and drag inside the viewer to change the perspective, though the image will only update once you let go of the mouse.
Here we should see the default code in the editor on the left-hand-side, the editor is where we design our CAD parts and we'll cover that more soon. You will also see the result will show up on the right-hand-side (along with the console which gives us extra information). You can click and drag inside the viewer to change the perspective, though the image will only update once you let go of the mouse.
You can also move the object with with right-click and drag, and scrolling will zoom in and out.
### What about the editor?
For that we'll need to learn about the OpenSCAD language. For now, try replacing all of the existing code with `cube([10,10,10]);` and then hit ctrl+s to tell CadHub to render a new image. You should see a cube appear!
For that we'll need to learn about the OpenSCAD language. For now, try replacing all of the existing code with `cube([10,10,10]);` and then hit `ctrl + s` to tell CadHub to render a new image. You should see a cube appear!
<Image img={cube} style={{backgroundSize: 'contain'}} />

View File

@@ -6,3 +6,7 @@ title: Why OpenSCAD
OpenSCAD is a Code-CAD, which means models are made from a code script rather than from a series of clicks in a user interface.
If you want an un-bias opinion on if this is a good paradigm you'll have to look elsewhere because CadHub are massive advocates for it.
A quick run down is that you get all the benifits of git version control. It makes reusing cad logic with a team much easier, and if you think of CAD models as a communication medium between colleagues and machine, what better way of storing it than in an auditable script.
We're going to learn OpenSCAD now over [the alternatives](/blog/curated-code-cad) because not only is it very mature and stable, it's also easy to pick up. Let's get started!

View File

@@ -15,6 +15,7 @@ module.exports = {
'definitive-beginners/modifiers',
'definitive-beginners/module-arguments',
'definitive-beginners/loops',
'definitive-beginners/wrap-up',
// {
// type: 'category',
// label: 'OpenSCAD tutorial',

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

BIN
docs/static/img/getting-started/plus.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 194 KiB