Repository navigation
Expand file tree
/
Copy pathmodeling_command_current_state.py
More file actions
59 lines (47 loc) · 2.26 KB
/
Copy pathmodeling_command_current_state.py
File metadata and controls
59 lines (47 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#coding: utf-8
"""Demonstrates how to execute the 'Current State to Object' tool.
Invokes 'Current State to Object' on the currently selected object in the active document via
`SendModelingCommand`. 'Current State to Object' is often the better alternative to evaluating the
caches of an object or BaseDocument.Polygonize() when a collapsed PointObject representation of a
generator chain is required.
Topics:
* The 'Current State to Object' tool
* c4d.utils.SendModelingCommand()
Note:
See `modeling_command_extrude.py` for a more in depth overview of the topic of `SendModelingCommand`.
"""
__author__ = "Ferdinand Hoppe"
__copyright__ = "Copyright (C) 2026 MAXON Computer GmbH"
__date__ = "08/04/2022"
__license__ = "Apache-2.0 License"
__version__ = "S26"
import c4d
import typing
doc: c4d.documents.BaseDocument # The currently active document.
op: typing.Optional[c4d.BaseObject] # The selected object within that active document. Can be None.
def main(doc: c4d.documents.BaseDocument, op: typing.Optional[c4d.BaseObject]) -> None:
"""Runs the example.
Args:
doc: The active document.
op: The selected object in #doc. Can be #None.
"""
if not isinstance(op, c4d.BaseObject):
raise TypeError(f"Please select an object.")
# The settings of 'Current State to Object'. The tool has multiple settings (which are not
# directly accessible for the user in the app) but none of them are relevant in this example
# and because of that, the tool container can remain empty.
bc = c4d.BaseContainer()
# Execute the command with the undo flag set.
res = c4d.utils.SendModelingCommand(command=c4d.MCOMMAND_CURRENTSTATETOOBJECT,
list=[op],
mode=c4d.MODELINGCOMMANDMODE_ALL,
bc=bc,
doc=doc,
flags=c4d.MODELINGCOMMANDFLAGS_CREATEUNDO)
if not res:
raise RuntimeError(f"Modelling command failed for {op}.")
# Inform Cinema 4D that the document has been modified.
c4d.EventAdd()
if __name__ == '__main__':
# #doc and #op are predefined module attributes as defined at the top of the file.
main(doc, op)