Multibody parametric drawings, some early work

Hello devs and users,

I want to share with you something specific that I made for my graduation and which may be useful to someone.

So what to begin with… 9 or so months ago and I was pretty sure that FreeCAD is more than enough for me to complete my mechatronics engineering project, fulfilling my goal to graduate using entirely OSS tools. I may have been way too optimistic, because about month and a half later, after all the drawing and calculations were done, I realized that the TechDraw module is not suited for complicated drawings, and most importantly, lacks any support for multibody assemblies and parametric model changes.

Needless to say, that was a catastrophe. With only a month or so left until my graduation and no sane way to get the drawings out of FreeCAD, I started to panic. (Actualy no sane way to do it in any other software, except to start from the ground up. FreeCAD appears to be working with the BREP blazingly fast, even compared to commercial software and my models were already overcomplicated.)

So after a painful recap, I had a new goal - to postopne my graduation and code something into FreeCAD so I can get my drawings done solely with OSS tools.

After an extensive forum research, I came to the conclusion that there is some great advance in terms of architectural drawings and single-body drawings (and I made use of the latter), but almost zero is done about multi-body mechanical drawings, assemblies and such.
And because of my huge previous SolidWorks experience and influence, I wanted to have some very specific features while able to sacrifice some other for the “next stages”.

I made a quick list of required tools in the early summer days, wrote it on a sticky note and stuck it to my laptop until everything was mostly done. Ended up using a set of python scripts and macros.
This is what I have implemented as absolutely needed for the toolset:

First of all, I find the TechDraw workflow kinda backwards - the 2D lines (which are absolutely correct!) are generated immediately after you create a drawing, voiding any useful 3D or parametric information, and only after that you can annotate the different parts. The huge flaw I see here is that you have to wait for ages until the whole geometry is flattened, but you end up using only a small part of it and if you have to change the geometry later, you’re back to zero. This is a tedious task for a single body, but for multiple bodies, fasteners and all their relations, it’s pure masochism.

My approach, parallel to what SolidWorks does, was to create the whole drawing in the CSG stage with relations to the CSG models and then export the 2D drawing with all the annotations, effectively splitting the implementation in two - The visual parametric representation and the code that generates the final drawing. So any model changes are recalculated immediately on the drawing, leaving the hours of waiting for the final export for the very end.

Secondly, I wanted to have a 3D lookaround of the drawing, exactly like in SolidWorks, because there are always some very hard to pick lines and dimensioning them is hell without a proper selection.

I sticked to the 3D Inventor View for that part, keeping the whole drawing plane coincident to the X-Y 3D plane. And because the whole drawing is volumetric, selection and orientation are really easy. Ultimately, there should be some core change where the rotation would be normally locked, but now that’s up to the user.

Thirdly, TechDraw treats the drawings inherently as a single body simply because when you section them, there is only one kind of hatch for the whole section, I guess due to lack of functionality. Truly a no-go for the mechanical engineer.

My approach here was to associate a different hatch with every unique solid, that’s able to survive a recomputation or a major change of the assembly. And I ‘mostly’ succeeded, at least not worse than SolidWorks I think.

Fourth, something that was bugging me, was that acording to the ISO drafting standards, all annotations should read from the bottom and right part of the page, but in FreeCAD the labels are oriented mostly at random.

While implementing the (very) basic dimensioning, took that into account.

Fifth, again according to basic drafting standards, some solids such as fasteners, balls, non-hollow shafts etc. should not be cut in a section view, that is, to serve as a visual clue of what is being looked at and to prevent drawing clutter.

I was able to implement a very sane selective exclusion mechanism, again based on solid uniqueness, so not everything is cut and hatched.

SIxth, I wanted everything to be as interactive and parametric as possible, meaning achievable solely through the user interface and dynamically recomputed when there are CSG changes back in the tree.

Seventh, When exporting the drawing (and probably during creation through another core change), there should be different line thicknessess, according to their different purpose, or at least things should be further editable.

Currently, all annotations can be exported with custom line thicknesses, independent of body line thickness.

Lastly, I was so pressed for time that I avoided any code which requires compilation, effectively implementing the whole toolset in python, though I would like to change that for its many limitations.

