3D model skp to fbd exporter

hi all,

currently i’m in starting makes a script for SketchUp 3D model to be capable exporting CalculiX CGX fbd format. it’s a modified version taken form another codes, Google SketchUp 8 is intiutive and known working welll in Linux trough Wine.

an interesting to know and implemented or improvement (maybe) are:

  • preset for automeshing of tetrahedral element
  • translate arc and circle object
  • color indek to define surface boundary condition and contact
  • material indek for a part
  • partition (surface inside a body) to generates structured hexahedral element
  • etc

i’ll post the codes at GitHub after minor fix and try to continue as possible, please comment or p.m if someone interest to contrributed also

best regards,

below screenshot of progress:

1 Like

It is interesting to see. I’ve also been thinking about a way to e.g. translate STEP files to FBD. Preferably in a way that would generate a halfway decent hex mesh!

But that seems far from a trivial problem. As I understand it, it is much easier to fill an arbitrary geometry with tet element than with hex elements.
I’ve tried creating hex meshes in arbitrary geometry in FreeCAD (which uses gmsh) but more often than not I run into problems even for simple geometry.

Would the geometry that you show work with cgx’s hex mesher as-is?
I would probably divide it up in parts that can be handled with the built-in hex mesher. Something like this:

So it can be meshed with he20r.

So far so good.

But what would happen if for example the geometry had a hole drilled trough it? Or if the parts had more than five edges? That would make the conversion much more tricky.
The geometry would have to be divided into meshable bodies. There will probably more than one way to do that and it might not be obvious if one way is “better”.

For practically all of the analysis that I’ve done, I have created (defeatured) geometry in cgx because I want a good quality paramatric mesh.

thank you for interesting.

actually it was available as cgxCadTools, but my experiences shown not run out of the box. it’s dependency problem on Windows. so, i can not testing is the tool deal with partition properly.

it seems to be better when partition and meshing are done inside GMSH, also hex-dominant meshing algorithm can be use as alternative.

SketchUp is intituitive 3D modeler, any partiotion as you shown can be easely drawn.

even five edges definition for structured quad/hex is capable in CGX, still prefer to keep using four edges only. this make result mesh less distorted.

the exporter seems capable for these case, user still need to trace if the problem occurs. but the CGX is a pre-processor itself, many command can be costumized or modified by the user.

the reason why, i starting makes this exporter. the capabilities and feature of CGX can be use further.

To me it seems the tool could be a good choice if the creation of geometry (and partitioning) is easier and faster than in cgx itself (be aware of the automatic calculation of line divisions in cgx). I personally create models based on parameters and additional software or I get my geometry in step format from a designer. If it is a general arrangement in 2D I do the same as rsmith and defeature it and subdivide it in a way that i get 3-5 sided surfaces. Then I sweep it in 3D. Sometimes in several successive circumferential sections were I can delete some bodies to realize for example a bore in a disk or a rib in a shroud etc. Very often I combine this hex meshes with pure tet meshes which I also generate in cgx based on a step file. The converters work very well on linux for the models I have received so far (and probably on windows since Rafal provided them for the audience). Unfortunately the necessary libraries to use them have to be installed by the user to avoid potential licensing problems with them. This is probably one of the reasons why seemingly only few people have ever used cgx to create tet meshes (actually in cgx only the shell elements for the tetgen or netgen program are created, cgx sends the shells to the filesystem, starts the tetmesher and reads the tets). The next obstacle is of course that the user needs to know quite well cgx before he can successful manipulate the geometry (please regard the qmsh command). On the other hand working with the netgen gui allows just few manipulations. I fixed some bugs and added functioallity in cgx_2.21, so please if you would give it a try please use this latest version.


indeed, using CAD as the base geometry and CGX dedicated pre-processor of CalculiX is good interactions. each part can be exported separately to modify if required then assembling of large parts.

regarding to modeling of 3D part in SketchUp is more like crafting and it;s not as advanced SpaceClaim but extension to export, partition and previously distributed by Google freely.

below an example of partition using model intersections, as can be seen line are generates in face of a part. separating them to makes of two bodies, later it can be merge the surfaces by CGX commands.

2023-08-05 01_05_31-Untitled - SketchUp

2023-08-05 01_08_49-Untitled - SketchUp


First I want to say “thank you” for writing cgx. It’s an amazing tool. There is a steep learning curve, but I guess that is unavoidable with FEA.
The fact that it’s completely scriptable comes in very handy.

Yes, creating geometry takes longer than in say FreeCAD, but I get a model that I know will mesh properly and I can make the model as fully parametric as I want. Given that I often use CalculiX to optimize fiber reinforced composites parts, making e.g. a laminate thickness a parameter is easily worth the effort. The first model takes longer, but after than making a variant can be as simple as making a copy and then a one-line edit in the preprocessor file.

