How to copy the last object on the stack, and move it?

687 views
Skip to first unread message

Lee

unread,
May 29, 2021, 12:47:14 PM5/29/21
to CadQuery
I'm trying to duplicate pending wires which I can move and then loft to, but there seems to be no obvious way to do this. I thought copy() would work but nope. Maybe it's the way I'm using it?

If it is possible, could someone write an example which uses a simple box, selects a face, copies the face, moves the face, and then lofts between the two?

Thank you!

Adam Urbanczyk

unread,
May 30, 2021, 4:57:06 AM5/30/21
to CadQuery
You can achieve this using translate and toPending

res = (
    cq.Workplane()
    .box(1,1,1)
    .wires('>Z').toPending()
    .translate((1,0,1)).toPending()
    .loft()
)

You might be also interested later on in using rotate in a similar way:

res = (
    cq.Workplane()
    .box(1,1,1)
    .wires('>Z').toPending()
    .translate((1,.1,1)).rotate((0,0,0),(0,0,1),45).toPending()
    .loft()
)

Marcus Boyd

unread,
May 30, 2021, 6:14:26 AM5/30/21
to CadQuery
This felt like a good example to get into the internals of CQ a bit more. There are 3 main concepts in the CQ code (Workplane.objects, the parent chain, and the modelling context) that once you understand, the rest of the codebase all sort of falls into place (IMHO). I've created a gist here to explain more: cq-internal-example.md

Please ask questions or give feedback if you have any. If this is helpful enough I might expand and tidy it up a bit and see if it can go in the CQ HTML docs.

--
cadquery home: https://github.com/CadQuery/cadquery
post issues at https://github.com/CadQuery/cadquery/issues
run it at home at : https://github.com/CadQuery/CQ-editor
---
You received this message because you are subscribed to the Google Groups "CadQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cadquery+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cadquery/77c895d3-ce44-437f-9da2-2c19c2b3172en%40googlegroups.com.

Jojain

unread,
May 30, 2021, 9:56:42 AM5/30/21
to CadQuery
That's very interesting, I didn't know how it worked. This means every step towards a model is saved in memory ? So it is possible to access let's say the step N - 3 from a Workplane at step N ?

Lee

unread,
May 30, 2021, 9:57:59 AM5/30/21
to CadQuery
Thank you very much. The examples are exactly what I needed, and the detailed example is even more helpful.

Marcus Boyd

unread,
May 30, 2021, 8:05:17 PM5/30/21
to Jojain, CadQuery
On Sun, 30 May 2021 at 23:26, Jojain <romain...@gmail.com> wrote:
That's very interesting, I didn't know how it worked. This means every step towards a model is saved in memory ? So it is possible to access let's say the step N - 3 from a Workplane at step N ?

Yes, that's right. The Workplane.end method does exactly that, part.end(-3) would return the Workplane object from the N - 3 step.

Tags do a very similar thing, they just use a string label instead of an index.

Ami Fischman

unread,
May 31, 2021, 2:56:11 PM5/31/21
to Marcus Boyd, CadQuery
Thanks for writing that up Marcus, I found it very helpful, and would indeed have liked for it to be integrated in the docs.

Here's an adaptation of your approach hooked into python's profile API to allow tracing fluent calls without explicit print() statements at each step. The down-side is that it's more verbose and likely harder to map to user-written code, the up-side is greater coverage and lower friction. 

I wonder if something along these lines would be a useful addition to CQ itself, e.g. cq.enable_debug_tracing() or somesuch.


Adam Urbanczyk

unread,
May 31, 2021, 4:53:31 PM5/31/21
to CadQuery
Tracing is not core CQ business, better leave this to specialized modules like https://github.com/ionelmc/python-hunter.
Reply all
Reply to author
Forward
0 new messages