Still there are tons of functionality left, that I managed to fix with inkscape for the real project, but should be straitforward to add from now on.
To name just a few things missing:
[] partial sections
[
] balloon annotations [1]
[] automatic thread symbols, centermarks and centerlines, based on underlying 3D structure
[
] solid groups in the BOM
[] zoomed-in sections
[
] toggling between a complete section and a section-plane only.
[*] dimension lines lying on top of the geometry, instead on the X-Y plane.

At the end, I want to point out some really buggy things that I encountered, which were huge stoppers.

The biggest FreeCAD pitfall to date, considering future multibody development, for me, is that there are no solid names/numbers/hashes. I know that’s part of the Open Cascade engine, but I presume that solid names were simply omitted in FreeCAD. So there’s a general lack of a mechanism to identify different compounded solids down the tree. I am using hashes based on faces for that purpose, but that’s a no-go.

[1] Another peculiarity, the initial idea was (and still is) to export the 2-D annotations as faces (svg with solid fill color and so), that is, the letters and numbers should not be converted to wires. But for almost half of the alphabet and even more (letters B, Ф, $, e to name a few, I think of them as “interlooped” letters), the built-in FreeCAD exporter dies horribly with an “Edges not ordered” error and refuses to export faces. Alternatively, in FreeCAD 0.20 this is mostly fixed at the expense of tremendous overhead, taking 2-3 hours to export 1000-2000 simple faces.

The last problem reflects in the way the whole SVG export is done, there should be some implementational flaw (use of std::vector somewhere/everywhere ?!?) because with increasing geometry complexity, the export time increases almost exponentially!

I also wanna mention again my previous thread https://devtalk.freecad.org/t/3d-view-edges-drawn-through-faces/63379/1 because this core issue really affects the drawing’s appearance.

And now for a simple demonstration.

A showcase of the creation of a multibody drawing. Credit for the model goes to Nelson Stoldt @ GrabCAD, I downloaded a random 3D model from the Internet for the purpose of the demonstration.
https://www.dailymotion.com/video/k6A2dyyBsPrc4JyQgtG

And this is my final assembly drawing, part of my thesis (defended in october), and made entirely using Python, FreeCAD and inkscape: ^^

https://pdfhost.io/v/U3Iyb~Rf8_Drawing_flat_anno_2

If you’re interested in what I’ve done, I’ll gladly share the set of scripts that make it possible. If not… wel, somebody please delete this wall of text. :cry:

In a perfect world, I see this workflow merged into the TechDraw workbench, which already has a huge and well-working drafting toolset.

Writing this as a truly OSS engineer :wink:

Edit 0: The raw source
scripts_alpha.zip

Well, this was certainly very interesting and promising, thank you! It seems that you coded it entirely in Python, so it’d make sense to make a full (Python) workbench from the collection of your macros, that way it could be developed and integrated into FreeCAD in an entirely independent fashion. Like, for example, the Assembly 4 workbench that I and many others use quite extensively, despite it not being part of the core FreeCAD packages (it’s offered in the addon manager).

Some notes:

  • You mention that the annotations and other text are exported as shapes. Would it be possible to not include the text as a rendered 3D characters, but as a metadata that would be exported to the final 2D SVG as text?
  • I’d think, in general, some output filters would do wonders. I mean that some script that would filter line thicknesses, colors, line endings, etc. for the dim objects into some nice values and shapes when converting from 3D view to SVG
  • In practice, one would get kind of lot of dims and other stuff in a technical drawing, so some kind of tree structure and containers would probably be a good idea (like in TechDraw, currently)

Thanks for the feedback, @aapo! A complete workbench is definitely an option, though another separate workbench for another subtask sounds like such a waste of available resources. I’m actually a huge fan of the Assembly 3 workbench.

There are no 3D characters, actually. All is 2D XY-aligned faces and my idea was that the representation in FreeCAD matches the generated svg exactly. So… metadata is certainly possible, but it may be preferable to have no visual difference between the UI and the drawing.

Yeah, I’m currently using filters for the line thicknesses, but as my previous statement, the best possible outcome will be if these filters are applied in the actual GUI, so no afterwork is needed.

Absolutely!

