After long hours of searching for an answer I thought it might be better to ask the community.
The problem I have is that I need to convert STL files to mesh files. I know that I therefore need to add a volume to the surfaces from the STL file.
When I do it manually in gmsh
Modules->Geometry->Elementary entities->Add->Volume->klick on the surface-mesh->pressing 'e'->pressing 'q')
that works very well.
Since I have to do this process for multiple hundreds of .stl-files I can't do it manually with the gui. Therefore I created a script which uses command line arguments to do the above and avoids opening the gui. Up until now I have:
gmsh input.stl -string "Surface Loop(2)={1}; Volume(3)={2};" -3 -o output.msh
When I run this I get the error, that the surface 1 is unknown. But when I inspect the STL file manually in the gui and do nothing but opening this STL file it shows me that the surface has id 1. So why is the surface in the script-version unknown? Is there maybe a better way to add a volume to a surface-mesh with gmsh?
P.S.: I can't use a .geo
-file for the commands since I am using a shell script to iterate through my files (with variables in the file names). Using a .geo
-file would not allow me to use the variables anymore.
P.P.S.: Here is the script I'm now using:
#!/bin/bash
# amount of files to be processed
endVal=400
# amount of slices per timestep to be processed
sliceCount=2
# create output folders for .msh and remeshed .stl files, if necessary
cd Slices/
# save current working directory to a variable
cwd=$(pwd)
# folder structure should be:
# / the Slices folder, created by the user or another script
# MSH/ after running the script it should contain the meshes created by gmsh
# Remeshed/ after running the script it should contain the remeshed meshes generated by mmg
# STL/ should contain the .stl files
# STL_Remeshed/ after running it should contain the remeshed meshes converted back to the .stl format by gmsh
if [[ ! -d MSH/ ]]; then
mkdir -p MSH/Remeshed
fi
if [[ ! -d STL_Remeshed/ ]]; then
mkdir STL_Remeshed
fi
for ((a = 0; a < $sliceCount; a++))
do
for ((i = 0; i < $endVal; i++))
do
# convert .stl to .msh
/Volumes/User/Gmsh.app/Contents/MacOS/gmsh $cwd/STL/slice$a.$i.stl -string "Merge '$cwd/STL/slice$a.$i.stl'; Surface Loop(2)={1}; Volume(3)={2};" -3 -o $cwd/MSH/slice$a.$i.msh -format "msh22"
# remesh
/Volumes/User/mmg/mmg3d_debug -in $cwd/MSH/slice$a.$i.msh -out $cwd/MSH/Remeshed/slice$a.$i.msh -hausd 0.00005
# convert remeshed .msh to .stl
/Volumes/User/Gmsh.app/Contents/MacOS/gmsh $cwd/MSH/Remeshed/slice$a.$i.msh -0 -o $cwd/STL_Remeshed/slice$a.$i.stl
done
done