5
5
Description:
6
6
- Create a new temporary script.
7
7
- Load an existing Python file into the Script Manager.
8
- - Retrieve the first script not active in the script manager and make it active.
8
+ - Retrieve the first script not active in the Script Manager and make it active.
9
9
10
10
Class/method highlighted:
11
11
- c4d.CreateNewPythonScript()
@@ -26,45 +26,49 @@ def CreateNewPythonScript():
26
26
# The new script will be set as active automatically.
27
27
newScript = c4d .CreateNewPythonScript ("" , r"print('Sometimes science is more art than science.')" )
28
28
29
- # ScriptObject being BaseList2D the usual C4DAtom bracket operator can be used to access various properties from it.
29
+ # Due to the type ScriptObject being derived from BaseList2D, the bracket operator syntax can be used to access
30
+ # the parameters of an instance.
30
31
scriptName = newScript [c4d .PYTHONSCRIPT_SCRIPTNAME ]
31
32
32
- # An empty PYTHONSCRIPT_SCRIPTPATH indicate that this script is not saved and will be deleted once Cinema 4D close.
33
+ # An empty PYTHONSCRIPT_SCRIPTPATH indicates that this script has not been
34
+ # saved and will be deleted once Cinema 4D closes.
33
35
scriptPath = newScript [c4d .PYTHONSCRIPT_SCRIPTPATH ]
34
36
35
- # PYTHONSCRIPT_TEXT returns the python script visible in hte Script Manager.
37
+ # PYTHONSCRIPT_TEXT returns the Python script visible in the Script Manager.
36
38
scriptContent = newScript [c4d .PYTHONSCRIPT_TEXT ]
37
39
38
- print (f"Added '{ scriptName } ', it's content in the Script Manager is:\n { scriptContent } " )
40
+ print (f"Added '{ scriptName } ', its content in the Script Manager is:\n { scriptContent } " )
39
41
40
42
41
43
def LoadExistingPythonScript ():
42
44
"""Load an existing Python file into the Script Manager.
43
45
"""
44
46
scriptPathToLoad = os .path .join (os .path .dirname (__file__ ), "reg_plugin_info_r23.py" )
45
47
46
- # Load the script in the script manager and set it as active automatically
48
+ # Load the script into the Script Manger and set it automatically as the active script.
47
49
loadedScript = c4d .LoadPythonScript (scriptPathToLoad )
48
50
49
- # ScriptObject being BaseList2D the usual C4DAtom bracket operator can be used to access various properties from it.
51
+ # Due to the type ScriptObject being derived from BaseList2D, the bracket operator syntax can be used to access
52
+ # the parameters of an instance.
50
53
scriptName = loadedScript [c4d .PYTHONSCRIPT_SCRIPTNAME ]
51
54
52
- # An empty PYTHONSCRIPT_SCRIPTPATHindicate that this script is not saved and will be deleted once Cinema 4D close.
55
+ # An empty PYTHONSCRIPT_SCRIPTPATH indicates that this script has not been
56
+ # saved and will be deleted once Cinema 4D closes.
53
57
scriptPath = loadedScript [c4d .PYTHONSCRIPT_SCRIPTPATH ]
54
58
55
- # PYTHONSCRIPT_TEXT returns the python script visible in hte Script Manager.
59
+ # PYTHONSCRIPT_TEXT returns the Python script visible in the Script Manager.
56
60
scriptContent = loadedScript [c4d .PYTHONSCRIPT_TEXT ]
57
61
58
62
print (f"Load '{ scriptName } ', from '{ scriptPath } ' it's content in the Script Manager is:\n { scriptContent } " )
59
63
60
64
61
65
def SetActiveScript ():
62
- """Retrieve the first script not active in the script manager and make it active.
66
+ """Retrieve the first non- active script in the Script Manager and set it as the active script .
63
67
64
- Scripts available in the script manager are BaseList2D stored into a specific GeListHead.
68
+ Scripts visible in the Script Manager are represented by BaseList2D instances stored under a GeListHead.
65
69
"""
66
70
def HierarchyIterator (obj ):
67
- """A Python Generator to iterate over the Hierarchy .
71
+ """Yields nodes from a GeListNode tree .
68
72
Args:
69
73
obj: The starting object of the python generator (will be the first result)
70
74
Returns:
@@ -79,26 +83,28 @@ def HierarchyIterator(obj):
79
83
# Retrieve the script list head.
80
84
scriptHead = c4d .GetScriptHead ()
81
85
82
- # Retrieve the first script not active in the script manager and make it active.
83
- # A script is active when it has its code displayed in the script manager .
86
+ # Retrieve the first non- active script in the Script Manager and set it as the active script .
87
+ # A script is active when it has its code displayed in the Script Manager .
84
88
for scriptOp in HierarchyIterator (scriptHead .GetFirst ()):
85
- # Go to the next script object if the script is already active in the script manager .
89
+ # Go to the next script object if the script is already active in the Script Manager .
86
90
if scriptOp .GetBit (c4d .BIT_ACTIVE ):
87
91
continue
88
92
89
93
# Retrieve the unique plugin ID generated by Cinema 4D for this script.
90
94
scriptId = c4d .GetDynamicScriptID (scriptOp )
91
95
92
- # Define this script as the new script to be active in the script manager.
96
+ # Set the script with the ID #scriptID as the new active script
93
97
c4d .SetActiveScriptObject (scriptId )
94
98
95
- # ScriptObject being BaseList2D the usual C4DAtom bracket operator can be used to access various properties from it.
99
+ # Due to the type ScriptObject being derived from BaseList2D, the bracket operator syntax can be used to access
100
+ # the parameters of an instance.
96
101
scriptName = scriptOp [c4d .PYTHONSCRIPT_SCRIPTNAME ]
97
102
98
- # An empty PYTHONSCRIPT_SCRIPTPATH indicate that this script is not saved and will be deleted once Cinema 4D close.
103
+ # An empty PYTHONSCRIPT_SCRIPTPATH indicates that this script has not been
104
+ # saved and will be deleted once Cinema 4D closes.
99
105
scriptPath = scriptOp [c4d .PYTHONSCRIPT_SCRIPTPATH ]
100
106
101
- # PYTHONSCRIPT_TEXT returns the python script visible in hte Script Manager.
107
+ # PYTHONSCRIPT_TEXT returns the Python script visible in the Script Manager.
102
108
scriptContent = scriptOp [c4d .PYTHONSCRIPT_TEXT ]
103
109
104
110
print (f"Set as active '{ scriptName } ', saved in `{ scriptPath } ` with the next content in"
0 commit comments