stl Package

stl Module

Inheritance diagram of pyNastran.converters.stl.stl
class pyNastran.converters.stl.stl.STL(log=None, debug=False)[source]

Bases: object

Initializes the STL object

Parameters:
debug : bool/None; default=True
used to set the logger if no logger is passed in

True: logs debug/info/error messages False: logs info/error messages None: logs error messages

log : logging module object / None

if log is set, debug is ignored and uses the settings the logging object has

create_mirror_model(self, xyz, tol)[source]

Creates a mirror model.

Parameters:
xyz : str {x, y, z}

the direction of symmetry

tol: float

the tolerance for symmetry plane nodes

.. note:: All elements on the symmetry plane will be removed
equivalence_nodes(self, tol=1e-05)[source]

equivalences the nodes of the model and updates the elements

flip_axes(self, axes, scale)[source]

Swaps the axes

Parameters:
axes : str

‘xy’, ‘yz’, ‘xz’

scale : float

why is this here, but is not applied to all axes?

flip_normals(self, i=None)[source]

Flips the normals of the specified elements.

Parameters:
i : (n, ) ndarray ints; default=None -> all

the indicies to flip

get_area(self, elements, stop_on_failure=True)[source]
get_normals(self, elements, stop_on_failure=True)[source]
Parameters:
elements : (n, 3) ndarray ints

the elements to get the normals for

nodes : (n, ) ndarray; default=None -> all

a subset of the nodes

stop_on_failure : bool (default=True)

True: crash if there are coincident points False: delete elements

get_normals_at_nodes(self, normals=None, nid_to_eid=None)[source]

Calculates the normal vector of the nodes based on the average element normal.

Parameters:
normals : (n, 3) ndarray floats

The elemental normals

nid_to_eid : Dict[int] = [int, int, … ]

key = node_id value = list of element_ids

Returns:
normals_at_nodes : (nnodes, 3) ndarray ints

the normals

read_ascii_stl(self, stl_filename)[source]

Reads an STL that’s in ASCII format

read_binary_stl(self, stl_filename)[source]

Read an STL binary file

Parameters:
stl_filename : str

the filename to read

read_stl(self, stl_filename)[source]

Reads an STL file

Parameters:
stl_filename : str

the filename to read

remove_elements_with_bad_normals(self)[source]

removes dot and line elements

scale_nodes(self, xscale, yscale=None, zscale=None)[source]

Scales the model

Parameters:
xscale : float

the scaling factor for the x axis; also the default scaling factor

yscale/zscale : float; default=xscale

the scaling factors for the y/z axes

shift_nodes(self, xshift, yshift, zshift)[source]

Shifts the model

write_binary_stl(self, stl_filename, normalize_normal_vectors=False, stop_on_failure=True)[source]

Write an STL binary file

Parameters:
stl_filename : str

the filename to read

normalize_normal_vectors : bool; default=False

should the vectors be normalized

write_stl(self, stl_out_filename, is_binary=False, float_fmt='%6.12f', normalize_normal_vectors=False, stop_on_failure=True)[source]

Writes an STL file

Parameters:
stl_out_filename : str

the filename to write

is_binary : bool; default=False

should a binary file be written

float_fmt : str; default=’%6.12f’

the format to use if an ASCII file is used

normalize_normal_vectors : bool; default=False

should the vectors be normalized

write_stl_ascii(self, out_filename, solid_name, float_fmt='%.6f', normalize_normal_vectors=False, stop_on_failure=True)[source]

Writes an STL in ASCII format

solid solid_name
facet normal -6.601157e-001 6.730213e-001 3.336009e-001
outer loop
vertex 8.232952e-002 2.722531e-001 1.190414e+001 vertex 8.279775e-002 2.717848e-001 1.190598e+001 vertex 8.557653e-002 2.745033e-001 1.190598e+001

endloop

endfacet

end solid

pyNastran.converters.stl.stl.read_stl(stl_filename, remove_elements_with_bad_normals=False, log=None, debug=False)[source]

Reads an STL file

Parameters:
stl_filename : str

the filename to read

remove_elements_with_bad_normals : bool; default=False

removes elements with NAN normal

Returns:
model : STL()

the stl model

stl_mesh Module

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.479.8237&rep=rep1&type=pdf http://math.stackexchange.com/questions/4322/check-whether-a-point-is-within-a-3d-triangle https://en.wikipedia.org/wiki/Barycentric_coordinate_system http://en.wikipedia.org/wiki/Line-plane_intersection http://math.stackexchange.com/questions/544946/determine-if-projection-of-3d-point-onto-plane-is-within-a-triangle

pyNastran.converters.stl.dev.stl_mesh.build()[source]
pyNastran.converters.stl.dev.stl_mesh.main()[source]
pyNastran.converters.stl.dev.stl_mesh.project_curve_onto_stl(stl, points, npoints=11)[source]

top down projection

pyNastran.converters.stl.dev.stl_mesh.project_line_onto_stl(stl, pa, pb, npoints=11)[source]

top down projection

pyNastran.converters.stl.dev.stl_mesh.project_points_onto_stl(stl, points)[source]
Parameters:
nodes : (n, 3) ndarray floats

The nodes on the surface.

elements : (n, 3) ndarray ints

The elements on the surface.

pyNastran.converters.stl.dev.stl_mesh.projected_barycentric_coord(p, q, u, v)[source]

points p, q vector u, v

3

*v

/ <—-p

q*—-*u 1 2 u = p2 - p1 v = p3 - p1

stl_reshape Module

pyNastran.converters.stl.stl_reshape.main()[source]
pyNastran.converters.stl.stl_reshape.stl_reshape(data)[source]

stl_to_cart3d Module

pyNastran.converters.stl.stl_to_cart3d.stl_to_cart3d(stl_filename, cart3d_filename=None, log=None, debug=False, is_binary=False, float_fmt='%6.7f')[source]

Converts a Cart3D object to STL format.

Parameters:
stl_filename : str / STL()

str : path to the input STL file STL() : an STL object

cart3d_filename : str; default=None

str : path to the output Cart3D file (or None to skip)

log : log

a logger object (or None)

debug : bool; default=False

True/False (used if log is not defined)

is_binary : bool; default=False

should the cart3d file be binary

float_fmt : str; default=‘6.7f’

the cart3d node precision

Returns:
stl : STL()

an STL object

stl_to_nastran Module

pyNastran.converters.stl.stl_to_nastran.stl_to_nastran(stl_filename, bdf_filename, nnodes_offset=0, nelements_offset=0, pid=100, mid=200, size=8, is_double=False, log=None)[source]
pyNastran.converters.stl.stl_to_nastran.stl_to_nastran_filename(stl_filename, bdf_filename, nnodes_offset=0, nelements_offset=0, pid=100, mid=200, size=8, is_double=False, log=None)[source]

utils Module

pyNastran.converters.stl.utils.merge_stl_files(stl_filenames, stl_out_filename=None, remove_bad_elements=False, is_binary=True, float_fmt='%6.12f', log=None)[source]

Combines multiple STLs into a single file

Parameters:
stl_filenames : List[str, str, …]

list of stl filenames or a string filename (useful for removing bad elements)

remove_bad_elements : bool; default=False

should elements with invalid normals be removed?

stl_out_filename : str; default=None -> no writing

string of stl output filename

is_binary : bool; default=True

should the output file be binary

float_fmt : str; default=’%6.12f’

the ascii float format

Returns:
stl : STL()

the stl object