11
11
* c4d.utils.SendModelingCommand()
12
12
13
13
Overview:
14
- There are in principle two ways to execute modelling commands: In the original document a node
15
- is contained or in a dummy document. This latter case is carried out by creating a dummy
16
- document just for the command, cloning the relevant nodes into that document, and then executing
17
- the command there. In most cases, executing a modelling command in the original document which
18
- could be a loaded document, and therefore subject to threading restrictions, will cause no
19
- issues, but there are some notable exceptions:
14
+ There are in principle two ways to execute modeling commands: In the original document a node
15
+ is contained in or in a dummy document. The latter case is carried out by creating a dummy
16
+ document just for the command, cloning the relevant node(s) into that document, and then
17
+ executing the command there. In most cases, executing a modeling command in the original
18
+ document - which could be a loaded document and therefore subject to threading restrictions -
19
+ will cause no issues, but there are some notable exceptions:
20
20
21
- * SMC calls which are not done from a non-main thread for a node in a loaded document.
21
+ * SMC calls which are not done from a non-main thread context for a node in a loaded document.
22
+ This could for example be an SMC call in an object plugins GetVirtualObjects method that is
23
+ meant to modify an input object of the plugin. Think of an extrude object plugin that has
24
+ for example the option to bevel its input spline.
22
25
* Tools or tasks for which the complexity of a document directly impacts runtime of the tool
23
- but not the result of the tool; imagine huge amounts of irrelevant data the tool might has
26
+ but not the result of the tool; imagine a huge amount of irrelevant data the tool might has
24
27
to traverse.
25
28
* Some tools require setups which make a dummy document desirable, e.g., the 'Join' tool.
26
29
27
30
But using a dummy document has also drawbacks:
28
31
29
32
* It is computationally much more demanding since all relevant data has first to be copied
30
- over and then back again.
33
+ over to the dummy document and often then also back again to an 'original' document .
31
34
* Inserting the SMC result back into its original document can be labour-intensive when the
32
- result is meant to replace the original object and cannot be inserted as new object. For
35
+ result is meant to replace the original object and cannot be inserted as a new object. For
33
36
example all BaseLink parameters in that document which link to that node must then be found
34
37
and updated too.
35
- * Determining what is relevant for a tool can be hard. In some cases it might be not enough
38
+ * Determining what is relevant for a tool can be hard. In some cases it might not be enough
36
39
to copy over a single object, and instead non-obvious dependencies which influence the
37
40
outcome of the tool are required too. The 'Current State to Object' tool is such example,
38
41
as the state of an object can depend on many things as for example fields, effectors, and
39
42
tags. In these cases it is best to clone the whole document; documents are nodes and can
40
- therefore be cloned themselves. But it will further increase the footprint of the command.
43
+ therefore be cloned themselves. But it will further increase the time and memory complexity
44
+ problem of the approach.
41
45
42
46
Showcased in this example is primarily the more complicated case of executing the command in a
43
47
temporary document. But in general it is more desirable to execute SMC in the document the node
@@ -75,18 +79,18 @@ def main(doc: c4d.documents.BaseDocument, op: typing.Optional[c4d.BaseObject]) -
75
79
raise MemoryError ("Could not create new document." )
76
80
temp .InsertObject (clone )
77
81
78
- # A modelling command invokes one of the modelling tools of Cinema 4D. The function takes
82
+ # A modeling command invokes one of the modeling tools of Cinema 4D. The function takes
79
83
# therefore container for the settings of that tool, in this case for the Extrude tool.
80
84
bc = c4d .BaseContainer ()
81
85
bc [c4d .MDATA_EXTRUDE_PRESERVEGROUPS ] = True # Preserve element groups in extrusions.
82
86
bc [c4d .MDATA_EXTRUDE_OFFSET ] = 50.0 # The extrusion depths.
83
87
# There are many more options for that tool as exposed in toolextrude.h
84
88
85
- # A modelling command takes a list of objects as one of its inputs. In this case it is just a
89
+ # A modeling command takes a list of objects as one of its inputs. In this case it is just a
86
90
# list containing the node #clone.
87
91
objects = [clone ]
88
92
89
- # A modelling command has also a mode of operation. The extrude tool for example behaves
93
+ # A modeling command has also a mode of operation. The extrude tool for example behaves
90
94
# differently, depending on in which editor mode (point, edge, polygon, object) the document
91
95
# is in. E.g., being in edge mode will extrude the active edge selection. The example here ties
92
96
# the SMC mode to the mode of active document. There are also more SMC modes than shown here.
@@ -100,7 +104,7 @@ def main(doc: c4d.documents.BaseDocument, op: typing.Optional[c4d.BaseObject]) -
100
104
else :
101
105
raise RuntimeError (f"Document is not in any of the modes supported by the extrude tool." )
102
106
103
- # Finally, a modelling command also takes a set of flags. With them the command can for example
107
+ # Finally, a modeling command also takes a set of flags. With them the command can for example
104
108
# be automatically wrapped in an undo. Since this example operates on a temporary 'throw-away'
105
109
# document, the flags are being set here to the none-flag.
106
110
flags = c4d .MODELINGCOMMANDFLAGS_NONE
@@ -111,7 +115,7 @@ def main(doc: c4d.documents.BaseDocument, op: typing.Optional[c4d.BaseObject]) -
111
115
res = c4d .utils .SendModelingCommand (command = c4d .ID_MODELING_EXTRUDE_TOOL , list = objects ,
112
116
mode = mode , bc = bc , doc = temp , flags = flags )
113
117
if not res :
114
- raise RuntimeError (f"Modelling command failed for { op } ." )
118
+ raise RuntimeError (f"modeling command failed for { op } ." )
115
119
116
120
# The same call when not going the temporary document route, and instead carrying out the
117
121
# command directly on the node in the active document. The the file documentation for details.
0 commit comments