1111 * c4d.utils.SendModelingCommand()
1212
1313Overview:
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:
2020
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.
2225 * 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
2427 to traverse.
2528 * Some tools require setups which make a dummy document desirable, e.g., the 'Join' tool.
2629
2730 But using a dummy document has also drawbacks:
2831
2932 * 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 .
3134 * 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
3336 example all BaseLink parameters in that document which link to that node must then be found
3437 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
3639 to copy over a single object, and instead non-obvious dependencies which influence the
3740 outcome of the tool are required too. The 'Current State to Object' tool is such example,
3841 as the state of an object can depend on many things as for example fields, effectors, and
3942 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.
4145
4246 Showcased in this example is primarily the more complicated case of executing the command in a
4347 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]) -
7579 raise MemoryError ("Could not create new document." )
7680 temp .InsertObject (clone )
7781
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
7983 # therefore container for the settings of that tool, in this case for the Extrude tool.
8084 bc = c4d .BaseContainer ()
8185 bc [c4d .MDATA_EXTRUDE_PRESERVEGROUPS ] = True # Preserve element groups in extrusions.
8286 bc [c4d .MDATA_EXTRUDE_OFFSET ] = 50.0 # The extrusion depths.
8387 # There are many more options for that tool as exposed in toolextrude.h
8488
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
8690 # list containing the node #clone.
8791 objects = [clone ]
8892
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
9094 # differently, depending on in which editor mode (point, edge, polygon, object) the document
9195 # is in. E.g., being in edge mode will extrude the active edge selection. The example here ties
9296 # 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]) -
100104 else :
101105 raise RuntimeError (f"Document is not in any of the modes supported by the extrude tool." )
102106
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
104108 # be automatically wrapped in an undo. Since this example operates on a temporary 'throw-away'
105109 # document, the flags are being set here to the none-flag.
106110 flags = c4d .MODELINGCOMMANDFLAGS_NONE
@@ -111,7 +115,7 @@ def main(doc: c4d.documents.BaseDocument, op: typing.Optional[c4d.BaseObject]) -
111115 res = c4d .utils .SendModelingCommand (command = c4d .ID_MODELING_EXTRUDE_TOOL , list = objects ,
112116 mode = mode , bc = bc , doc = temp , flags = flags )
113117 if not res :
114- raise RuntimeError (f"Modelling command failed for { op } ." )
118+ raise RuntimeError (f"modeling command failed for { op } ." )
115119
116120 # The same call when not going the temporary document route, and instead carrying out the
117121 # command directly on the node in the active document. The the file documentation for details.
0 commit comments