Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workplane translate does not move the tags #1619

Closed
lenianiva opened this issue Jul 1, 2024 · 3 comments
Closed

Workplane translate does not move the tags #1619

lenianiva opened this issue Jul 1, 2024 · 3 comments
Labels
question Further information is requested

Comments

@lenianiva
Copy link
Contributor

lenianiva commented Jul 1, 2024

Consider this example which should produce 3 cubes stacked on top of each other:

import cadquery as Cq

def tagged_box(tag=""):
    result = (
        Cq.Workplane('XY')
        .box(10, 10, 10)
    )
    result.faces("<Z").tag(f"{tag}bot")
    result.faces(">Z").tag(f"{tag}top")
    return result

def tagged_double_box():
    result = (
        tagged_box("b1_")
        .union(
            tagged_box("b2_")
            .translate((0, 0, 5))
            .rotate((0, 0, 0), (0, 0, 1), 45)
        )
    )
    return result

result = (
    Cq.Assembly()
    .add(tagged_box(), name="parent", color=Cq.Color("blue1"))
    .add(tagged_double_box(), name="child", color=Cq.Color("yellow1"))
    .constrain("parent?bot", "child?b2_top", "Plane")
    .solve()
)

show_object(result)

but instead the mating surface child?b2_top stays in place, despite that the object was moved up by 5mm.

image

Is this intended behaviour? How can I get the tag b2_top to move during .translate()?

One solution here is to use sub-assemblies.

@lorenzncode
Copy link
Member

Methods such as translate create new Workplane objects in the chain.

See also docs introspective example for more. It should help with tags usage. https://cadquery.readthedocs.io/en/latest/primer.html#an-introspective-example:
Returning a new instance of Workplane is the normal behaviour of most Workplane methods...
Tags offer a way to refer back to a previous Workplane

@lenianiva
Copy link
Contributor Author

Methods such as translate create new Workplane objects in the chain.

See also docs introspective example for more. It should help with tags usage. https://cadquery.readthedocs.io/en/latest/primer.html#an-introspective-example: Returning a new instance of Workplane is the normal behaviour of most Workplane methods... Tags offer a way to refer back to a previous Workplane

Is there a way to move all objects in a workplane while preserving the tags?

@lorenzncode
Copy link
Member

Yes, it's possible. There is no built-in method, but can be done as follows:

  1. Iterate over <the Workplane>.ctx.tags.values()
  2. Directly update each tagged Workplane object list (translate each object)

@adam-urbanczyk adam-urbanczyk added the question Further information is requested label Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants