stl Package

stl Module

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

Bases: object

Initializes the STL object

Parameters
debugbool/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

loglogging module object / None

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

create_mirror_model(xyz, tol: float) → None[source]

Creates a mirror model.

Parameters
xyzstr {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(tol: float = 1e-05) → None[source]

equivalences the nodes of the model and updates the elements

flip_axes(axes, scale)[source]

Swaps the axes

Parameters
axesstr

‘xy’, ‘yz’, ‘xz’

scalefloat

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

flip_normals(i=None) → None[source]

Flips the normals of the specified elements.

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

the indicies to flip

get_area(elements, stop_on_failure: bool = True)[source]
get_normals(elements, stop_on_failure: bool = 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_failurebool (default=True)

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

get_normals_at_nodes(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_eidDict[int] = [int, int, … ]

key = node_id value = list of element_ids

Returns
normals_at_nodes(nnodes, 3) ndarray ints

the normals

read_ascii_stl(stl_filename: str) → None[source]

Reads an STL that’s in ASCII format

read_binary_stl(stl_filename: str) → None[source]

Read an STL binary file

Parameters
stl_filenamestr

the filename to read

read_stl(stl_filename: str) → None[source]

Reads an STL file

Parameters
stl_filenamestr

the filename to read

remove_elements_with_bad_normals()[source]

removes dot and line elements

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

Scales the model

Parameters
xscalefloat

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

yscale/zscalefloat; default=xscale

the scaling factors for the y/z axes

shift_nodes(xshift, yshift, zshift)[source]

Shifts the model

write_binary_stl(stl_filename: str, normalize_normal_vectors: bool = False, stop_on_failure=True) → None[source]

Write an STL binary file

Parameters
stl_filenamestr

the filename to read

normalize_normal_vectorsbool; default=False

should the vectors be normalized

write_stl(stl_out_filename: str, is_binary: bool = False, float_fmt: str = '%6.12f', normalize_normal_vectors: bool = False, stop_on_failure: bool = True) → None[source]

Writes an STL file

Parameters
stl_out_filenamestr

the filename to write

is_binarybool; default=False

should a binary file be written

float_fmtstr; default=’%6.12f’

the format to use if an ASCII file is used

normalize_normal_vectorsbool; default=False

should the vectors be normalized

write_stl_ascii(out_filename: str, solid_name: str, float_fmt: str = '%.6f', normalize_normal_vectors: bool = False, stop_on_failure: bool = True) → None[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: str, remove_elements_with_bad_normals: bool = False, log: Optional[cpylog.SimpleLogger] = None, debug: bool = False)[source]

Reads an STL file

Parameters
stl_filenamestr

the filename to read

remove_elements_with_bad_normalsbool; default=False

removes elements with NAN normal

Returns
modelSTL()

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_filenamestr / STL()

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

cart3d_filenamestr; default=None

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

loglog

a logger object (or None)

debugbool; default=False

True/False (used if log is not defined)

is_binarybool; default=False

should the cart3d file be binary

float_fmtstr; default=’6.7f’

the cart3d node precision

Returns
stlSTL()

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_filenamesList[str, str, …]

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

remove_bad_elementsbool; default=False

should elements with invalid normals be removed?

stl_out_filenamestr; default=None -> no writing

string of stl output filename

is_binarybool; default=True

should the output file be binary

float_fmtstr; default=’%6.12f’

the ascii float format

Returns
stlSTL()

the stl object