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.clone() #1643

Open
wirekang opened this issue Aug 10, 2024 · 2 comments
Open

Workplane.clone() #1643

wirekang opened this issue Aug 10, 2024 · 2 comments
Labels
consistency enhancement New feature or request

Comments

@wirekang
Copy link

I know I can define a function or use w1.translate((0,0,0)) to create a new reference, but it would be great if there is a simple clone method:

w1 = cq.Workplane().box(1,2,3)
w2 = w1.clone()

w2.add(...)
    def clone(self: T) -> T:
        return self.newObject([*self.objects])
@adam-urbanczyk
Copy link
Member

What is the use case? I.e. are you after a deep or shallow copy in the end?

@adam-urbanczyk adam-urbanczyk added enhancement New feature or request consistency labels Aug 11, 2024
@wirekang
Copy link
Author

I thought CadQuery is based on immutable objects, since there are chaining methods with description Returns a copy of.... So the use case I thought was like:

left_pin = cq.Workplane()...
right_pin = left_pin.translate((0,0,0)) // Oh this is so hacky
cq.Assembly().add(left_pin).add(right_pin)...

You know this is wrong. They shares many things like CQObject and CQContext. If I understand correctly, newObject has nothing to do with immutable but for parent stack.

So if there is a clone method, it should deep copy everything, but I can't sure this kind of approche is valid in CadQuery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consistency enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants