I want to write a CAD program, what would be a good place to start. Libraries/frameworks etc? (C++ or Python)

Red Squirrel

No Lifer
May 24, 2003
68,788
12,783
126
www.anyf.ca
As title, I want to write a CAD program, nothing super crazy fancy, just something where I can draw lines in a 3D space, specify faces, make various modeling transforms like extrusions etc then export to Gcode or STL etc. Basically I need to be able to interact with a 3D space and create objects that can then interact with each other by clicking on them or selecting them and so on.

I'm kind of leaning towards python as GUI stuff is most likely going to be much easier to do with tkinter etc, vs C++ where you need like 500 lines of code just to draw a window but C++ may also have a better performance advantage. The nice thing with Python is the app should in theory be cross platform, but I am aiming for Linux. I may also do a client-server model, where the server is C++ and all the calculations are handled there, and the GUI is more thin and just talks with the server. But those are details I will figure out as I go. I'm mostly wanting to figure out the best approach for the GUI part and any libraries I should look into.

I'm not worried yet about the math involved in creating transforms, I will cross that bridge when I get there, and it will not be easy as math is not my thing, but for the time being I mostly want to get a basic interface going where I can draw lines, create basic objects and click on them to then trigger actions on that object. So any recommendations of directions to go?

There is a big lack of user friendly CAD programs when it comes to Linux, so I want to write this for myself as it would be nice to get into 3D printing and what not, but at same time I feel there is a gap to be filled and I may as well fill it. I've been pondering on starting a major coding project anyway so this may be the one.
 

purbeast0

No Lifer
Sep 13, 2001
53,139
6,029
126
Do things like the Unreal Engine work for Linux?

I wrote a little game a while back using it and it was pretty easy to get into 3D space and just move around and put things in 3D space. I started it out in Javascript but quickly changed it to C# because the 3rd party libraries I was using all integrated better/easier with C#. This was like 6 years ago though so it could have changed drastically since then.
 

mxnerd

Diamond Member
Jul 6, 2007
6,799
1,102
126
Writing your own 3D software is a daunting task. And don't think you can use Python alone. Use existing software and make some adaptation might be better route.

===

Searched.



Looks like 2D only. Not updated for 10 years.


 
Last edited:
  • Like
Reactions: marcus0

mxnerd

Diamond Member
Jul 6, 2007
6,799
1,102
126
If you were talking about horrible Blender UI before 2.7, it seems been fixed in 2.8 or you can use Bforartists, a Blender fork.


 
Last edited:

purbeast0

No Lifer
Sep 13, 2001
53,139
6,029
126
I'm with @mxnerd on this. If you think you are just going to write your own CAD software in your spare time, you are in for a rude awakening. My first job out of school was developing CAD software and it is a huge piece of software.
 

Red Squirrel

No Lifer
May 24, 2003
68,788
12,783
126
www.anyf.ca
Blender is not what I'm going for, that is more for free hand modeling and is very powerful for what it does, but it's not really meant for CAD unless you are 3D printing stuff that does not really need precision. If you want actual precision where you can type in numbers so the line is the exact length you want, and want things like snap, etc you really need CAD where you can draw things to specific dimensions etc. Though whatever libraries Blender uses would probably work, I can look into what they use.
 

robvas

Member
Jun 18, 2018
37
6
41
Do something 2D first to get the hang of it. Shouldn’t take you more than a week or two to get a 2D editor going. I threw a rough Doom level editor together pretty quickly on the Mac, and I kind of want to write a 3D editor of some sort next.
 

Red Squirrel

No Lifer
May 24, 2003
68,788
12,783
126
www.anyf.ca
Yeah that would be the plan, do 2D to get the general idea going, then go 3D.

I also forgot about Ogre, which is a 3D C++ engine, I may look into that to see if it can be adapted for CAD. Ex: a 3D space window that has toolbars and such. It's more geared towards games but it's also fairly general purpose, I don't think it's considered a game engine.

The biggest thing for me is being able to click to start a line, and type a number and it makes the line that size, along with angle snaps, point snaps, that sort of thing. Drag and drop stuff like lines and shapes, Being able to select a bunch of lines, copy, move, mirror, group them.. all basic functions like that. None of the Linux CAD programs have this and make those operations very convoluted. Eventually I would add 3D capabilities but at first I would concentrate on 2D, but still want to use a 3D engine so I'm not rewriting everything when I do 3D. Essentially my goal would be a very basic version of like Autocad2000 style functionality. I'm not even considering things like fluid or motion dynamics or anything like that, I know some of the more advanced CAD programs can do it.

