3D new library for Mechanical CAD exporting and enclosure design

from an earlier post of @xavierw:

I’d say it’s what you get inside ProE when you render the model, won’t look as nice in KiCAD or FreeCAD, but maybe in blender after you played with the materials a bit after using @maui’s StepUp tool to get the pcb assembly over there.

@xavierw
You don’t want each value on those, unless you’re insane or a genius. :wink:
What is the STEP file size for that resistor btw? Looks marvelous… I wage a guess, the VRML file will come in at 800kB+ unless you find a way to control the amount of segments being used for round surface approximation - I had no luck so far :worried:
Doesn’t ProE have some kind of facility where you can code behaviors of model parameters according to some table? I know it exits in Inventor… never used it though.

The footprints are generic and there currently is no way of transferring values from the symbols over to the 3D models in an automated fashion in KiCAD… which means you’d need one resistor symbol, footprint and model per value… which E-series do you had in mind? :open_mouth:

Not even this is possible in KiCAD for now, which is way simpler:

@SBW
I cheated a bit: the photo attached was actually from a Keyshot render.
In Creo, it looks fine, just not as realistic as it’s just the model, not the render.

In FreeCAD, the STEP model is ok:

BTW, the STEP file is 120KB in size. Not too large, but not practical if you have several different values.
In all fairness, I went to model something that looks realistic rather than simple: the colour rings are actually a “thickness” so emulate a band of paint on top of the actual resistor rather than just changing the colour of a section of the resistor’s body.

@Joan_Sparky
I need to investigate what scripting / lookup is possible with Creo. If I could assign a text file and associate that with different colours, I could then write a simple macro to generate a list of values, much like @cbernardo has done with VRML. Alternatively, I’ll try to get my head around Python (I’ve never done that, my last scripting goes back to Turbo Pascal when I was a university!) and see if I can generate a script with @maui’s FreeCAD scripting stuff.

Zip file of step model attached.
res.zip (20.0 KB)

1 Like

ran the STEP model through my FreeCAD/python script to get the VRML model: 2.8 MB
You really don’t want to make every value… a couple different ones of these on a single board and the 3D viewer will have a stroke :smile:

Resistor_0.25W_TH.wrl.zip (346.6 KB)

Can you tell Creo how many segments per 360deg it uses for the surfaces?
I can’t find any settings for this in Autodesk Inventor, nor in FreeCAD (after importing the STEP model)… but maybe your CAD has got an option for that to get the file size down?

One more thing, you might want to realign your modeling planes to fit KiCADs world (Z-axis is away from pcb, Y upward) as otherwise you have to realign every single one of them models (and you really don’t want that):

2 Likes

Thanks.
Regarding segments, the one I posted earlier has 24 - I just counted them in FreeCAD. Maybe there’s the option to make less. I think the added complication comes from making it look nice. If I were to simplify, the STEP version ends up being around 60KB and resulting conversion to VRML would be a lot smaller too I guess.

You can trial&error yourself as you got freecad already… just load the python script from github that is linked in my last post and open it in freecad (edit scripts button), modify some bits and then run it (run button).
This way you get scaled components for KiCAD from STEP files by clicking on a button in FreeCAD only - couldn’t get it to work outside of FreeCAD unfortunately…
You can change the license text to any other if you want, shouldn’t fault if you stick to the layout that is there. The license will be added to both the VRML and the STEP file, as both are needed for StepUp.

1 Like

I (nor anyone else I guess) really need the VRML version of TH resistors (as well as other TH components) as they’re already available from @cbernardo’s scripts - I’ve generated all the various components and they work fine with the built-in 3D viewer in KiCAD.

I really wanted to have a STEP version of the models so I can use the new scripts allowing 3D modelling outside of KiCAD. The examples here use FreeCAD, but of course you can use any other 3D CAD/CAM package that can read STEP files.

