File Exchange

image thumbnail

STL Lattice Generator

version 1.4.0.0 (680 KB) by Marten
Lattice generator program in STL format for additive manufacturing

30 Downloads

Updated 27 Jan 2015

View License

The Lattice Generator is a simple MatLab program that automatically generates various lattice geometries direct to STL format. These periodic structures are intended for use with the metallic additive manufacturing technologies of Selective Laser Melting (SLM) or Electron Beam Melting (EBM), however could be applied to a number of other additive technologies that require the input of an STL file.
Developed out the apparent need for a fast and simple way to generate STL lattice structures for research purposes, the program is a part of a preliminary work in developing a much larger lattice generation capability. In its current state, the program includes the following uniform lattice types:
- Body Centred Cubic (BCC)
- Face Centred Cubic (FCC)
- Modified FCC variants removing x-y, y-z, and x-z planes
- Combined BCC and FCC cell
- Modified combined BCC and FCC removing x-y plane
- Simple cube (box cell)
In theory, any lattice cell configuration could be added to the program provided that it can occupy a cubic volume and is able to be tessellated.
In addition, it was observed that creating Finite Element (FE) meshes was incredibly time consuming via traditional techniques. In response, the lattice generator script has the added functionality of generating FE meshes automatically in NASTRAN format. Other formats are possible, however for the purposes of the development project NASTRAN was all that was needed. In its current form, the lattice FE mesh is a 3D beam element mesh with the properties of the STL lattice applied. Loads or constraints are not generated, and the material properties are only set as a place holder. These aspects need to be modified in a pre-processor (HyperMesh, Patran etc.).

Comments and Ratings (9)

harsh jain

13222000109

Hey there, I'm trying to run this code, but I'm getting the following errors:

Error using fopen
Invalid filename.

Error in initialise_FE (line 4)
fid_nas=fopen(FEvars.nas_filename,'w'); % make nastran file

Error in Lattice_cell (line 58)
misc.fid_nas=initialise_FE(FEvars,nodes_unique,element_radius);

Error in Lattice_GUI_v0a_extended>generate_Callback (line 105)
Lattice_cell(handles.lattice,handles.FEvars,handles.misc);

Error in gui_mainfcn (line 95)
feval(varargin{:});

Error in Lattice_GUI_v0a_extended (line 42)
gui_mainfcn(gui_State, varargin{:});

Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Lattice_GUI_v0a_extended('generate_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.

Did anybody else face this issue? If so, how did you resolve it?

Thank you for your help

Julie

Like the code, I needed a list of nodes and connectors for a basic 3d truss for dimensions nxmxl and this was good. Some quick speed improvements in Lattice_node_connections for larger lattices-

Use a new variable instead of any of the Structures.ABC as Matlab structures can be slow.
Example:
LCX=lattice.csize.x;

Also if you parallelize all of your loops you also get a giant increase in speed, although you do only get the unique nodes. You could further paralellize the entire loop, but you will get diminishing returns. For an FCC 5x5x5 it is 100 times faster, and the disparity grows as the dimensions grow. I have an example of the FCC below:

elseif strcmpi(lattice.ctype,'FCC') % Face centred cubic
for n=1:size(nodes_unique,1)-1
J=n+1:size(nodes_unique,1);
I=ones(size(J))*n;
Lnew=sqrt(sum((nodes_unique(I,:)-nodes_unique(J,:)).^2,2));
J(~((Lnew<(sqrt((LCX/2)^2+(LCY/2)^2)+MEb) &...
Lnew>(sqrt((LCX/2)^2+(LCY/2)^2)-MEb) &...
sum(abs(nodes_unique(I,:)-nodes_unique(J,:))==[LCX/2,LCY/2,0],2)==3&...
rem(nodes_unique(I,3),LCZ)==0)|...
(Lnew<(sqrt((LCX/2)^2+(LCZ/2)^2)+MEb) &...
Lnew>(sqrt((LCX/2)^2+(LCZ/2)^2)-MEb) &...
sum(abs(nodes_unique(I,:)-nodes_unique(J,:))==[LCX/2,0,LCZ/2],2)==3&...
rem(nodes_unique(I,2),LCY)==0)|...
(Lnew<(sqrt((LCY/2)^2+(LCZ/2)^2)+MEb) &...
Lnew>(sqrt((LCY/2)^2+(LCZ/2)^2)-MEb) &...
sum(abs(nodes_unique(I,:)-nodes_unique(J,:))==[0,LCY/2,LCZ/2],2)==3&...
rem(nodes_unique(I,1),LCX)==0)))=[];
connection_nodes_unique=[connection_nodes_unique;n*ones(size(J')),J'];
end

Hi this program is very helpful for me.
I'm studying to create 3D structure model.
Can you share more about this program detail?
I want to create more different model.

Alex H

Hi this is extremely helpful for me. Thanks for developing this.

However, sometimes these errors appears. Sometimes it does not.

-----------------------------
Error using dialogCellstrHelper
Expected input to be one of these types:

char, cell

Instead its type was double.

Error in dialogCellstrHelper (line 10)
validateattributes(inputStr, {'char','cell'}, {'2d'},mfilename);

Error in msgbox (line 62)
BodyTextString = dialogCellstrHelper(inputStr);

Error in Lattice_cell (line 186)
msgbox(string,'Lattice Generator','modal')

Error in Lattice_GUI_v0a_extended>generate_Callback (line 105)
Lattice_cell(handles.lattice,handles.FEvars,handles.misc);

Error in gui_mainfcn (line 95)
feval(varargin{:});

Error in Lattice_GUI_v0a_extended (line 42)
gui_mainfcn(gui_State, varargin{:});

Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Lattice_GUI_v0a_extended('generate_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback

Marten

Hi Jay, thanks for your feedback! Yes in this function the ends are left open (holes) but you shouldn't see inverted normals. There are some cross over with variable names in new versions of Matlab I've noticed, but haven't had a chance to change that as yet. I don't believe it effects the overall operation though.
As referred to in the documentation, the ends can easily be filled by the fill hole function in a program like Meshlab (or Magics if you've got it). Implementation in Matlab was a little clumsy so it wasn't included here.. sorry about that.

Jay Muller

Thanks very much for your work on this -- it seems to be a great tool. However, on my Matlab version (2015a) only the edges are generated, but no vertices/corner points, leaving the structure disconnected. Also, when I check the generated stl for errors (in e.g. Magics), it detects numerous inverted normals, holes and bad edges. Is there a newer version available where these issues are fixed?

Updates

1.4.0.0

New features and significant performance improvements have been added with this version, including: Binary STL file support, a new rapid uniform lattice creation option, new bulk form STL writing, and new cell types.

1.3.0.0

Bug fixes

1.2.0.0

Bug fixes and added cell types (FCC with added Z struts)

1.1.0.0

Full scripts and GUIs now available.

MATLAB Release Compatibility
Created with R2011b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: geom3d, Quaternions