MCPcopy
hub / github.com/ManimCommunity/manim / add

Method add

manim/mobject/mobject.py:464–550  ·  view source on GitHub ↗

Add mobjects as submobjects. The mobjects are added to :attr:`submobjects`. Subclasses of mobject may implement ``+`` and ``+=`` dunder methods. Parameters ---------- mobjects The mobjects to add. Returns ------- :class:

(self, *mobjects: Mobject)

Source from the content-addressed store, hash-verified

462 """
463
464 def add(self, *mobjects: Mobject) -> Self:
465 """Add mobjects as submobjects.
466
467 The mobjects are added to :attr:`submobjects`.
468
469 Subclasses of mobject may implement ``+`` and ``+=`` dunder methods.
470
471 Parameters
472 ----------
473 mobjects
474 The mobjects to add.
475
476 Returns
477 -------
478 :class:`Mobject`
479 ``self``
480
481 Raises
482 ------
483 :class:`ValueError`
484 When a mobject tries to add itself.
485 :class:`TypeError`
486 When trying to add an object that is not an instance of :class:`Mobject`.
487
488
489 Notes
490 -----
491 A mobject cannot contain itself, and it cannot contain a submobject
492 more than once. If the parent mobject is displayed, the newly-added
493 submobjects will also be displayed (i.e. they are automatically added
494 to the parent Scene).
495
496 See Also
497 --------
498 :meth:`remove`
499 :meth:`add_to_back`
500
501 Examples
502 --------
503 ::
504
505 >>> outer = Mobject()
506 >>> inner = Mobject()
507 >>> outer = outer.add(inner)
508
509 Duplicates are not added again::
510
511 >>> outer = outer.add(inner)
512 >>> len(outer.submobjects)
513 1
514
515 Only Mobjects can be added::
516
517 >>> outer.add(3)
518 Traceback (most recent call last):
519 ...
520 TypeError: Only values of type Mobject can be added as submobjects of Mobject, but the value 3 (at index 0) is of type int.
521

Callers 15

test_mobject_copyFunction · 0.95
test_familyFunction · 0.95
test_mobject_addFunction · 0.95
test_mobject_removeFunction · 0.95
__init__Method · 0.45
_add_bracketsMethod · 0.45
__init__Method · 0.45
__init__Method · 0.45
_add_created_vertexMethod · 0.45
_add_edgeMethod · 0.45
__init__Method · 0.45

Calls 3

remove_list_redundanciesFunction · 0.85
list_updateFunction · 0.85

Tested by 4

test_mobject_copyFunction · 0.76
test_familyFunction · 0.76
test_mobject_addFunction · 0.76
test_mobject_removeFunction · 0.76