Skip to content

Commit aea195b

Browse files
committed
R25 Release
Add nodes example within scripts\05_modules\node Update symbols to remove deprecated one
1 parent a73d4ba commit aea195b

22 files changed

+696
-24
lines changed

plugins/py-liquid_painter_r12/py-liquid_painter_r12.pyp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ class LiquidTool(c4d.plugins.ToolData):
128128
raise MemoryError("Failed to create a Phong Tag.")
129129

130130
# Adds an undo step
131-
doc.AddUndo(c4d.UNDO_NEW, metaball)
131+
doc.AddUndo(c4d.UNDOTYPE_NEWOBJ, metaball)
132132

133133
# Inserts the object in the active document and set it as active one.
134134
doc.InsertObject(metaball)
135135
doc.SetActiveObject(metaball)
136136

137137
# Updates the Viewport (so the metaball is drawn)
138-
c4d.DrawViews(c4d.DA_ONLY_ACTIVE_VIEW | c4d.DA_NO_THREAD | c4d.DA_NO_ANIMATION)
138+
c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_NO_ANIMATION)
139139

140140
# Retrieves the X/Y screen position of the mouse.
141141
mx = msg[c4d.BFM_INPUT_X]
@@ -171,7 +171,7 @@ class LiquidTool(c4d.plugins.ToolData):
171171
sphere.InsertUnder(metaball)
172172

173173
# Updates the Viewport (so the metaball with the newly created sphere is drawn)
174-
c4d.DrawViews(c4d.DA_ONLY_ACTIVE_VIEW | c4d.DA_NO_THREAD | c4d.DA_NO_ANIMATION)
174+
c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_NO_ANIMATION)
175175

176176
# Updates drag information
177177
result, dx, dy, channel = win.MouseDrag()

plugins/py-rounded_tube_r13/py-rounded_tube_r13.pyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class RoundedTube(c4d.plugins.ObjectData, RoundedTubeHelper):
227227
"""
228228
# Disable the following lines because cache flag was set
229229
# So the cache build is done before this method is called
230-
# dirty = op.CheckCache(hierarchyhelp) or op.IsDirty(c4d.DIRTY_DATA)
230+
# dirty = op.CheckCache(hierarchyhelp) or op.IsDirty(c4d.DIRTYFLAGS_DATA)
231231
# if dirty is False: return op.GetCache(hierarchyhelp)
232232

233233
# Retrieves parameters value from the generator object

plugins/py-spherify_modifier_r13/py-spherify_modifier_r13.pyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ class SpherifyModifier(c4d.plugins.ObjectData):
341341

342342
if self.falloff is not None and not skipFalloff:
343343
if not self.falloff.InitFalloff(op.GetDataInstance(), bh.GetDocument(), op):
344-
return c4d.DRAWRESULT_ERROR
344+
return c4d.DRAWRESULT_FAILURE
345345

346346
# Retrieves the object color
347347
bd.SetPen(bd.GetObjectColor(bh, op))

plugins/py-texture_baker_r18/py-texture_baker_r18.pyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class TextureBakerThread(c4d.threading.C4DThread):
8282
return False
8383

8484
# Starts bake thread
85-
self.Start(c4d.THREADMODE_ASYNC, c4d.THREADPRIORITY_BELOW)
85+
self.Start(c4d.THREADMODE_ASYNC, c4d.THREADPRIORITEXY_BELOW)
8686

8787
return True
8888

plugins/py-tooldata_ui_r15/py-tooldata_ui_r15.pyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class ToolDataWithUiExample(c4d.plugins.ToolData):
250250
doc.StartUndo()
251251

252252
# Adds an undo step
253-
doc.AddUndo(c4d.UNDO_NEW, cloned)
253+
doc.AddUndo(c4d.UNDOTYPE_NEWOBJ, cloned)
254254

255255
# Inserts the cloned object in the active document.
256256
doc.InsertObject(cloned)

scripts/03_application_development/gui/description/description_check_descid_r18.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def main():
2323
raise RuntimeError("Failed to retrieve the description.")
2424

2525
# Builds the object's X position parameter DescID
26-
descId = c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, 0, 0), c4d.DescLevel(c4d.VECTOR_X, 0, 0))
26+
descId = c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_REL_POSITION, 0, 0), c4d.DescLevel(c4d.VECTOR_X, 0, 0))
2727

2828
# Prints previously built DescID
2929
print(descId)

scripts/04_3d_concepts/modeling/read_write_normal_tag_r13.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
QUARTER_PI = math.pi * .25
2525

26+
2627
def ReadNormalTag(tag):
2728
"""Reads a c4d.NormalTag to a list of c4d.Vector.
2829
@@ -59,6 +60,7 @@ def ReadNormalTag(tag):
5960
data[i-1] * factor)
6061
for i in range(3, len(data) + 3, 3)]
6162