With a 3D model of the PCB in STEP, I can then do my case design and ensure everything fits as well as generating any marketing material :slight_smile:

Ah, didn’t see/read that… understandable.

At least you got me to write some doc for the script and some pitfalls, in case others go down that path. :blush:

OK, I’ve made some good progress with my antiquated use of PTH components :stuck_out_tongue:

However, I have two points I think worth making out, although they are only relevant to PTH usage:

Following a lengthy discussion last night on IRC, as far as I can tell (and from much virtual head banging in the chat room LOL), there’s a lot of confusion regarding positioning of components and the alignment between footprint in pcbnew, VRML and STEP files.

From the [KiCAD rules][1], all SMDs are placed with the centre of component as origin. See 3.3 and 6.4. This makes it easy to line up the footprint with the VRML model in KiCAD 3D Viewer and a STEP model for exporting to MCAD using the FC macros.

But for PTH stuff, 6.3 ruins it all suggesting use pin 1 as origin.

@Joan_Sparky, I’ve tried using your scripts to creat some clean STEP models from existing VRML models, but I do have a problem with the logging stating:

>  Traceback (most recent call last):
>   File "C:/Users/Xavier/AppData/Roaming/FreeCAD/kicad_StepUp_vrml_export.FCMacro", line 58, in <module>
>     fileName=sys.argv[1][:-4]
> <type 'exceptions.IndexError'>: list index out of range

Any idea where to look?

One day I hope to contribute more than ask questions, but I really appreciate the effort everyone’s putting into this, so thank you all :smile:
[1]: https://github.com/KiCad/kicad-library/blob/master/KiCad_Library_Convention.txt

the Joan’s script exports STEP file to scaled VRML; the opposite way is unfortunately not viable for mechanical purposes…
(it is a pity because all the kicad mesh models out there are useless for MCAD world)
that is why I started this topic and the 3D MCAD library of STEP models

1 Like

What @maui said… the workflow for me is Inventor > STEP > VRML and the script automates that + adds license info to the files.

I just tried the opposite, importing a VRML into FreeCAD 0.16 and exporting it as STEP… looks really broken. Whatever comes out of that is just some sort of metadata, no geometry data inside.

I ignore that as it’s not logical :wink:
All models I create are centered… may whoever thought it should be different piiiieep

@maui, @Joan_Sparky,
Sorry, I did mean going from STEP to VRML!
I have converted other STEP models to VRML using various 3D packages, but they all seem to make a real mess of it, hence why I’d like to try using Joan’s scripts :smile:
Do you have some instructions on setting it up? Is it just a case of having your Python script loaded and editing only the paths and creator lines in your screenshot above? Any other dependencies I might have missed causing the problem?

@xavierw
if you have downloaded kicad StepUp, inside there is a small script with bat/bash file

launch-kicad_StepUp-step-to-vrml-example.bat

launch-kicad_StepUp-step-to-vrml-example.sh

and the python file is

kicad_StepUp_vrml_export.FCMacro

just edit the batch with the step model you need and launch the batch
e.g.

cd %~p0
start "" "%PROGRAMFILES%\FreeCAD 0.15\bin\freecad" shapes/sod80.step kicad_StepUp_vrml_export.FCMacro

Thanks, working now :slight_smile:

edit: although I’ve also had FreeCAD crashing (inconsistently) when filenames have hyphens in them…

@Joan_Sparky, as well as the hyphen problem, I seem to have another issue following transformations with your macro.

If I take a step model downloaded from the web, it opens fine with FreeCAD. If I then export it from FreeCAD as a new step model, it still works with the WRL macro conversion.

However, if I take the step model and then do a transformation so it lines up with the footprint and then save it, the resultant step file doesn’t work with the WRL macro conversion, FreeCAD crashes.

I haven’t looked into the step files to try to understand, I’ve attached a few zip files of a typical JST connector I use. I’ve already removed the hyphen so it doesn’t crash on that :smile:

