1
+ """Generates and sets a MoGraph selection tag on a MoGraph cloner object.
2
+
3
+ Effectively, this will create a selection tag for all uneven clones in the cloner object. This script
4
+ has no runtime requirements, as it creates its inputs itself.
5
+
6
+ Class/method highlighted:
7
+ - c4d.modules.mograph.GeSetMoDataSelection()
8
+
9
+ Note:
10
+
11
+ This example has been updated as it was a bit thin-lipped in its old form, and uses now some
12
+ newer feature of the Python API, such as exposed symbols, type hinting, and streamlined type
13
+ validation. This script requires Cinema 4D R2024.0.0 or later due to that. The core functionality
14
+ of setting a MoGraph selection is available from R18 out, just as its neighboring examples. See
15
+ older releases of the Python SDK for an R18 version of this example.
16
+ """
17
+ __author__ = "Maxime Adam, Ferdinand Hoppe"
18
+ __copyright__ = "Maxon Computer GmbH"
19
+ __version__ = "2024.0.0"
20
+
21
+ import c4d
22
+ import mxutils
23
+
24
+ doc : c4d .documents .BaseDocument # The active document.
25
+
26
+ def main () -> None :
27
+ """Invoked by Cinema 4D when the script is run.
28
+ """
29
+ # Create a cloner object in linear mode with 10 clones, a cube object child, a MoGraph
30
+ # selection tag on it, and then insert it into the active document.
31
+ count : int = 10
32
+ cloner : c4d .BaseObject = mxutils .CheckType (c4d .BaseObject (c4d .Omgcloner ))
33
+ cloner [c4d .ID_MG_MOTIONGENERATOR_MODE ] = c4d .ID_MG_MOTIONGENERATOR_MODE_LINEAR
34
+ cloner [c4d .MG_LINEAR_COUNT ] = count
35
+ cube : c4d .BaseObject = mxutils .CheckType (c4d .BaseObject (c4d .Ocube ))
36
+ cube [c4d .PRIM_CUBE_LEN ] = c4d .Vector (10 )
37
+ cube .InsertUnder (cloner )
38
+
39
+ tag : c4d .BaseTag = mxutils .CheckType (cloner .MakeTag (c4d .Tmgselection ))
40
+ tag [c4d .MGSELECTIONTAG_NUMBERS ] = True # Enable displaying index numbers in the viewport.
41
+ tag .SetBit (c4d .BIT_ACTIVE ) # Select the tag, so that the indices are drawn in the viewport.
42
+
43
+ doc .InsertObject (cloner )
44
+
45
+ # Selections in Cinema 4D are a list of states. When we want to create a selection that selects
46
+ # all uneven elements, we have to go `False, True, False, True, ...` until we reach the last
47
+ # element (because the first element is the element with index 0).
48
+ states : list [bool ] = [i % 2 == 1 for i in range (count )]
49
+ print (f"{ states = } " )
50
+
51
+ # Create a new selection, set our states for the clones, and finally write the selection
52
+ # to the MoGraph selection tag.
53
+ selection : c4d .BaseSelect = c4d .BaseSelect ()
54
+ selection .SetAll (states )
55
+ c4d .modules .mograph .GeSetMoDataSelection (tag , selection )
56
+
57
+ # Inform Cinema 4D that the UI should be updated.
58
+ c4d .EventAdd ()
59
+
60
+ if __name__ == '__main__' :
61
+ main ()
0 commit comments