But ya may look at Ogre and using C++... another approach I was thinking is a C++ back end server that does all the logic stuff and calculations, and a python front end that just displays if I can find a good 3D library for python as I imagine it will be easier to write in that language. Or heck maybe even web based. Javascript/html etc. I know there's lot of stuff you can do in the browser now. If I recall Google sketchup runs in the browser.

I have lot of small projects I need to start/finish before It take on this one though. This would basically be a near full time project for quite a while before I get it to where I like. I don't expect this to be something I can just whip up in a couple months or even a year. Probably longer.
 

piokos

Senior member
Nov 2, 2018
554
206
86
What is the aim of this project, though?

You want to write a functional, usable CAD program? Because you really think you'll write something better than existing projects?
Or do you want to develop your skills in 3D-related problems?

In both cases, starting a project from scratch just doesn't make much sense and is seriously against how software is developed in the Internet era.
If you start with the GUI and user interactions, you'll be bored and exhausted before you start coding CAD manipulations.
If you start with CAD, you'll probably end up with a very limited script-based program.

We got this far in software development precisely because people STOPPED coding everything on their own.

Look how massive FreeCAD is:

You don't like it - maybe start contributing?
 
  • Like
Reactions: mxnerd

mxnerd

Diamond Member
Jul 6, 2007
6,799
1,102
126
Unless you want to become a graphics programmer, really don't understand your point for the project.

After some search, if you don't like OpenSCAD or FreeCAD, etc., probably the best alternative is Google Sketchup + it's STL extension.

Download old but free SketchUp 8.0 here


How to Install SketchUp 8 on Linux

Install one of the STL extension


==

 
Last edited:
  • Like
Reactions: marcus0

piokos

Senior member
Nov 2, 2018
554
206
86
I'm kind of leaning towards python as GUI stuff is most likely going to be much easier to do with tkinter etc, vs C++ where you need like 500 lines of code just to draw a window but C++ may also have a better performance advantage. The nice thing with Python is the app should in theory be cross platform, but I am aiming for Linux.
A few words just to touch the GUI issue - totally aside of the earlier opinion that writing this from scratch is a loss of time. :)

You shouldn't be worried about a window in C++ requiring "500 lines", because why write them on your own? Use an IDE with a graphical creator for the GUI.
Someone else already did it and countless other people worked on that code to make it as robust and bug-free as possible.
If you write everything yourself, you'll just repeat the errors that someone else made 10 years ago. And since this will (apparently) be a private project, no one will help you fix them.

CAD editor will need a pretty complex interface and going Python and Tkinter will make it unbearably slow.
As in most cases (at least on Linux) your best bet is Qt. Or if you want something more modern and niche, check Kivy.
I may also do a client-server model, where the server is C++ and all the calculations are handled there, and the GUI is more thin and just talks with the server. But those are details I will figure out as I go. I'm mostly wanting to figure out the best approach for the GUI part and any libraries I should look into.
Now, this is probably the most interesting part of your post and it makes this project at least valuable as a skill-developing exercise.

But don't waste your time on a standalone GUI client in Tkinter or whatever. Just do it as web app.
FreeCAD has an API that you could use - instead of writing your own CAD software, which is an enormous task even for a team doing this as a day job.
You can always extent FreeCAD if you're missing some features.

Very good examples of how such an application should work are:
- Sketchup - originally a very popular free app, later commercialized. Free plan is cloud-based and really fun to use (with enormous user community).
- Onshape - clearly designed for pros from the start and very expensive, but there's a free plan if you want to try it.

This is the kind of project I'm talking about:
The author wants to run FreeCAD in a container and expose it via a browser.
I don't know if he completed this and if it's any good. But this looks like a good example of how to set up the general framework.
 
  • Like
Reactions: VirtualLarry

Red Squirrel

No Lifer
May 24, 2003
68,788
12,783
126
www.anyf.ca
The main issue with all the CAD programs in Linux that I've tried including Freecad is the lack of intuitivity. Everything requires tons of clicks and manual fiddling around. In freecad you can't even select stuff and copy/move it or quickly draw a line and specify the length on the fly by typing while still dragging the line. Everything is manual by editing properties of each line and you're doing everything one by one. It's honestly easier to use a pencil and paper and a ruler than it is to use any of these programs.

So my goal is something that is actually going to be user friendly and intuitive to use and be quick to draw out stuff, and change it. But yeah maybe I won't use python it was just an idea, I may look at C++ and using Ogre as the framework or something.

I may look at the browser approach too. The hardest part is the GUI, the back end won't be as bad, so if I can use some kind of browser based open source framework for it I could save lot of time and effort.
 
  • Like
