Save a STL file with multi-regions

A subforum specific to the development of the OpenFoam-based workbenches ( Cfd https://github.com/qingfengxia/Cfd and CfdOF https://github.com/jaheyns/CfdOF )

Moderator: oliveroxtoby

wandererfan
Posts: 2355
Joined: Tue Nov 06, 2012 5:42 pm

Re: Save a STL file with multi-regions

Postby wandererfan » Sun Aug 21, 2016 12:12 pm

User avatar
virengos
Posts: 5
Joined: Fri Oct 14, 2016 9:56 am
Location: haibach, germany
Contact:

Re: Save a STL file with multi-regions

Postby virengos » Tue Oct 25, 2016 2:12 pm

I just came across this topic, and would like to contribute my own thoughts on the matter.
One other possibility is to export all the single regions to separate files and merge it outside of FreeCAD by using the 'cat' command in terminal (when using Linux) or the 'type' command (when using Windows).

cat obj1.stl ob2.stl obj3.stl > all_obj.stl

That's my approach, and it works for me when dealing with Open FOAM, meshing and CFD.

OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.6706 (Git)
Build type: Release
Branch: releases/FreeCAD-0-16
Hash: f86a4e411ff7848dea98d7242f43b7774bee8fa0
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
<free> add value to your live by respecting other's ideas </free>
fynn
Posts: 1
Joined: Tue Jan 24, 2017 12:23 pm

Re: Save a STL file with multi-regions

Postby fynn » Tue Jan 24, 2017 1:08 pm

Hi,

I am facing the same issue as many cfd-people in this forum: For flow simulations in OpenFoam I need to be able to export the surfaces of my geometry individually as either .stl or .obj files, since the different surfaces will be assigned to different boundary conditions. As virengos suggests, the files can then be collected or imported to OpenFoam individually.
The big advantage of freeCad for cfd applications would be the treatment of geometry surfaces as part objects allowing their individual export.
This is the one reason why I tested freeCad. Until now, only the cad editor of Comsol Multiphysics allows me to do just that.
jbi
Posts: 41
Joined: Sun Apr 24, 2016 3:28 pm

Re: Save a STL file with multi-regions

Postby jbi » Fri Mar 17, 2017 5:20 pm

Hi,

I just stumbled across this thread. If I understand it right, only a Export of each single face of a shape is needed. This can be done with a macro.

Code: Select all

# Purpose:     export each face of a selected shape to .stl file

#paste the import statements first:
import FreeCADGui
from FreeCAD import Base, Console
import FreeCAD
import Part
import DraftGeomUtils
import Draft
import time
import math
import os

#pre work: just create a folder tmp in FreeCAD 0.15 folder, single faces will be saved here

#first: select the shape for exporting and paste this 2 lines into the console and hit enter
sw = FreeCADGui.Selection.getSelectionEx()[0]
obj = sw.Object.Shape

#second: paste following lines into the console
for face in obj.Faces:
	unique=str(time.time())
	hash=str(face.hashCode())
	#edit your filename here
	filename='D:\\Anwenderprogramme\\FreeCAD 0.15\\tmp\\001_TIME_'+unique+'_Hash_'+hash+'.stl' #create unique filename
	face.exportStl(filename,0.3) 
	"""
	parameters for stl export can be found here: search "exportSTL"
	at https://github.com/FreeCAD/FreeCAD/blob/4664e5bb483404b064e8de59ce0ca3161482e9a1/src/Mod/Part/App/TopoShapePyImp.cpp
	"""

#single file for each face is created in D:\\Anwenderprogramme\\FreeCAD 0.15\\tmp folder

####################################################################
####################################################################

#single faces can be selected too, just select the face of interest:
sf = FreeCADGui.Selection.getSelectionEx()[0]
face=sf.SubObjects[0]	#sf.Object.Shape

unique=str(time.time())
hash=str(face.hashCode())
#edit your filename here
filename='D:\\Anwenderprogramme\\FreeCAD 0.15\\tmp\\001_TIME_'+unique+'_Hash_'+hash+'.stl' #create unique filename
face.exportStl(filename,0.3) 

You can also create a macro and add a button to the gui. A lot of Information how this can be done can be found here and https://www.freecadweb.org/wiki/Online_Help_Toc here.

I hope this helps.
johan
Posts: 14
Joined: Tue Nov 29, 2016 8:37 pm

Re: Save a STL file with multi-regions

Postby johan » Thu Jun 01, 2017 9:14 am

The new CFD WB might provide some help in this regard: https://forum.freecadweb.org/viewtopic. ... 6&start=40

It creates a multi-element stl instead of exporting separate stl files for the faces. This ensures a watertight geometry and allows for feature edge extraction.
User avatar
bernd
Posts: 7041
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Save a STL file with multi-regions

Postby bernd » Thu Dec 14, 2017 7:34 am

this is may be interesting in the regard of this topic ... https://forum.freecadweb.org/viewtopic.php?f=3&t=16855