Replies: 4 comments 1 reply
-
A simple approach how to achieve a concept like boilerplates is using the snippet functionality in your favorite editor. See https://www.geeksforgeeks.org/how-to-create-the-boilerplate-code-in-vs-code/ for an explanation how to create boilerplates in vs-code. A document like my Replicad quick reference guide (see https://github.com/raydeleu/ReplicadManual/blob/main/replicad-qrc.adoc) could be translated into small snippets of code. Instead of using copy and paste from the quick reference document or typing the code the user can search for a snippet by its name and enter an example piece of code into his/her own code. There are also some downsides to this approach:
|
Beta Was this translation helpful? Give feedback.
-
For sure there needs to be a global repository for discovery. But even more important is there needs to be established practices of naming for said discovery. "makeX" should always return a solid. "sketchX" should always return a sketch. etc. I'm really in favor for making all these functions having the same behavior as the I suggest we start by creating a new repository called "RER" (replicad extensions repository) and setting a few moderators which vet incoming code and organize the repository along with other users. |
Beta Was this translation helpful? Give feedback.
-
My idea would be to rely on the fact that we are using webtechnologies. Ideally we should be able to import modules share by others directly: import addYears from "https://unpkg.com/[email protected]/esm/addYears/index.js"; For instance in the case of a module share on npm, or even just a script save in github (or a gist). This should not be logic that is specific to replicad, but something that uses the (already existing) infrastructure of the web. This make at the same time replicad a better citizen of the web by using its standards, as well as avoiding to limit ourselves to things made in the replicad environment. I have played a bit with it, but there are a couple of roadblocks so far (some more solvable than others). But this is something definitely worth doing! |
Beta Was this translation helpful? Give feedback.
-
By module I meant javascript modules - a simple way to import code made by other people, but supported by the technology in the browser. I have played with it and now you can write something like this: /* global replicad */
/** @typedef { typeof import("replicad") } replicad */
import { makeFlatHinge } from "https://cdn.jsdelivr.net/gh/sgenoud/replicad-hinges@418e11f2a9b712ca4754b889c6847fa750c018c8/main.js";
const { drawRoundedRectangle } = replicad;
export const defaultParams = {
boxWidth: 120,
boxHeight: 80,
boxDepth: 6,
wallThickness: 1,
};
/** @type {function(typeof defaultParams): any} */
export default async ({ boxWidth, boxHeight, boxDepth, wallThickness }) => {
const base = drawRoundedRectangle(boxWidth, boxHeight, 5)
.sketchOnPlane()
.extrude(wallThickness);
const top = drawRoundedRectangle(boxWidth, boxHeight, 5)
.sketchOnPlane()
.extrude(boxDepth + wallThickness)
.shell(wallThickness, (f) => f.inPlane("XY", boxDepth + wallThickness));
const { hinge, hingeWidth } = makeFlatHinge(
boxDepth + 2 * wallThickness,
20,
wallThickness
);
return hinge
.clone()
.translateX(boxWidth / 4)
.fuse(hinge.clone().translateX(-boxWidth / 4))
.fuse(base.clone().translateY(hingeWidth + boxHeight / 2))
.fuse(base.translateY(hingeWidth + boxHeight / 2))
.fuse(top.translateY(-hingeWidth - boxHeight / 2));
}; What is different with modules for the visualiser:
Why does this encourages code reuse? You can see that I import something from jsdelivr. This is a way to import my code that lives in GitHub (a print-in-place hinge library, still a work in progress but good enough for the current example) that you can find here: https://github.com/sgenoud/replicad-hinges (I need to us jsdelivr to be able to load the code). Note that I still need to iron out some kinks (and wishes that Firefox supported the technologies need here) and want to have a way to create module that can be imported directly in a script, or shared via npm (for bigger projects). |
Beta Was this translation helpful? Give feedback.
-
Something that came to my mind while analysing the code that was used to prepare a model of a plug with "grips" to create a tight fit (see #36 (comment))
The value of the Replicad concept is that a user can take functions, prepared by a different user to enhance his/her model. The "grip" idea used in this model has certain elements in it that - when generalized - are very useful to other users. For example, the function to create a radial array is interesting and can be used for all kinds of patterns. Another is the idea to create a small protrusion to create a tight fit.
In this example I would think that the solution envisaged by @lf94 using lofts would already be more generally applicable. It would also work on rectangular plugs, not only circular ones. I assume that it would also solve the difficult calculation of the rotation angle for the grip-cylinders. And using a standard loop instead of a mapping function to create a circular array where you can adapt the number of grips would be wider applicable and easier from a user perspective.
The questions then are:
Beta Was this translation helpful? Give feedback.
All reactions