EmbeddedRelated.com
Forums

KiCad - script based creation of component 3D models in FreeCAD - RM84/84 and G3MB examples

Started by Unknown April 3, 2016
Hi,

In my work, especially the one related to my teaching and hobyyist 
activity I always prefer using the Open Source environment.
Therefore KiCad is may favorite schematic and PCB tool.

Unfortunately, this tools sometimes doas not provide all needed
part symbols and models, so it necessary, that either me or my
students have to create them ourselves.

(Well, I know, there are websites like http://www.tracepartsonline.net/
but when I read all the limitations in their "Standard terms and 
conditions of use" all the limitations, I rather prefer to spend
some time on preparation of something, that I can freely share
with the whole Open Source Community).

Last time I needed to create the footprints and 3D models for two elements:
1) The power relay RM84/RM85
   https://www.relpol.pl/content/download/13766/168091/file/RM84.pdf
   https://www.relpol.pl/content/download/13794/169018/file/RM85.pdf
2) The solid state relay G3MB
   http://datasheet.octopart.com/G3MB-202PEG-4-DC20MA-Omron-datasheet-111010.pdf

I found a wonderful 3 part description, which suggests using OpenSCAD or 
FreeCAD and then Wings3D:

http://www.sl-alex.com.ua/en/page/3d-models-for-kicad-part1-openscad
http://www.sl-alex.com.ua/en/page/3d-models-for-kicad-part2-freecad
http://www.sl-alex.com.ua/en/page/3d-models-for-kicad-part3-import

I have prepared a script, which generates the 3D model of RM85 in OpenSCAD.
It is available in the archive as RM85.scad.
It generates a perfect model, which can be saved as STL, converted by the
meshlab to binary STL, imported to Wings3D and saved as WRL.
However in that process you loose the color information (when OpenSCAD 
generates the STL), so you must manually add that information in Wings3D.

I like the script based method used by OpenSCAD. It is a perfect solution
when you have just drawing of the component and its dimensions published
in the datasheets.
So I decided to try to use this approach with FreeCAD.
Unfortunately, the documentation for FreeCAD is not oriented on creation
of models in scripts, but in the Python console it displays the Python
commands performed during the menu driven operations.
Basing on that, and on documentation found at 
http://www.freecadweb.org/wiki/index.php?title=FreeCAD_Scripting_Basics
I've managed to prepare the appropriate scripts.

The interesting thing is, that this method allows one to avoid using 
Wings3D at all. The FreeCAD (version 0.15) is able to export the WRL file
which may be used by the currect KiCAD (version 4.0.2)!

In my archive there are two files G3MB.py and RM85.py, which may be executed
simply by:
$ freecad G3MB.py
$ freecad RM85.py
Unfortunately, it is necessary to run them on a X11 capable console.
Otherwise, the commands from FreeCADGui fail.

The attached archive contains:
1) Scripts G3MB.py and RM85.py, which generate the WRL files
2) directory WZ_Relays.pretty with PCB footprints associated
   with the generated WRL files (with appropraite rotation
   and scaling)
3) directory WZ_Relays.3dshapes (with generated WRL files)

The above files are published as PUBLIC DOMAIN (or Creative
Commons CC0)

4) The WZ_Relays.lib - is the schematic symbol for the
   G3MB component and RM84 component. However for that I have
   reused standard KiCAD MOC3031M and RELAY_2RT symbols.
   Therefore this file is published under the original KiCAD
   library symbols license

The archive itself is available on the alt.sources group:
Message-ID: <ndrcm2$5vd$1@node2.news.atman.pl>
Subject: "Creation of KiCad 3D models with scripts in FreeCAD - RM84/85
 and G3MB models as examples - corrected, with RM85.scad"

Archive: https://groups.google.com/forum/?fromgroups#!original/alt.sources/M_n456KMEn4/1cPWPuZlCQAJ
(please remember to save the "original" format to be able to unshar
the archive).

DISCLAIMER

Of course all submitted files are provided for free WITHOUT ANY WARRANTY
you use it ON YOUR OWN RISK.
As RM84 RM85 and G3MB are used to controll the mains voltage, DOUBLE
CHECK if my symbols and models are correct. I've tried to avoid
mistakes, but I may have overlooked something. The symbols and models
HAVE NOT been used for any hardware verified design yet!

With best regards,
Wojtek Zabolotny