https://github.com/fogleman/sdf
One big plus to doing it this way is that it's "just" Python and you can use arbitrary logic to help construct your model.
You can even load an existing 3D mesh and operate on it as an SDF. Great for hollowing, chopping, eroding/dilating, etc. existing models.
I should probably do more with this project. I think there's a lot of interest in this space.
I recently also got annoyed with OpenSCAD and its limitations and therefore started experimenting with Build123d. I'm very much a beginner in the CAD space and would love to understand what inspired you to build sdf.
My basic understanding is that STL files are essentially like Bitmap images and store a list of triangles and their positions, whereas STEP files are more like Vector art where there is a list of instructions on how to build the model. Most CAD GUI programs also operate on a similar model to vector art where they record a list of operations one on top of another. It's why STEP files are a standardized format and can be imported / exported from most GUI based CAD builders. I think.
Given that SDF also seems like it builds only STL files (I could be wrong), wouldn't learning build123d or CadQuery work better if one cares about compatibility with existing GUI based CAD modeling software?
Additionally, atleast build123d offers a similar conceptual model to using Fusion360 and FreeCad - I have limited experience here - but essentially you sketch something in 2D on a particular plane, and then apply some operations to convert it to 3d in a particular manner - the simplest being extruding. This means the mental modeling of how to construct something is very similar across both GUI based CAD programs and Build123d, and that makes it easier for me to jump between GUI based and code based CAD modelling.
I'd love to understand your point of view, and learn more.
Like most of my projects, this was just for fun and I mainly made it for myself. I'm a DIY kind of guy when it comes to software. I just throw things up on GitHub in case anyone else can get some use or inspiration out of it.
Honestly I was about to ask the same questions as the parent comment. Whenever I'm interested in something I usually look at what available tools exists out there already; seeing a new tool mentioned that I've never heard of before, my reflex is to ask "oh neat, what makes it different than the existing tools?". I don't think the question was ill-intended, just genuine curiosity; assuming that you wrote your library because you had no idea build123d existed rather than because you were unsatisfied with it and wanted to tackle the problem differently is a bit of a leap.
Something like two precisely interlocking gears with a tooth geometry with a profile that's the developed curve of the opposite tooth is a nightmare to build with SDFs
Or precise fillets.
Or hard intersections and differences.
Very useful for doing soft, squishy shapes, less so for hard CAD.
Also, a suggestion: in your project, please consider using Wavefront OBJ as an output format, it is a much, much better choice than STL (STL can't represent the actual topology of the object, it has to be reconstructed).
This has my instant interest. Multiple times I have wanted to take an existing .STL file and cut a hole on it or add another object to it and have never had success.
I've tried things like Meshlab, but while the interface has what appears to be a hundred different functions, attempting to use anything returns some error code that requires a PhD to understand and none of the "repair" functions seem to help.
I mean seriously: Mesh inputs must induce a piecewise constant winding number field.
How the hell am I supposed to accomplish that on a STL file?
In freecad you first just open the stl file, then Part -> Create part from mesh, then you have a solid you can modify.
intersection() { import("3DBenchy.stl"); sphere(30); }
If you have the paid version of Fusion, you can run "feature detection" to turn things like holes, fillets, extrusions etc. into dedicated features which are even easier to edit. [2]
[1] https://www.autodesk.com/learn/ondemand/curated/direct-model...
[2] https://www.autodesk.com/learn/ondemand/curated/direct-model...
https://github.com/fogleman/sdf/blob/main/examples/mesh.py
You basically just say:
f = Mesh.from_file(path).sdf(voxel_size=0.25, half_width=1)
Then you can operate on `f`.
Removing faces from an STL and adding other objects is quite straightforward. Previously, Autodesk had Meshmixer and 123D, I guess Meshmixer is still available: https://meshmixer.org/ and I found it to be great for quick editing of the type you're describing.
https://pythonscad.org/examples.php
(search for "sdf" about halfway down the page)
What do you use for sdf meshing? I never really got the perf where I wanted it.
> I should probably do more with this project.
I, for one, would be glad.
I would really recommend using the git master than the latest release though. The last release was 2021 but they are still actively working on it and it's much faster now.
I also have to recommend the BOSL2 library which means you don't have to implement all of those one million features from typical CAD software yourself. Its definitely got a bit of a learning curve but the fact that you can always default back to vanilla OpenSCAD and that you can actually see how stuff is implemented makes it much more satisfying to me to learn than learning what all the traditional CAD GUI buttons do.
I love OpenSCAD. I've been 3D printing for a while, but I never really got to a place where I could design interesting parts until I started to get the precision of doing models in code. Sometimes it is slower, for sure.
Every time I've used as a CAD GUI program I would get to this point where I would need to alter a single dimension by 0.25mm and realize that _all_ of my fastener holes, cutouts, etc have to be nudged with the keyboard or mouse to accommodate it. The input devices lack precision for that kind of task, and having to repeat the operation dozens of times (or bulk select) gave me a terrible sinking feeling, and I'd often just step away and give up on the design at that point out of frustration. I try to approach everything in OpensSCAD in a way that means I never have to experience that feeling again.
I will also say that doing everything from scratch in OpenSCAD would be it's own special kind of hell. Libraries like [BOSL2](https://github.com/BelfrySCAD/BOSL2) provide a good set of core ideas and preferences that help set you on a good path. A good example: BOSL2 shapes tend to have a "center origin" by default, which is different than the OpenSCAD default, but makes doing transforms later way easier.
Anyway, happy to see OpenSCAD getting some attention here :)
There seems to be some fundamental misunderstanding of CAD here. I can't imagine how you could even design something in CAD in a way that you would end up in this situation.
When I'm doing something more sophisticated I use SolveSpace, but I'm a lot slower with that.
SolveSpace is open source and has parametric capabilities. It's much more limited in scope (e.g. you can't do filets) but good enough for my purposes.
I've not explored the commercial options beyond TinkerCAD, and that's not parametric. Super easy to bodge something together though :)
Are all CAD programs parametric or make their parametric functionality obvious? If not, that's how you end up in this situation.
What.
This makes no sense. This isn't PowerPoint; your holes and cutouts are supposed to be parameterized. How are they even supposed to be at the proper position in the first place?
As a CAD user, this is like e.g. a coder seeing someone write code with global variables everywhere.
I'm not doing complex character model designs, I'm usually building functional prints like enclosures or cases. It certainly sounds like there are features of better CAD software that makes parametric the default?
But OpenSCAD isn't really parametric CAD. It's a programming language; it's parametric for that reason. But it's not really CAD, at another level, in the sense that it does nothing to "aid" your design work. It has no interim abstraction for generated geometry; everything must be explicitly described.
FreeCAD, though, is profoundly parametric, through and through, and really always has been. Indeed the parametric aspects are the main thing that made it workable before the TNP mitigations were added. It is not a limited CAD package, by any means. It's just a somewhat unfriendly one with a CAD kernel that has some limitations. Really it's almost better understood as a 3D IDE with some workflow affordances.
If you are stuck trying to get your head into how FreeCAD works, there are now three really good ways on Youtube: the Mango Jelly Solutions videos are incredible, the Shawn Hymnel/Digikey FreeCAD and 3D Printing course is good, and there are great recent videos by Deltahedra.
But what you will be able to make with it, once you get your head into it, is night and day different to what is possible with OpenSCAD. Because your parametric work in FreeCAD (or other CAD packages) can operate on the geometry of the result of previous operations.
Give it a try in the New Year with FreeCAD 1.1 when it is released.
If you want another stepping stone from OpenSCAD to FreeCAD or any other package, I really recommend you look at CadQuery/Build123D. This will give you a similar coding approach but it will introduce you to operations on the true faces, edges and vertexes of the output of other operations.
(FWIW I would not say that Sketchup is not high end, either. It's not to my tastes but it is quite powerful)
Dune 3D seemed quite promising, but very limited --- is there a set of options for the UI in FreeCAD which will create a similar interface?
Now, if the random crashing were fixed, that would make a real difference for me...
That mode works OK on touchscreens, in the sense that any app with tiny buttons to click does. I have tried using a tablet with a pen but it is a heavily modal UI so it feels a little bit like old fashioned light pen territory, as much CAD does. Not like an iPad app; they need designing differently.
Quite a lot of progress on macOS FreeCAD crashes because they changed an exception handling strategy for exceptions outside the Qt loop, if I remember right. Some crashing in 1.1RC that is being fixed. In general it crashes a whole lot less than it did in 0.20, say. But if you can reproduce them, definitely report them.
(Which is not to say that I am not pleased to see more open source CAD packages taking different approaches. Dune3D is interesting, Blobfish's Cadseer is very interesting to a coder I'd have thought, and SALOME has obvious value)
The one small tweak I would suggest for FreeCAD is to use the tab bar workbench selector rather than the dropdown version. It’s such a small change but it helps flow between things in a way that feels like the various functions are more closely integrated. That, combined with custom panels if you want them, makes it more fluid.
(I am not making any particular claims for FreeCAD's usability; I do though think it is much better and much more learnable than the average HN perspective of it, which seems to often come across more as TUI-exceptionalism or "but I don't wannnnnaaa learn a guuuuuuuiiii". GUI CAD isn't intrinsically some inferior, imprecise, unformalised thing.)
Maybe this is pedantic, but why wouldn't OpenSCAD qualify as CAD exactly? It's still "Computer-Aided Design"? Sure, the UI/UX is different, but is there some qualifier to CAD around the UI/UX?.
CAD is software to help people make complex things without having to do complex geometry/trig/general maths.
OpenSCAD doesn't really "aid" you much with this. It's a 2D/3D shape generator with boolean operations, but because it doesn't let you do constraint operations on 2D geometry, and it doesn't let you do further operations on the fundamental geometry (faces, edges, vertices) of the generated 3D solids either, it never liberates you from most of the difficult work.
I'm not even sure how much it aids you with "design": it doesn't support chamfers or fillets, it offers no tools for adding drafts or making truly uniform thicknesses. And it only generates meshes.
OpenSCAD is useful. I'm not saying it's not. But it is useful mostly for drawing strongly geometric or mathematically-derived solids and producing a mesh from it.
At least you've inspired me to try it and see if it's "worth writing home about"
I often switch between FreeCad and Dune3d now, Freecad for things I know how to design properly and Dune when I'm in 'claying' mode. E.g. export a .step part when I get stuck in FreeCad, import it into Dune, make some progress and vice versa so I don't walk away from the project
For example, if you put a hole in a box, do you want to reference the center of the sides of the hole? And do you want to place them relative to the left side or right side, and front or back? You never say "it's x mm from the left and y mm from the right and my box is w mm wide" - because the relationship x+y=w is always here! You only define 2 out of 3. But it may happen that you picked the wrong 2 - and a parametric CAD makes it very easy to do so in a few clicks, while a programmatic CAD like OpenSCAD is a large rewrite with calculation you have to do yourself on the side.
My example is silly but start doing big designs, large assemblies, and you "chains of cotations" may need to be redone again and again - especially when tolerances begin to add up.
I had the change the height of an entire enclosure to accommodate a taller than anticipated PCB, and simply edited the sketch at the top of my design tree that defined the overall dimensions.
It took about 5 minutes to adjust the odd broken fillet and change some mates in assembly and it was done. No fidgety mouse movements. I actually do a lot of mech design on a laptop with a trackpad, arrow keys for view changes and numeric dimensioning for 95% of everything else.
I am just starting to learn CAD and FreeCAD - also dabbled a bit in OpenSCAD. But I do know that FreeCAD has Spreadsheets [1] and Configuration Tables [2] which allows you to define your model parameterically and changes values as needed.
How good this is, I don't know yet.
[1] https://wiki.freecad.org/Spreadsheet_Workbench [2] https://wiki.freecad.org/Configuration_Tables
The little-known Configuration Tables aspect of Spreadsheets is absolutely worth using, though, and has no equivalent in the VarSets scheme at this point. Once you get that set up it is great fun.
I can see how you would end up in that position
You need to add constraints to your sketches. In other words tell it that the hole needs to be x distance from certain lines.
If you don't do that what you get is the equivalent of hard coding a hole location in OpenSCAD. I guess OpenSCAD just forces you to think parametrically.
Also in fusion 360 make sure timeline editing is on.
As an example, consider a bar with a constrained length, e.g. 1000mm. I want holes in the bar every 100mm (not a strange requirement). Now I change the length constraint to 800mm. Consequently, the number of holes should change. But this seems not possible in a "parametric" modeler. Maybe I'm missing something, though.
Thats surprising! Last time I used software like this (Inventor, back in ~2005-2006) constraints meant that I didn't need to do this at all
This. The master version is so much further ahead of the last tagged version. The render time can be orders of magnitude faster for more complex models.
or with Homebrew you can do `brew install --cask openscad@snapshot` to install the latest snapshot version.
Or, browse all the snapshot builds here: https://files.openscad.org/snapshots/
(as of this comment, the last snapshot build is from yesterday)
It is a useful tool for programmatically describing either very simple or heavily geometric objects. For everything else it's the wrong tool.
OpenSCAD clearly qualifies because it creates precise 2D/3D models; supports parametric modification; enables reproducible designs; produces manufacturable geometry (STL, DXF, etc.). The fact that it is code-based does not disqualify it. By the same logic, CadQuery, SolidPython, or FeatureScript would also not be CAD - which is not a position held in engineering practice.
CadQuery, Build123D, Featurescript etc. all have something OpenSCAD does not have: they all have facilities to operate on generated geometry such as edges, faces and vertices. So they have generalisable operations, and they can output pure geometry representations as STEP/IGES. Featurescript presumably also allows access to sketch constraints. (Build123D is beginning to add those I think.)
These are the things I think are necessary to “aid” design, because they are the things that begin to abstract away the mathematics. OpenSCAD never does. So it “aids” design little more than any pixel graphics library aids 3D software developers.
And it does not, in fact, create precise 3D models! It produces mesh representations of them. So it cannot, by definition, produce a precise representation of a cylinder, sphere, cone or curve.
The 3D models from OpenSCAD are not highly manufacturable at all, except with additive production techniques. STLs do not make good inputs for a CNC (nobody will tell you that is good engineering practice).
https://www.cnccookbook.com/meshcam-great-ease-of-use-in-a-3...
But I think we agree that mesh formats don't make good engineering interchange outside additive manufacturing.
Personally I think they often make a bad format even in additive manufacturing. They are the right format for medical/dental, and yes, slicers make internal STL-ish mesh representations of STEP etc. before slicing, but they are much harder to modify precisely than STEP.
People will reasonably choose not to publish their original designs but can only publish STL because of OpenSCAD, Blender and because of the free tier of commercial CAD.
And having the OpenSCAD source doesn't help that much; you can modify it but you are still stuck with STL. OK so FreeCAD can reinterpret some — not all — OpenSCAD operations in a bRep context. But it's not a great way to work; it doesn't really help much with interchange.
I absolutely have had to modify STL files for people because that is the only interchange format the designer made available to them, or even could make available because they used the wrong tool for the job (like Fusion's free tier). At this point there are many STL-folk-song designs out there, CC-NC, with bad geometry, non-centred exports, etc.
Thankfully there are ways, in core FreeCAD and in a third party workbench (MeshRemodel), to more easily extract and reconstruct some key geometry from a mesh, such that parametric modifications can be made. (Whereas with OpenSCAD you're basically stuck with cut-out-and-roughly-refill).
https://openscad.org/cheatsheet/
Note that updating it is one of the blockers for a new release, so it doesn't include some newer features/syntax
There is also:
https://cubehero.com/2013/11/19/know-only-10-things-to-be-da...
FWIW, when I need to rough something out in OpenSCAD, I usually use:
Pro tip: Use the latest nightly build and switch to the Manifold backend in preferences. Render times drop from minutes to seconds for complex models. The official 2021 release is painfully outdated.
Also, the BOSL2 library is essential - it adds proper filleting, rounding, and attachment operations that vanilla OpenSCAD lacks. Makes the difference between toy projects and actually useful designs.
The Git-friendliness is underrated too. Diffing .scad files is trivial compared to trying to understand what changed in a binary Fusion 360 file.
The awful thing about OpenSCAD is that what one can model in 3D is limited by one's ability to mathematically stretch, rotate, and/or arrange spheres, cylinders, and cubes in 3D.
For folks who want "real" (read mutable in normal terms of scope) variables there is a Python-enabled fork (which should become part of the main release presently:
You can use modules to create a semblance of relative measurements but you still cannot do things like “attach this surface of object A to that surface of object B)”. In practice this means that if you want to create something like a spacer or a bracket you can do that easily enough. But if you want to make a part that matches some real world design you are stuck doing a lot of caliper measurements and math to try to create a part that lines up correctly. The you 3D print it and find that you positioned some hole based on its edge and not center and so nothing quite fits.
OpenSCAD is easy to start but difficult to scale because of these limitations and because once you hard-code any measurement you are stuck with it. The “proper” way to do this is to give everything a variable but honestly that makes reasoning about how to line things up even more difficult. “Does base_width include the width of the vertical walls? What about the margin to make the parts fit together?”
I have never been able to understand how things like FreeCAD lay out their UI. TinkerCAD is relatively simple but clearly a lot less powerful. I did try cadquery which solved a lot of OpenSCAD’s issues by having all offsets be relative by default but also introduces a few issues of its own.
One tip I will give about OS: grab a copy of the latest beta/dev release. The renderer is several orders of magnitude faster.
(Post author here.)
This was a very weird thing to me I ran into and have thus far just sort of... accepted.
In Fusion, and other CAD software, if I have two faces end at the same point, unless I've specifically said to create them as separate bodies, they are joined, because they share a plane.
In OpenSCAD, in the tutorial, it has you extend an object 0.001 to ensure they overlap. To quote:
> In the example above, the second cube sits exactly on top of the first cube. This is something that should be avoided, as it’s not clear to OpenSCAD whether the two cubes form one object together. This issue can be easily solved by always maintaining a small overlap of about 0.001 - 0.002 between the corresponding objects. One way to do so is by decreasing the amount of translation along the Z axis from 10 unit to 9.999 units.
This struck me when making the example in my post. In line 47 I specifically add 1 to heightCompartment to ensure the opening extends past the top of the main body. If I didn't do that, this happens during preview: https://imgur.com/a/Amc1dK6 (That's an exported image from the latest nightly of OpenSCAD.)
But it doesn't happen during the actual render?
Still, that just feels... like there's something going on with a floating point value or something which, programatically, is probably correct... But from the perspective of someone trying to design something feels Very Wrong. Because I have a 20mm high box, I subtract a 19mm high box from it, starting 1mm up from the base. Why shouldn't the top be open? Why is it acceptable for it to be maybe kinda open but broken by design?
I still don't /like/ it because it seems I'll need to add in some sort of 0.001mm overlap into the code if I want to ensure this doesn't become a problem. And this feels like a messy way to go about it.
Sure you can, but openscad is an imperative language so you need to do it in an imperative manner.
a_cube_loc = [10, 5, 5];
a_cube_size = [2, 4, 1];
b_cube_loc = [a_cube_loc[0], a_cube_loc[1] + a_cube_size[1], a_cube_loc[2] ];
b_cube_size = [2, 4, 1];
translate(a_cube_loc) cube(a_cube_size);
translate(b_cube_loc) cube(b_cube_size);
It would be nice to have more declarative constraints. The solvespace file format is plain text and it almost feels like you could write it by hand, but that would be a lot of manual record keeping. and you would loose all that imperative goodness. Perhaps you could have an imperative layer(say python or lisp or forth) that outputs the declarative layer(solvespace) and then solvespace renders(picture or stl) the declarative layer.Manifold backend also eliminates the need to avoid coincident faces.
I'm 100% with you there. One of the most utterly confusing UI I've had to deal with.
And I suspect the answer is : the FreeCAD devs don't either.
It also has hulls and minkowski sums, which are powerful once you understand them.
So, spheres and cylinders and cubes placed, rotated, stretched and placed mathematically.
A minkowski sum, as far as I understand it, requires a surface and a volume and returns a volume.
Example 1: apply hull() to a star shape
Example 2: You want to fold a picture (SVG) around a cylinder and make its edges FDM printable by 45 degree overhang, apply a cone to the image
If you wish to use Rust for 3D modeling directly there is:
(the developer of which is actually working on a BREP kernel)
Which avoids using the OpenSCAD language, but also means you can't use BOSL2. Might as well use FreeCAD.
If you are coming from SolidWorks, Fusion360, Inventor, or OnShape, it won’t take long before you start finding that there are a lot of things missing from it.
There is a problem though - sometimes what you want requires deep understanding. It's less user friendly, polished, and documented. That's also relevant to the performance - it's easy to cause performance issues. But I remember the same was also applicable to Fusion.
It's _not_ something which was designed for ease of use, or rational semantics, or to facilitate expression.
Thanks for this, didn't know about it.
How does that compare to solid python 2?
Rather then adding an additional compile cycle:
- run Python code to generate OpenSCAD code
- render OpenSCAD code to see output
OpenPythonSCAD creates a .py code window in the OpenSCAD interface which one interacts with in the same way as a .scad code window (there's even basic support for the Customizer).
I suspect it would be really easy to port SolidPython to work w/in OpenPythonSCAD (if it hasn't already been done)
(3D printing a sacrificial gear for a seat position adjustment mechanism)
Not at all. You can build any polyhedron you want using the polyhedron command.
Which would be an enormous pain to write out by hand every time, but I wrote a function once upon a time to generate a polyhedron from a stack of layers, each of which is a list of points, and haven't had to mess with old cubes and spheres since.
One annoying thing is that the default way of writing programs in OpenSCAD uses 'modules', which are a bit limited compared to functions (you can't store them as values to to functions or other modules). I worked around that by writing a module that interprets arrays (think S-expressions) that representing the shape, and then just build up that S-expression-like thing with functions and whatever.
Once you've built your own programming language inside OpenSCAD it's perfectly usable. :-)
This might sound like sarcasm but I actually do prefer this to dealing with Python's mutable state jungle / package management nightmare.
This sounds _fascinating_ have you posted your code or written this up in a math journal? Link?
I don't touch polyhedrons in OpenSCAD because the logic of point placement mystifies me --- a tool such as you describe would make life a lot easier for a lot of folks, esp. if there was a way to use it to import a series of SVG files which could be used to define the points interactively.
I sometimes wonder if the key to future computer usage would be a series of Domain Specific Languages each intended for a given task:
- 3D == OpenSCAD
- 2D == METAPOST
- SQL == databases
- TeX == text/page composition
- sed == text
(and yes, I know this is the Unix ideal)
but such languages seem to be most successful and most approachable to typical users when they are paired with a front-end which affords editing, previewing, and, direct interaction.
I'm actually nuking my Python install right now, because I got it into a state where I couldn't get Fullcontrol G-code to run, so I agree that the state of Python package population is pitiful, hence of course, the XKCD:
I wrote about the approach a little bit in this Reddit post: https://www.reddit.com/r/openscad/comments/186b54r/interpret...
The interpreter itself is just a single module: https://github.com/TOGoS/OpenSCADDesigns/blob/master/2023/li...
Instead it's basically like graphics programming, with a couple of basic primitives, some linear transformations and a bit of set theory. When I do a model a month and get back to previous work, I read a few lines of code and know exactly how I achieved the result.
I also have the opposite experience about understanding previous scripts. Unless it's dead simple I'm usually thinking why the hell did I multiply this thingy by sqrt(3)/2 plus this other thing. Maybe a documentation problem, but it's inescapable that sometimes you need a lot of math for what are trivial constraints in an interactive sketch. A real CAD program will let you roll back to any feature to figure out how it's constructed step by step so there's really nothing to decipher.
I know this is not typical, and nothing against folks who see it the other way. But OpenSCAD fits the way I think and want to work better than the more “normal” tools.
but it has real problems - the language is weird and unfortunate. not anything super fatal, just the obvious product of evolution that would be more cohesive if it were architected wholesale
epsilons are really unfortunate. you have to expect that after getting what you want in the whole, you're going to have to scan over the whole thing and look for cracks or collision where there shouldn't be
performance is quite sad. here you are happy going back and forth between the view and text windows, but as you go on, it starts taking .. minutes.. to update the view once you have a reasonably complicated geometry
high-level operators would also be nice. I made the mistake of using a thread library once, not only did that make my model unrenderable, there was so much noise in the model and the manufacturing process I had to make 3 expensive test prints in sintered nylon to get the fit right. (I'm thinking an annotation on a cylinder that says 'standard 1mm thread')The same model in freecad is like 6 megs of zipped xml and realistically not nearly as usefully parametric.
That couple-k of plain text is such a huge deal that it makes all the other difficulty worth it for mechanical/functional stuff.
I just wish it had operations for subtractively chamfering, rounding, etc. as doing minkowski() with cones and spheres to achieve that result can be unwieldy.
Over time I added other things like a single linear fillet, a single radial fillet, both interior and exterior, convenience things built out of those like a screw post with a fillet base etc. But really I always end up just using mirror_copy and rounded_cube a lot.
There is a scifi book series aboit a programmer who gets zapped into a fantasy world that has magic, and he becomes the most powerful wizard in the world because he applies the coding concept of reusable components and building big things out of smaller things and automation, which none of the other wizards ever thought of.
openscad is like that. To get anywhere you first have to build a library of useful higher level things out of the low level things. Like forth or assembly, or really all programming I guess.
cuboid([20, 20, 30], chamfer=5);
Fusion is great for that as long as there's not too many parts. But sometimes I'll want a new variant or a series of new variants.
And reaching for python makes that easy.
Currently I'm playing with a gear library which is part of BOSL2 (https://github.com/BelfrySCAD/BOSL2/wiki/gears.scad), to make something to rotate a polariser in my microscope.
The power of parametric cad is such that I wouldn't be a 10th as productive using an interactive cad system. And because it is effectively software you are writing (even if it compiles into physical objects) you can use all of the goodies that you can use to manage software. Diff files, git, kompare, branching, merging. It is nothing short of amazing, it is like I have a design team and a prototype injection molding facility in one. And the turnaround time is something you'd have killed for in the 90's.
This sounds like parametric and interactive CAD are polar opposites. Normal CAD software is generally parametric too.
The other points about the advantage of text files still applies though.
There are cad packages that can do this but unlike OpenSCAD the main interaction there is the 3D window, not the text editor.
Though AutoCAD of course had this with AutoLISP since 1986.
Interestingly, I'm not sure which has the steeper learning curve, OpenSCAD or AutoLISP. OpenSCAD is really great once it clicks but most people give up long before then.
Two 3D CAD tools which seem to be focused on ease-of-use are:
- Dune 3D --- this has been discussed here a couple of times (I think I posted the two most active posts elsethread)
- Moment of Inspiration --- created by the developer who created the program Rhinoceros 3D was based on and who was the lead developer for that program for years, it focuses on ease of use and apparently started with the idea of making a CAD Program suited to use on a computer pen tablet --- there's a video series: https://www.youtube.com/playlist?list=PLUilfM8GEmrS3yRLygdFO... which makes it seem very approachable
Mathematica however is Lispy enough and has a lot of helpful geometry primatives and can export STL
That's because you wrote a for-loop without braces, so it can only contain a single statement, and that single statement is your let().
Here is an equivalent way to write that section of code (and I did test it):
for (r = [ 1 : numRows ]) {
startColumn = ((c * thicknessWall) + ((c - 1) * batteryType));
startRow = ((r * thicknessWall) + ((r - 1) * batteryType));
translate([startColumn, startRow, thicknessWall])
cube([batteryType, batteryType, heightCompartment + 1]);
}
Side note, related to declaring variables but not an issue that you encountered: OpenSCAD does not allow setting the value of a variable more than once. So this code is illegal: x = 1;
echo(x);
x = 2;
echo(x);
Second note is that whenever you introduce a construct such as {union(), difference(), if(), for()}, variables declared within the braces are scoped, so they don't exist between iterations or after the scope ends. if (true) { y = -1; }
echo(y); // Illegal
However, just introducing braces without a construct does not restrict the variable to the scope: { z = 5; }
echo(z); // Legal