63+
6264
def WriteNormalTag(tag, normals, doNormalize=True):
6365
"""Writes a list of c4d.Vector to a c4d.NormalTag.
6466
@@ -106,6 +108,7 @@ def WriteNormalTag(tag, normals, doNormalize=True):
106108
data = data.tobytes()
107109
buffer[:len(data)] = data
108110

111+
109112
def main():
110113
"""Entry point."""
111114
# Raise an error when the primary selection is not a PolygonObject.
@@ -128,7 +131,7 @@ def main():
128131

129132
# Get the normals from the newly allocated NormalTag.
130133
normals = ReadNormalTag(normalTag)
131-
print (f"Normals of the newly allocated tag: {normals}")
134+
print(f"Normals of the newly allocated tag: {normals}")
132135

133136
# This should not happen.
134137
if len(phongNormals) != len(normals):
@@ -139,20 +142,21 @@ def main():
139142

140143
# Inspect our write operation in the console.
141144
normals = ReadNormalTag(normalTag)
142-
print (f"Normals after writing the phong normals: {normals}")
145+
print(f"Normals after writing the phong normals: {normals}")
143146

144147
# Start an undo block.
145148
doc.StartUndo()
146149
# Insert our NormalTag.
147150
op.InsertTag(normalTag)
148151
# For insertions the undo has to be added after the operation.
149-
doc.AddUndo(c4d.UNDOTYPE_NEW, normalTag)
152+
doc.AddUndo(c4d.UNDOTYPE_NEWOBJ, normalTag)
150153
# End the undo block.
151154
doc.EndUndo()
152155

153156
# Notify Cinema and the object that we did made changes.
154157
op.Message(c4d.MSG_UPDATE)
155158
c4d.EventAdd()
156159

160+
157161
if __name__ == "__main__":
158162
main()

scripts/04_3d_concepts/scene_elements/animation/ctrack_copy_r14.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def main():
3838

3939
# Defines a list that will contains the ID of parameters we want to copy.
4040
# Such ID can be found by drag-and-drop a parameter into the python console.
41-
trackListToCopy = [c4d.ID_BASEOBJECT_POSITION, c4d.ID_BASEOBJECT_ROTATION, c4d.ID_BASEOBJECT_SCALE]
41+
trackListToCopy = [c4d.ID_BASEOBJECT_REL_POSITION, c4d.ID_BASEOBJECT_REL_ROTATION, c4d.ID_BASEOBJECT_REL_SCALE]
4242

4343
# Start the Undo process.
4444
doc.StartUndo()
@@ -56,15 +56,15 @@ def main():
5656
foundTrack = fixedBox.FindCTrack(did)
5757
if foundTrack:
5858
# Removes the track if found.
59-
doc.AddUndo(c4d.UNDOTYPE_DELETE, foundTrack)
59+
doc.AddUndo(c4d.UNDOTYPE_DELETEOBJ, foundTrack)
6060
foundTrack.Remove()
6161

6262
# Copies the initial CTrack in memory. All CCurve and CKey are kept in this CTrack.
6363
clone = track.GetClone()
6464

6565
# Inserts the copied CTrack to the static object.
6666
fixedBox.InsertTrackSorted(clone)
67-
doc.AddUndo(c4d.UNDOTYPE_NEW, clone)
67+
doc.AddUndo(c4d.UNDOTYPE_NEWOBJ, clone)
6868

6969
# Ends the Undo Process.
7070
doc.EndUndo()

scripts/04_3d_concepts/scene_elements/animation/ctrack_create_keys_r13.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def main():
6262
obj = c4d.BaseObject(c4d.Ocube)
6363

6464
# Creates the track in memory. Defined by it's DescID
65-
trackY = c4d.CTrack(obj, c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0),
65+
trackY = c4d.CTrack(obj, c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_REL_POSITION, c4d.DTYPE_VECTOR, 0),
6666
c4d.DescLevel(c4d.VECTOR_Y, c4d.DTYPE_REAL, 0)))
6767

6868
# Gets curves for the track

scripts/04_3d_concepts/scene_elements/materials_shading/material_set_to_selected_poly_r13.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def AssignMatToObject(obj, matList, onlyToSelection=False):
3131
for mat in matList:
3232
# Creates the texture Tag
3333
textureTag = obj.MakeTag(c4d.Ttexture)
34-
doc.AddUndo(c4d.UNDOTYPE_NEW, textureTag)
34+
doc.AddUndo(c4d.UNDOTYPE_NEWOBJ, textureTag)
3535

3636
# If the texture tag is not available at this point, something went wrong
3737
if textureTag is None:
@@ -63,7 +63,7 @@ def AssignMatToObject(obj, matList, onlyToSelection=False):
6363

6464
# Creates the selection tag
6565
selectionTag = obj.MakeTag(c4d.Tpolygonselection)
66-
doc.AddUndo(c4d.UNDOTYPE_NEW, selectionTag)
66+
doc.AddUndo(c4d.UNDOTYPE_NEWOBJ, selectionTag)
6767

6868
# Checks if there was no error during the creation of the selection tag
6969
if selectionTag is None:

scripts/04_3d_concepts/scene_elements/scene_management/basedocument_read_animated_mesh_r16.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def main():
8888
null.SetName(str(frame))
8989

9090
# Inserts the objects into the documents
91-
doc.AddUndo(c4d.UNDOTYPE_NEW, null)
91+
doc.AddUndo(c4d.UNDOTYPE_NEWOBJ, null)
9292
doc.InsertObject(null)
9393

9494
# Defines the position of the null with the position of the point from the deformed mesh

scripts/04_3d_concepts/scene_elements/scene_management/basedocument_undo_r13.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ def main():
3030

3131
# Inserts a Material into the active document
3232
doc.InsertMaterial(mat)
33-
doc.AddUndo(c4d.UNDOTYPE_NEW, mat)
33+
doc.AddUndo(c4d.UNDOTYPE_NEWOBJ, mat)
3434

3535
# Inserts both objects
3636
doc.InsertObject(null)
37-
doc.AddUndo(c4d.UNDOTYPE_NEW, null)
37+
doc.AddUndo(c4d.UNDOTYPE_NEWOBJ, null)
3838

3939
# Inserts both objects
4040
doc.InsertObject(cube)
41-
doc.AddUndo(c4d.UNDOTYPE_NEW, cube)
41+
doc.AddUndo(c4d.UNDOTYPE_NEWOBJ, cube)
4242

4343
# Inserts the Texture Tag to the cube object
4444
cube.InsertTag(textureTag)
45-
doc.AddUndo(c4d.UNDOTYPE_NEW, textureTag)
45+
doc.AddUndo(c4d.UNDOTYPE_NEWOBJ, textureTag)
4646

4747
# Defines the material used in the Texture Tag to our material
4848
doc.AddUndo(c4d.UNDOTYPE_CHANGE, textureTag)
@@ -60,7 +60,7 @@ def main():
6060
cube.InsertUnderLast(null)
6161

6262
# Delete the Texture Tag
63-
doc.AddUndo(c4d.UNDOTYPE_DELETE, textureTag)
63+
doc.AddUndo(c4d.UNDOTYPE_DELETEOBJ, textureTag)
6464
textureTag.Remove()
6565

6666
# Defines the final state of the scene

scripts/05_modules/mograph/voronoi_fracture_r18.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def main():
2626
doc.InsertObject(cube)
2727

2828
# Makes it editable and finally insert it as child of Voronoi Fracture object
29-
editable = c4d.utils.SendModelingCommand(c4d.MCOMMAND_MAKEEDITABLE, list=[cube], mode=c4d.MODIFY_ALL, doc=doc)
29+
editable = c4d.utils.SendModelingCommand(c4d.MCOMMAND_MAKEEDITABLE, list=[cube], mode=c4d.MODELINGCOMMANDMODE_ALL, doc=doc)
3030
if not editable:
3131
raise RuntimeError("Failed to do the SendModelingCommand operation.")
3232
doc.InsertObject(editable[0], parent=voronoi)
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
"""
2+
Copyright: MAXON Computer GmbH
3+
Author: Manuel Magalhaes
4+
5+
Description:
6+
Creates a NodeMaterial for the current node space and for Redshift node
7+
space.
8+
9+
NodeMaterials inherit from BaseMaterial. To be able to use the functions
10+
that are in the NodeMaterial class, the BaseMaterial must be cast to a
11+
NodeMaterial. This is done with the function GetNodeMaterialReference. To
12+
add a graph to an existing node space, one must use the function AddGraph.
13+
If one wants to have access to an already added node graph, one must
14+
retrieve the nimbus reference which does store the graph. Once one has
15+
retrieved the graph, one can access the root that contains all the nodes.
16+
17+
Class/method highlighted:
18+
- GetNodeMaterialReference
19+
- AddGraph
20+
- GetActiveNodeSpaceId
21+
- GetChildren
22+
- GetNimbusRef
23+
"""
24+
import c4d
25+
import maxon
26+
import maxon.frameworks.nodespace
27+
import maxon.frameworks.nodes
28+
29+
# Define a function that will create the node material for the passed
30+
# nodespace Id and return the root of the created Graph
31+
32+
33+
def CreateMaterialForNodeSpace(nodespaceId):
34+
# Create a baseMaterial first
35+
mat = c4d.BaseMaterial(c4d.Mmaterial)
36+
if mat is None:
37+
raise ValueError("Cannot create a BaseMaterial.")
38+
39+
# Retrieve the reference of the material as a node material.
40+
nodeMaterial = mat.GetNodeMaterialReference()
41+
if nodeMaterial is None:
42+
raise ValueError("Cannot retrieve nodeMaterial reference.")
43+
44+
# Add a graph for the space Id
45+
addedGraph = nodeMaterial.AddGraph(nodespaceId)
46+
if addedGraph is None:
47+
raise ValueError("Cannot add a GraphNode for this NodeSpace.")
48+
49+
# Retrieve the Nimbus reference for a specific NodeSpace
50+
nimbusRef = mat.GetNimbusRef(nodespaceId)
51+
if nimbusRef is None:
52+
raise ValueError(
53+
"Cannot retrieve the nimbus reference for that NodeSpace.")
54+
55+
# Retrieve the graph corresponding to that NodeSpace.
56+
graph = nimbusRef.GetGraph()
57+
if graph is None:
58+
raise ValueError("Cannot retrieve the graph of this nimbus NodeSpace.")
59+
60+
# Retrieve the root of the graph
61+
root = graph.GetRoot()
62+
63+
# Insert the material in the document
64+
doc.InsertMaterial(mat)
65+
return root
66+
67+
68+
# Define a function that will recursively print all the child of the root node.
69+
def PrintChildren(node):
70+
if node is None:
71+
return None
72+
# Print the current Node
73+
print(node)
74+
75+
# Call GetChildren on this node with the delegate function
76+
node.GetChildren(PrintChildren, maxon.frameworks.graph.NODE_KIND.ALL_MASK)
77+
78+
# Important that the delegate return True or False
79+
return True
80+
81+
82+
def main():
83+
84+
# Retrieve the current node space Id
85+
nodespaceId = c4d.GetActiveNodeSpaceId()
86+
87+
# Create the material and retrieve the root of the graph
88+
root = CreateMaterialForNodeSpace(nodespaceId)
89+
90+
# Start the recursive process on the first node
91+
PrintChildren(root)
92+
93+
# Do the same with the Redshift node space. The Redshift plugin is not
94+
# installed by default, so we call the function in an exception handling
95+
# context.
96+
redShiftNodeSpPaceId = maxon.Id(
97+
'com.redshift3d.redshift4c4d.class.nodespace')
98+
try:
99+
root = CreateMaterialForNodeSpace(redShiftNodeSpPaceId)
100+
PrintChildren(root)
101+
except:
102+
print(f"The node space with id {redShiftNodeSpPaceId} does not exist")
103+
104+
# Pushes an update event to Cinema 4D
105+
c4d.EventAdd()
106+
107+
108+
if __name__ == "__main__":
109+
main()

0 commit comments

Comments
 (0)