MCPcopy
hub / github.com/CadQuery/cadquery / remove

Method remove

cadquery/assembly.py:282–315  ·  view source on GitHub ↗

Remove a part/subassembly from the current assembly. :param name: Name of the part/subassembly to be removed :return: The modified assembly *NOTE* This method can cause problems with deeply nested assemblies and does not remove constraints associated with t

(self, name: str)

Source from the content-addressed store, hash-verified

280 return self
281
282 def remove(self, name: str) -> "Assembly":
283 """
284 Remove a part/subassembly from the current assembly.
285
286 :param name: Name of the part/subassembly to be removed
287 :return: The modified assembly
288
289 *NOTE* This method can cause problems with deeply nested assemblies and does not remove
290 constraints associated with the removed part/subassembly.
291 """
292
293 # Make sure the part/subassembly is actually part of the assembly
294 if name not in self.objects:
295 raise ValueError(f"No object with name '{name}' found in the assembly")
296
297 # Get the part/assembly to be removed
298 to_remove = self.objects[name]
299
300 # Remove the part/assembly from the parent's children list
301 if to_remove.parent:
302 to_remove.parent.children.remove(to_remove)
303
304 # Remove the part/assembly from the assembly's object dictionary
305 del self.objects[name]
306
307 # Remove all descendants from the objects dictionary
308 for descendant_name in to_remove._flatten().keys():
309 if descendant_name in self.objects:
310 del self.objects[descendant_name]
311
312 # Update the parent reference
313 to_remove.parent = None
314
315 return self
316
317 def _query(self, q: str) -> Tuple[str, Optional[Shape]]:
318 """

Callers 15

deleteMethod · 0.45
__delitem__Method · 0.45
test_removeFunction · 0.45
test_sewingFunction · 0.45
_wFunction · 0.45
TVFunction · 0.45
rFunction · 0.45

Calls 1

_flattenMethod · 0.80

Tested by 7

test_removeFunction · 0.36
test_sewingFunction · 0.36