step to stl converter

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
jenosik
Posts: 4
Joined: Tue Jan 12, 2016 3:38 pm

step to stl converter

Post by jenosik »

hey guys,
im using freecad to translate my files from solid edge to blender.
i design everything in solid edge and i need to get the assembly files into blender as individual parts. im using blender as a rendering software, so i need individual parts so i can texture each component without having to select the mesh of each part.

solid edge kinda sucks. i can not batch export individual .stl files from my assembly easily. ( ive used solidworks for years and did everything i needed it to.)

so currently, i export from solid edge as a .step file (1 step file and all individual component parts are preserved within the step file.)
i then open that up in freecad and i can easily select and export individual parts to stl files.

this is still very long and laborious as sometimes i have parts with 200 screws and 50 component parts

is there a way to open the step file in freecad and then with a macro save out each part as an individual .stl file?

is it easy to create? im relatively new to developing. but will definitely give it a go, seeing as im going to have to do this at least 3 times a week.

thanks very much
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: step to stl converter

Post by wmayer »

You can write a Python script to automate this:

Code: Select all

from PySide import QtCore
import Part, Mesh

d=QtCore.QDir("Directory_to_step_files")
d.setNameFilters(["*.step", "*.stp"])
files = d.entryInfoList()

for i in files:
    shape = Part.Shape()
    shape.read(i.absoluteFilePath())
    mesh = Mesh.Mesh()
    mesh.addFacets(shape.tessellate(0.01))
    mesh.write(i.absolutePath()+"/"+i.baseName()+".stl")
This code is not really tested but it should work this way more or less.
jenosik
Posts: 4
Joined: Tue Jan 12, 2016 3:38 pm

Re: step to stl converter

Post by jenosik »

hey thanks for doing this for me.

im really showing how much of a noob i am. can you show me how to use it please.
i changed my directory to step files and nothing happened. what else do i need to change?
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: step to stl converter

Post by NormandC »

Hello jenosik,
jenosik wrote:im using freecad to translate my files from solid edge to blender.
i design everything in solid edge and i need to get the assembly files into blender as individual parts. im using blender as a rendering software
Funny, I too use Solid Edge at work, and I've thought of doing the same. We have an almost 10-year old version of SE, and since migrating from XP to Seven I can't get Virtual Studio to work anymore. But I can't get enough time off to learn Blender, that beast is so totally different to what I'm used to. :?
jenosik wrote:solid edge kinda sucks.
Uh, I do not totally agree. :D Sure it sucks in a few areas, but as for general modeling I much prefer its workflow to SolidWorks! The problem with SE is that its core market is the machinery industry, so most everything is geared toward that. This is why rendering used to suck (Solid Edge now comes with Luxion KeyShot, a pretty sweet rendering package I shortly used in a previous job), and why surface tools are so lacking compared to SW...
jenosik wrote:so currently, i export from solid edge as a .step file (1 step file and all individual component parts are preserved within the step file.)
i then open that up in freecad and i can easily select and export individual parts to stl files.

this is still very long and laborious as sometimes i have parts with 200 screws and 50 component parts
May I suggest trying a different method? STL is a very limited mesh format designed for rapid prototyping of single parts. Instead I suggest exporting your STEP assembly file from FreeCAD to .obj, which can contain multiple closed mesh objects. Then import the .obj in Blender. It will import as a single object, but you can separate it "by loose parts" see http://blender.stackexchange.com/questi ... -closed-ge
And in theory that should be it! I just tested with a bunch of primitives I created in FreeCAD all with the same placement and sharing the same space, and once I separated by loose parts they were considered as separate mesh objects.

One thing that I don't understand though, is that the obj produced by FreeCAD looses its placement once imported in Blender, it looks like everything is rotated 90 degrees along the X axis.

Last time I had to produce a quick render, I found a free online rendering app that can import multiple file format, including CAD formats. I don't recall its name ATM, if you're interested to check it out, I'll find the link at work.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: step to stl converter

Post by microelly2 »

NormandC wrote: May I suggest trying a different method? STL is a very limited mesh format designed for rapid prototyping of single parts. Instead I suggest exporting your STEP assembly file from FreeCAD to .obj, which can contain multiple closed mesh objects. Then import the .obj in Blender.

And in theory that should be it! I just tested with a bunch of primitives I created in FreeCAD all with the same placement and sharing the same space, and once I separated by loose parts they were considered as separate mesh objects.
I have done some work for colored export of obj files and reuse it in other viewers.
https://www.youtube.com/watch?v=Vz2sRNQ5wjI
https://github.com/microelly2/freecad-export
You can export sinlge parts but the complete assembly too.

My idea was to wirte an exporter to WebGL too. There is already a method to export monochrom webgl objects,
and its not to difficult to do it with colors too.
WebGL has the benefit that you can publish your model in the web.

However, for realistic texture work Blender is the best.

One thing that I don't understand though, is that the obj produced by FreeCAD looses its placement once imported in Blender, it looks like everything is rotated 90 degrees along the X axis.
There are two parameters left bottom in the import dialog where you can define the directions
jenosik
Posts: 4
Joined: Tue Jan 12, 2016 3:38 pm

Re: step to stl converter

Post by jenosik »

BRILLIANT!!!! thankyou very much!!! .obj worked PERFECTLY that is exactly what i need thankyou very much for your input. much appreciated.

that changes the game!!!

Normandc
im biast to solidworks for sure!! i actually dont hate solid edge. i just wish i knew solid edge as well as i do solidworks. im only 2 months into solidedge and i can scrape by.
i really like the synchronous modelling in solid edge......... as long as nothing unusual comes up. and i do find myself shouting at the screen "why are you doing that???".

Im really enjoying learning blender. i learnt 3d studio max years ago at university used it for rendering and animations

https://youtu.be/yDRg2Z1FTSI


but blender is awesome. attached is what i rendered this week.


once again. thank you very much for your help separating meshes.
Attachments
dell tablet dock front.jpg
dell tablet dock front.jpg (238.05 KiB) Viewed 15514 times
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: step to stl converter

Post by NormandC »

Hey, I'm glad it simplifies your process. I may need it too in the future! :D
microelly2 wrote:There are two parameters left bottom in the import dialog where you can define the directions
Doh! I hadn't noticed. :oops: Thanks!
microelly2 wrote:I have done some work for colored export of obj files and reuse it in other viewers.
Interesting. Would these obj import in Blender with colors? Right now the export to obj seems to loose color info.
jenosik wrote:i really like the synchronous modelling in solid edge......... as long as nothing unusual comes up. and i do find myself shouting at the screen "why are you doing that???".
:D Ah! We're using a version that predates Sync tech, I guess I may scream at my display quite a few time when we upgrade.
jenosik wrote:attached is what i rendered this week.
Nice!
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: step to stl converter

Post by microelly2 »

NormandC wrote:
microelly2 wrote:I have done some work for colored export of obj files and reuse it in other viewers.
Interesting. Would these obj import in Blender with colors? Right now the export to obj seems to loose color info.
Yes, may be it uses some path adjusting, but all data are written. I will check it next and will refine the workflow.
jenosik
Posts: 4
Joined: Tue Jan 12, 2016 3:38 pm

Re: step to stl converter

Post by jenosik »

Instead I suggest exporting your STEP assembly file from FreeCAD to .obj
hey guys just a quick update.
i tried exporting a .stl of my entire assembly into blender. it allowed me to seperate my .stl into multiple parts. using the same method as above
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: step to stl converter

Post by NormandC »

Hey jenosik,

You may be interested in this topic someone posted today: viewtopic.php?f=22&t=14613
Post Reply