I don’t think that would be a waste of resources at all.

First, a typical FreeCAD external Workbench is just a collection of macros that just happen to have a common workflow and interdependencies. In your video, one can see that you already use your macro collection like an external Workbench: First, you select something, run a macro on it; select something from the results of the macro, run another macro on that; select something else, and run a third macro on it, etc. This is a very typical external Workbench workflow in FreeCAD, and you even seem to have some special objects that cannot easily be interacted without your macro tools. I don’t think that there’s much else missing from an external Workbench but some button icons and menus to execute your macros.

Second, your new workbench would not be just another version of TechDraw or Drawing Workbenches: There’s the fundamental difference that your new Workbench would be fundamentally a 3D-editing Drawings workbench with only the final SVG exported to 2D; whereas the currently existing Workbenches are 2D-editing Workbenches that start with a 2D-projection of a 3D object, and all the editing is done in 2D. So, there really is a fundamental difference, and to my knowledge there is not yet such a 3D Drawings Workbench in FreeCAD, yours would be the first. Moreover, I don’t think that these workbenches could be combined, because they are fundamentally very different; and I don’t see a reason why they should be combined, as both workflows probably have their use cases. 2D is simpler for some objects, anyway, and there are some serious advantages with the 3D approach, as well as probably some serious disadvantages and difficulties with it, too, I’d imagine.

Anyways, as you’ve probably planned, it’d be structurally nice to keep the tree of the 3D model itself completely separate from your Drawings and decorations; I mean that it would be much easier to continue editing the original 3D model if all this drawings stuff would be under a separate folder in the tree view, so that one could make it invisible and hide it in the tree view with couple keystrokes.


There are no 3D characters, actually. All is 2D XY-aligned faces and my idea was that the representation in FreeCAD matches the generated svg exactly. So… metadata is certainly possible, but it may be preferable to have no visual difference between the UI and the drawing.

Yes, certainly if it’ll be technically feasible, it’d be the preferred choice to have WYSIWYG. I must say that your macros look very promising despite the project being in an alpha state, I’m looking forward to maybe test and see how to use them experimentally in a simple test example. To me they seem to be an interesting and novel proof-of-concept, at least in the FreeCAD world. I’m not sure if any commercial CAD software offer such functionality, though, as I only tend to use open source software if possible.

Totally valid points!

Actually a workbench was on my TODO list before I realized how little time I had.

My only concern is that “the fundamental difference” means that everything that’s been already done in the other drawing workbenches should now be duplicated inside the new one, but if that’s the way… I get it.

As to separating the diferent tree items, I’m heavily relying on realthunder’s links in separate .fcstd files for the different manipulations, but that’s just my own workflow. I don’t think that nesting the different ofjects into the ‘Drawing’ object and structuring them would be too complicated anyway.

The way my “workbench” works is heavily influenced from what I was empirically able to figure out about the way SolidWorks does things internally. And for some people that said piece of software defines the de facto limit of what a machine-generated state of the art drawing may look like… but those are just opinions :wink:

My scripts, if I remember correctly, are actually a (couple of) thounsand-ish lines of python code and despite them being in some brutally raw alpha state (only if I was as good in writing python as I was in C++…), I’m very curious if they would work out of the box on someone else’s machine or they would require at least some patches. After all, the development was done on the Freecad Link 0.19 branch but some final tests and operations were performed on FreeCAD 0.20 nonetheless.

I think I can share them here tomorrow, if I figure out what all the paths were…

aapo Edited my original post and attached the scripts. Truly don’t know if they’ll be usable.

This is a very long text, i did not understand it full, but i think i get it mostly.

The most things are right, you also mixing things like what is missing now for classical 2D deviating drawing and your proposed workflow.


But there are few things you have written, they are not true anymore. You seems to use the LinkDevelopment branch from realthunder. But this branch is missing almost every TechDraw fixes and enhancement since a very very long time.

to point 1:
You can switch off recompute the drawing, even in the old version. And new is, that wandererfan managed to make TechDraw using multithreading. Also when 3D geometry changes, it does not freeze anymore.

to point 4:
It is already solved in the master

to point 7:
When i get it right what you mean, they are editable (general in the view tab and per line), since a long time.