Up to recently I alway set the line division manually to ensure a nice even mesh. :slight_smile: But now I’ve been playing with auto divisions, and I have to say it’s not too bad. But even in expensive FEA software like Abaqus you sometimes have to basically set line divisions yourself.

Why would you create a tet mesh in the first place? Given that a hex mesh generally gives better results with fewer elements. That has been my experience, at least. With a tet-mesh I tend to see a “shadow” of the mesh in the stress results.

Getting cad2fbd to compile on a UNIX-like system was not that difficult. It basically needs OpenCascade and libstdc++. A lot of Linux distributions and BSD systems have those libraries available in their native package managers. If your platform doesn’t have a decent package manager (like ms-windows) then I suspect it will indeed be a PITA.

I used the following Makefile to build cad2fbd on FreeBSD. It should probably work on Linux as well, although you might have to update CFLAGS and LFLAGS with the actual directories on your system.

.PHONY: clean

CFLAGS= -I../inc -I/usr/local/include/OpenCASCADE -std=c++11
LFLAGS= -L/usr/local/lib
LIBS = \
    -lTKBinL -lTKBin -lTKBinTObj -lTKBinXCAF -lTKBool -lTKBO -lTKBRep -lTKCAF \
    -lTKCDF -lTKDCAF -lTKDraw -lTKernel -lTKFeat -lTKFillet -lTKG2d -lTKG3d \
    -lTKGeomAlgo -lTKGeomBase -lTKHLR -lTKIGES -lTKLCAF -lTKMath  -lTKMesh \
    -lTKMeshVS -lTKOffset -lTKOpenGl -lTKPrim -lTKQADraw -lTKService -lTKShHealing \
    -lTKStdL -lTKStd -lTKSTEP209 -lTKSTEPAttr -lTKSTEPBase -lTKSTEP \
    -lTKSTL  -lTKTObjDRAW -lTKTObj -lTKTopAlgo -lTKTopTest -lTKV3d -lTKVCAF \
    -lTKXMesh -lTKXmlL -lTKXml -lTKXmlTObj -lTKXmlXCAF -lTKXSBase -lTKXSDRAW \
    -lstdc++ -lm

SRCS!= ls *.cpp
OBJS= $(SRCS:.cpp=.o)

cad2fbd: $(OBJS)
    $(CXX) -o cad2fbd $(OBJS) $(LFLAGS) $(LIBS)
    strip cad2fbd

    rm -f *.o cad2fbd

(For those of you not familiar with make, the empty space at the beginning of a line should be a <tab> character, not spaces.)
This was written for BSD make but worked with GNU make as well.

Place this Makefile in cgxCadTools/CadReader/src and invoke make.

1 Like

actually it did not come to my mind to look into the package manager (yast) to seach for open-cascade. You are right, it’s there! Regarding the tet meshes your statement that you see a shadow of the mesh describes the problem of localized accuracy very well but on the other hand they allow to keep all the details in the model which helps to avoid lengthly discussions and makes life easier (if you have the patience for the longer calculation and evaluation times). Critical regions can be meshed with hex and glued to the rest.

1 Like

That makes things a lot simpler. On my system, OpenCascade depends on 50-odd other packages. Building that by hand without the build files provided by your distribution would be quite an adventure.

Let’s just say that I’m not always wise enough to avoid those discussions. :blush:

What I would like to know is, if you get e.g. geometry in STEP format, how do you partition it so that cgx can mesh the parts?

Either I use the ‘split’ or the ‘qspl’ or just the ‘qdel’ command to reduce the step based geometry to the one I want to mesh with tets. Usually I use cgx based additional software to generate parameter controlled geometry (an fbd file) which is already configured to be meshed by hex or, if no parametric model is available and to create one would be uneconomical, I try to generate a hex meshable geometry in the painful way of subdividing the rest manually (using split or/and creating new lines and surfaces etc). Often it is possible to just use a 2D part of the geometry and sweep it in 3D. To be fair I also have to admit that I first judge if the geometry is suited for cgx. I do not use cgx in cases were a lot of very small surfaces might exist like in a cooled turbine blade with lots of bleed holes. In this cases I use commercial software or ask my younger colleagues for a helping hand :slight_smile:

1 Like

I want to add that with cgx_2.21 you can delete holes by placing all the related points or lines or surfaces of that hole in a set and ‘zap’ it. The surfaces through which the hole goes are redefined without them. Be aware that if not all parts of that hole in the surface are deleted in one step the surface can not be kept. And a hole must be inside a surface and not part of the outer lines.


i have been posted the modify version of codes at GitHub, however it’s only base of geometry. an arc or circle object in SketchUp still puzzling me.

to use the exporter, place the script at folder below and access through Plugins menu.

C:\Program Files\Google\Google SketchUp 8\Plugins

an example usage of solid and surface modeling is not yet documented, i’ll add later.