Open smurfix opened 10 months ago
The import_stl script worked for me after splitting the original mesh (https://github.com/JustinSDK/cqMore/issues/7).
# numpy-stl 2.16 or later is required.
from stl.mesh import Mesh
from cqmore import Workplane
def import_stl(fileName):
vectors = Mesh.from_file(fileName).vectors
points = tuple(map(tuple, vectors.reshape((vectors.shape[0] * vectors.shape[1], 3))))
faces = [(i, i + 1, i + 2) for i in range(0, len(points), 3)]
return Workplane().polyhedron(points, faces)
# projection.stl from https://github.com/openscad/openscad/blob/master/examples/Basics/projection.stl
part0 = import_stl("projection_part_0.stl")
part1 = import_stl("projection_part_1.stl").translate((10, 0, 0))
Here shown in cq-editor and admeshgui (used to split mesh):
Owch. Is there a way to do the splitting in CQ? Telling people "no you can't import a mesh with more than one part" isn't what I'd like to be doing here.
The import STL script function is a cqMore feature not a cadquery feature. Changes to cqMore are required to handle this STL without split.
Regarding cadquery Shell.makeShell
, as tested here https://github.com/CadQuery/cadquery/blob/e9b8b31f6a5421c1692b4e722e89d64736e349ca/tests/test_cadquery.py#L3940 the wrapped object is TopoDS_Shell
.
I confirm that with multiple sets of faces, the wrapped object is a TopoDS_Compound
- in the following example containing two shells.:
import cadquery as cq
b0 = cq.Workplane().box(10, 10, 10)
b1 = cq.Workplane().box(2, 2, 2)
f0 = b0.faces().vals()
f1 = b1.faces().vals()
#faces = f0
faces = f0.copy()
faces.extend(f1)
shell = cq.Shell.makeShell(faces)
I'm calling
cadquery.occ_impl.shapes.Solid.makeSolid
with acadquery.occ_impl.shapes.Shell
object.The body of this function is the one-liner
My problem is that
SolidFromShell
complains that it wants anOCP.TopoDS.TopoDS_Shell
object as a parameter.shell.wrapped
however contains anOCP.TopoDS.TopoDS_Compound
:Naïvely I'd assume that wrapping a shell returns, well, the appropriate shell object.
Is that a bug? if not how do I call this correctly?
My usecase is importing an STL mesh, using the script at https://github.com/JustinSDK/cqMore/blob/main/examples/import_stl.py – if there's another / better / less-buggy way of doing this I'm all ears.