to your proposed workflow:
To be honest, for me it neither fish nor fowl. If you want annotate in 3D, i would do it similar like this https://github.com/juanvanyo/FreeCAD-GDT old and not functional addon. And when finished, you can deviate it in a drawing, or save it in a *.jt (Jupiter, ISO) format. At least i see no sense or usecase in a 2D/3D hybrid.


Greetings
user1234

Thanks for the feedback, user1234

I’m not sure that you’re getting the main point of my workflow.

It’s not about some mixed 2D/3D drawing.

First, It’s about drawing annotations being parametrically associated with the underlying geometry. Right now, if some dimension changes, or if the direction and/or the position of a section changes, all the dimension lines, hatches, materials and so on, are going to update accordingly, to the best possible extent.
No matter how hard I’ve tried using the TechDraw workbench, there’s no general straightforward way to do so. It’s virtually impossible without manually inputing the according information, because it gets discarded at the instant when the body is flattened.

Second, It’s about being able to apply different materials to the different bodies of an assembly.
I don’t know if there are any plans for this to be implemented in TechDraw, but my research found none. TechDraw treats the whole model as a single body.

The drawing doesn’t have to do anyting with the 3D view actually, except from being able to select some hard to select lines. All annotations lie in the X-Y plane, unlike the CAD-GDT workbench that you mention and which has nothing to do with technical drafting.

I’m well aware of the great advancements in TechDraw, which I’m really missing, but that’s not main problem here. TechDraw still requires hours (in my case) for a simple HLR recompute and the logical thing should be that the HLR algorithm takes place at the end of the workflow, not every time a single parameter is trimmed. And TechDraw is still virtually decopuled from the underlying geometry - annotations generally don’t follow the exact curves and surfaces they are put on.

Needless to say, if I was able to use some other workbench to complete my work, I woudn’t have bothered writing code at all.

Points 1-7 are the criteria that I wanted my toolset to have in order to be useful. They aren’t pointing to another workbench functionality.

Anyway, I find switching off recompute absolutely useless. I want the recompute to take place every single time I make a change or else I have a drawing that’s not up to date with the assembly that I’m developing, who would want that?

Sadly, that’s not true for the Draft dimensions AFAIK. If it was, I’d be using them instead.

Yes, this is just another criterion for the toolset.

As I said in the very beginning of the thread, I made something very specific. It’s specific for machine engineering where multibody drawings are the norm and where tons of little interactions and reiterations between the drawing and the model are required before the end product is done. I know that TechDraw & co work flawlessly for the simple case when you need a quick drawing of something already finished, but that’s not the usecase.

And I know that machine engineering is a small niche in modern days and FreeCAD combines hundreds of such niches together, which makes it so great, so I was curious if my specific work would be of any interest for the community. And if it will be inspirational for other devs.

Thank you very much! It’s surprisingly straightforward proof-of-concept, I mean there’s not too much code for what it can already do. I guess that’s just a good thing when trying to understand the mechanics, as it’s much less lines to understand than, e.g., the TechDraw workbench. Thanks again for this! :smiley:

You’re welcome, aapo !

It’s just the tip of the iceberg, I’d say :smiley: Thanks to all the great FreeCAD devs.

That was not clear to me.



Now i think what you up to, it can be shorted in, no hlr use, since it is not TNP save (for example in your suggestion passing properties from 3D to 2D is not needed more) and error prone. Is that correct?


The views what you made, are the clipped views form 3D (clipped from mesh)? Or they are real projections / boolean sections? For drawings you still need real geometry. And what is with hidden lines? You need still a kind of hlr to separate from overlying and underlying geometry.



Greetings
user1234

Kind of. HLR is still used, of course, but only during the export stage. So the user has to wait only once during export.
And yes, I think the term is robust - less things to manage, harder to break, way more productive.

No, as you already pointed out, simple clipping doesn’t work here. The sections are cut, almost like in TechDraw. With the added advantage that boolean cutting single bodies is way faster and raliable than compsolids. And yes, 3D->SVG still uses HLR.

Thanks, for clarifying.


Greetings
user1234

Sorry for bumping, but I have just read this and it looks
interesting work. Has there been any progression?

BW