Extracting cross section from step model

23 views
Skip to first unread message

Dan Peirce

unread,
Feb 27, 2024, 4:23:46 PMFeb 27
to CadQuery
I'm new to CadQuery and looking for s simple example that extracts a 2d cross section from a 3d model at a distance above the xy plain.

Neri

unread,
Feb 27, 2024, 4:55:13 PMFeb 27
to CadQuery
Just so we're on the same page, are you looking for something that resembles this?

xsection.png

Just so you know I did this with another tool, but used some home-grown techniques.
Have not tried with CadQuery yet, can only offer insights into home-grown solutions, and not so much "the standard way of doing things".

Dan Peirce

unread,
Feb 27, 2024, 7:01:32 PMFeb 27
to CadQuery
The model I am working on is far simpler that that. I can do it in OpenSCAD with

translate([0, 0, -vert_offset]) projection(cut=true) model3d;

That results in a 2D representation of the intersection of the xy plain and the 3d model.
I was wondering if there is a similar method in CadQuery. I have not spotted an example.

Neri

unread,
Feb 27, 2024, 7:53:28 PMFeb 27
to CadQuery
Holy smokes!  I didn't even realize that the mentioned OpenSCAD construct existed!

I don't have an answer for you as far as best practices in CadQuery.  Only a very naive approach comes to mind which I have not tried yet, which is to use cut() with a box which is infinitesimally thin, but spans two dimensions with a very big length.  Once you cut(), then of course you''ll be left with a paper-thin cross section of your model.

I am just doing a best guess, and I have to admit that I have not yet solved this problem myself; I have only thought about it.

I am guessing that you may be interested in programmatically generating a PNG image or an SVG outline of your cutaway?
In that case, I'll state that I'm working on these aspects, and the E.T.A. is about two weeks.  SVG generation code already exists and is working decently by the way; it's part of the exporters.

Neri

unread,
Feb 27, 2024, 7:59:05 PMFeb 27
to CadQuery
Sorry I meant intersect().
I tend to brain fart while I'm working on really hard math problems.
I'm sure there's a better way BTW.

Lorenz

unread,
Feb 27, 2024, 8:24:54 PMFeb 27
to CadQuery
See  Workplane.section().

Here is an exampe.

import cadquery as cq

res = cq.importers.importStep("thefile.step")

sec10 = res.section(10)
sec90 = res.section(90)

dxf = cq.exporters.dxf.DxfDocument()
dxf.add_layer("layer1", color=1)
dxf.add_layer("layer2", color=2)
dxf.add_shape(sec10, "layer1")
dxf.add_shape(sec90, "layer2")
dxf.document.saveas("test.dxf")
Reply all
Reply to author
Forward
0 new messages