The B02PVL2.STEP file converts fine. This is just the exported-from-FreeCAD version without making any changes.
The B02VPL3.STEP file is modified so it matches with the footprint I have. This then crashes when I try to convert to WRL format.B02PVL2.zip (31.4 KB) B02PVL3.zip (31.4 KB)

@xavierw
FYI you are using my script, not the @Joan_Sparky one…

If you use the GUI kicad StepUp tool to scale and export your STEP model, everything is working…
follow this video tutorial

@maui, I’ve had your tool working fine on a lot of models, it’s great :smile:

I’ve now just come across an issue with some STEP models that don’t seem to work with the STEP -> VRML conversion tool Joan made so I can have the VRML files to use in the native KiCAD 3D viewer.

This isn’t an issue as the long-term goal is of course to have a 3D model in a MCAD application. I haven’t tried yet: maybe I can create a fake/empty VRML file with the correct file name to match corresponding STEP file so whilst it won’t appear in the KiCAD 3D viewer, the KiCAT StepUp macro will still work? I presume the scaling used in KiCAD under the 3D settings aren’t exported / used when you export the IDF .emn file. I’ll expirement a little more :smile:

Both STEP files load into Inventor.
Looking at them in Notepadd++ and comparing them, there are some differences there.
Opening them in FreeCAD 0.16 in Windows 7 nothing crashes for me?

OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.5942 (Git)
Build type: Release
Branch: master
Hash: c9cfc369d6eb00529deb7c04a2e20e436523e0b6
Python version: 2.7.8
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17

As for my script that converts a folder full of *.stp files into another folder that then has got *.wrl files of the same name & content + license information… it works:B02PVL-2and3_test.zip (11.4 KB)

Funnily enough, both footprints land at the same position for me in KiCAD?! Are you sure you did anything to #3 vs #2?

  1. kicad_StepUp_vrml_export.FCMacro is not @Joan_Sparky macro
  2. have you tried using the highlited button?

using B02VPL3.STEP I don’t have any issue,
I couldn’t really found any model to fail with the GUI macro…
3) moreover @Joan_Sparky tested his command line macro with your models and the conversion is fine…
so I cannot see any issue in having 3d VRML in kicad and STEP MCAD in FreeCAD fully aligned …
keep me informed :smile:

OK, I was using FreeCAD 0.15 so I’ve now switched to 0.16. It seems a lot quicker, but I still have the problem.

But if I try to convert to WRL, it crashes in the process. I’m just launching from the command line:

“c:\Program Files\FreeCAD_0.16\bin\FreeCAD.exe” .\3d_models\b02pvl4.step kicad_StepUp_vrml_export.FCMacro

Maurice, the FCMacro I’m using is v0.3 dated 01/07/2015.

I don’t think I have to scale it because the scaling already matches the size of the footprint.

Summary of what I’m doing:
I open the original STEP file from JST (removing first the hyphen in the filename).


I then open the StepUp Macro, then load the footprint.

At this stage, I can see the scaling is correct: the size of the connector matches the footprint. So all I need to do is rotate and translate it:

I then select the B02P-VL shape in the tree view, go to file, export and save the STEP file: B02PVL6.zip (32.0 KB)

If I close FreeCAD, and then open up this new B02PVL6.STEP file, it opens fine in FreeCAD. If I then load up the StepUp macro and load my footprint, I can see that this file is now correctly located on the footprint.

If I then take this exact file and try to convert to VRML, FreeCAD crashes shortly after it launches.

export your modified STEP file using the “Scale to Kicad VRML” button of the GUI kicad StepUp macro, not with the command line (which is just a reference for scaling and export models)…


here your vrml models coming from B02PVL6.zip
B02PVL6 (step-vrml).zip (40.2 KB)
NB the GUI macro creates a scaled model of a selected object, then you have to select and export the model (Ctrl-E) and save as vrml
or just use the @Joan_Sparky macro command line…