Test selectors with shapes
(self)
| 1148 | gram.parse_string(e, parse_all=True) |
| 1149 | |
| 1150 | def testShape(self): |
| 1151 | """ |
| 1152 | Test selectors with shapes |
| 1153 | """ |
| 1154 | |
| 1155 | def check_centers(w, s): |
| 1156 | self.assertTupleAlmostEquals( |
| 1157 | w.val().Center().toTuple(), s.Center().toTuple(), 6 |
| 1158 | ) |
| 1159 | |
| 1160 | w = Workplane().box(3, 2, 1) |
| 1161 | s = w.val() |
| 1162 | |
| 1163 | res1 = s.solids() |
| 1164 | |
| 1165 | assert res1.ShapeType() == "Solid" |
| 1166 | |
| 1167 | res2 = s.faces(">Z") |
| 1168 | res2_w = w.faces(">Z") |
| 1169 | |
| 1170 | check_centers(res2_w, res2) |
| 1171 | |
| 1172 | res3 = s.wires(">Z") |
| 1173 | res3_w = w.wires(">Z") |
| 1174 | |
| 1175 | assert res3.ShapeType() == "Wire" |
| 1176 | check_centers(res3_w, res3) |
| 1177 | |
| 1178 | res4 = s.edges(">Z") |
| 1179 | |
| 1180 | assert res4.ShapeType() == "Compound" |
| 1181 | |
| 1182 | res5 = s.edges(">Z").edges(">X") |
| 1183 | res5_w = w.edges(">Z").edges(">X") |
| 1184 | |
| 1185 | check_centers(res5_w, res5) |
| 1186 | assert res5.ShapeType() == "Edge" |
| 1187 | |
| 1188 | res6 = s.vertices(">Z").vertices(">X and >Y") |
| 1189 | res6_w = w.vertices(">Z").vertices(">X and >Y") |
| 1190 | |
| 1191 | assert res6.ShapeType() == "Vertex" |
| 1192 | check_centers(res6_w, res6) |
| 1193 | |
| 1194 | res7 = s.shells(">Z") |
| 1195 | res7_w = w.shells(">Z") |
| 1196 | |
| 1197 | check_centers(res7_w, res7) |
| 1198 | assert res7.ShapeType() == "Shell" |
| 1199 | |
| 1200 | res8 = s.faces(selectors.DirectionMinMaxSelector(Vector(0, 0, 1))) |
| 1201 | res8_w = w.faces(">Z") |
| 1202 | |
| 1203 | check_centers(res8_w, res8) |