Reactions: amd6502

piokos

Senior member
Nov 2, 2018
554
206
86
The main issue with all the CAD programs in Linux that I've tried including Freecad is the lack of intuitivity. Everything requires tons of clicks and manual fiddling around. In freecad you can't even select stuff and copy/move it or quickly draw a line and specify the length on the fly by typing while still dragging the line. Everything is manual by editing properties of each line and you're doing everything one by one. It's honestly easier to use a pencil and paper and a ruler than it is to use any of these programs.

So my goal is something that is actually going to be user friendly and intuitive to use and be quick to draw out stuff, and change it.
But the whole point of CAD is the precision you're criticizing.
Some CAD suites are more user-friendly than FreeCAD, but none of them is optimized for quick and easy model creation. It's more about precise, incremental changes.
People create models in CAD when they want something to be manufactured or numerically analyzed.

I think you may be looking for a convenient 3D modeling software, not CAD.
Seriously, try Sketchup. It's super fast to use. And with the STL export plugin it's good enough even for casual 3D printing.
 

Red Squirrel

No Lifer
May 24, 2003
68,788
12,783
126
www.anyf.ca
You can still have precision and make it user friendly though. AutoCAD does this, but it's subscription based now days so not really an option, and it does not run in Linux anyway. I want to get away from having to rely on VMs and stuff. For example if you want to make a line that is exactly 5.5 units long you click to start your point and drag in the direction you want, let it snap to an angle if you want, then type in "5.5" and boom, you have a line, then you can make another, and another etc.. it's real quick. You want to later on change it, you can click and drag, or copy it etc. None of the Linux CAD programs let you easily do any of that. They just lack the intuitivity of being able to use the mouse and keyboard to quickly make/change things.

But anyway this post was about looking for directions to go to start coding one, not to find an alternative or be discouraged from it.
 

Red Squirrel

No Lifer
May 24, 2003
68,788
12,783
126
www.anyf.ca
The javascript libary looks interesting at quick glance. This is the sort of thing I was looking for. I'm not nececerily dead set on python or C++ it was just initially what I had in mind. The more I think of it, I kinda do want to lean on the client-server approach now. I can do the server in C++, and GUI stuff client side in browser.
 

amd6502

Senior member
Apr 21, 2017
971
360
136
That's an awesome endeavor and I hope you get underway soon and make a lot of progress.

I've wanted a simple easy to use architectural 2D CAD tool to sketch out rough floorplan ideas for YEARS. Something that just did a few very basic and useful tasks:

1. Rectangles with the option of specifying both dimensions by text input (aside from the approximate input by mouse).

2. Lines and Double Lines (walls) with option to specify length and angle by text input.

3. Text for annotation

4. Cut and Paste of Objects

5. Undo/Redo

6. Ability to Save work to file.

7. Ability to export canvas to either pdf file or very high resolution image.
 
  • Like
Reactions: Red Squirrel

piokos

Senior member
Nov 2, 2018
554
206
86
You can still have precision and make it user friendly though.
Sure. But it'll never be as fast and easy as normal 3D modeling suites. CAD is about precision.
AutoCAD does this
AutoCAD is nice to use for the same reason Lightroom is nice to use - compared to FOSS alternatives. Because there's an army of people taking care of the UI/UX.
I want to get away from having to rely on VMs and stuff.
Why? This is a foundation of computing today. And we're not going back.
For example if you want to make a line that is exactly 5.5 units long you click to start your point and drag in the direction you want, let it snap to an angle if you want, then type in "5.5" and boom, you have a line, then you can make another, and another etc.. it's real quick.
That's how 3D modeling programs work (seriously, try Sketchup).

CAD is more about: you want to move that line slightly left or add a little curvature - and check how it affects the model.
You want to later on change it, you can click and drag, or copy it etc. None of the Linux CAD programs let you easily do any of that.
Because why would they?

I mean, seriously, in your posts you've mentioned a few ways you would like to use a program (or how you think it should look).
None of that screams "CAD". Why are you so attached to the idea? Why not use something that is design to be fast and easy?

They just lack the intuitivity of being able to use the mouse and keyboard to quickly make/change things.
Absolutely.

I've just found a good analogy. CAD programs are a bit like (La)Tex. And you want them to be as easy to use as MS Word. :)
But anyway this post was about looking for directions to go to start coding one, not to find an alternative or be discouraged from it.
Which brings me to the original suggestion. Don't write this yourself. You'll waste way too much time on basic things.

Why aren't to considering contributing to some open project? You're against the idea or what?
That would let you work on what you really want to do.
 
  • Like
Reactions: VirtualLarry