CadQuery / CadQuery/cadquery

select faces by their age

Open
#1,104 1 comment 0 reactions 0 assignees View on GitHub
question
Dominant language
Python
Stars
5.8k
Forks
541
Avg merge
3d 2h
Merged PRs (30d)
5

Description

When modelling parametric pieces with a lot of steps, I find it hard to select the right faces with the existing Selectors. For instance, the order of the faces might change depending on the input parameters making the selector `faces(">Z")` hard to use.

So I was looking at ways to select faces by their age in the chain of parent workplanes.

1. I first thought about patching functions like the `extrude`, `revolve`,`loft`, so that they add data to the workplane with information about the newly created faces. This information could be access to create new workplanes. However as seen in another issue, the workplane class seems rigid and not prone to changes.
2. then i thought about comparing if faces from `object.faces().objects` are equal to faces in `object.parent.faces().objects`. However, when a face is modified by making a hole in it for example, the orgin face doesn't match with the modified face for obvious reason. I then noticed that the new not modified faces are added at the end of the `object.faces().objects` list, but I am not sure that I can trust the order of the faces in the list to determine their age.

Here is the sample code and piece that I used to experiment on this :
```
import cadquery as cq

out = cq.Workplane('XY').box(10,10,5,centered=(1,1,0))
out2 = out.faces('>Z').workplane().rect(3,3).extrude(4)

fout = out.faces().objects
fout2 = out2.faces().objects

#print the corresponding index of the face in the old version of the piece
print([ fout.index(a) if a in fout else None for a in fout2 ])
print([ a.Center() for a in fout2 ])
show_object(out2)
```
```
output :
[0, 2, None, 3, 4, 1, None, None, None, None, None]
[Vector: (-5, 0 , 2.5),
Vector: (0, -5 , 2.5),
Vector: (0 , 0 , 5 ),
Vector: (0 , 5.0, 2.5),
Vector: (0 , 0 , 0),
Vector: (5.0, 0 , 2.5),
Vector: (0 , -1.5, 7.0),
Vector: (1.5, 0 , 7.0),
Vector: (0 , 1.5, 7.0),
Vector: (-1.5, 0 , 7.0),
Vector: ( 0 , 0 , 9.0)]
```
![image](https://user-images.githubusercontent.com/23189926/173165357-2bbc4ca6-4b59-4e56-a935-3157e6f969e0.png)

I have the following questions :
- Is selecting faces by their age, a valid workflow ? Or is there a other way to mitigate selector fuzzyness ?
- Then should I go with my first or second option (or another) ?
- Then is there a safe way to access the new (and not modified) faces ?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.