Skip to content

Commit 513723d

Browse files
committed
Cinema 4D 2023.1.0 SDK
Cinema 4D 2023.1.0 SDK - Updated scripts\02_data_algorithms\maxon_datadictionary_2023_1.py - Updated nodes example to not use anymore AddGraph but instead use CreateDefaultGraph.
1 parent ff384cb commit 513723d

6 files changed

+112
-51
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
"""
2+
Copyright: MAXON Computer GmbH
3+
Author: Maxime Adam, Ferdinand Hoppe
4+
5+
Highlights the key-functionalities of maxon.DataDictionary.
6+
7+
Topics:
8+
- Constructing DataDictionary instances.
9+
- Reading, writing, and deleting key-value pairs.
10+
- Retrieving the number of contained pairs.
11+
- Testing if a specific key is contained.
12+
- Testing equality.
13+
"""
14+
import typing
15+
import maxon
16+
17+
def main():
18+
# A Python dictionary object as a data source.
19+
pyDict: dict = {42: "The answer.", "pi": 3.1415, True: "A string"}
20+
21+
# Create a reference to a `DataDictionaryInterface` object.
22+
dataDict: maxon.DataDictionary = maxon.DataDictionary()
23+
24+
# Items can be set with the `.Set` method or with the bracket syntax. Just as the standard
25+
# Python dictionary, the type `DataDictionary` supports mixed key and value types.
26+
dataDict.Set("myKey", "foo")
27+
for key, value in pyDict.items():
28+
dataDict[key] = value
29+
30+
# However, only the most atomic Python types as string, int, float, and bool are being
31+
# automatically converted to their maxon API equivalent. For storing a list of integer values
32+
# under a key for example, one must convert that list explicitly to a BaseArray.
33+
dataDict["prime_numbers"] = maxon.BaseArray(maxon.Int32, [2, 3, 5, 7, 11, 13])
34+
35+
# The number of key-value pairs in a `DataDictionary` instance can be evaluated with with
36+
# `len()` and `.GetCount()`. Alternatively, `.IsPopulated()` or `IsEmpty() can be called to
37+
# evaluate if an instance is empty or not.
38+
length: int = len(dataDict)
39+
alsoLength: int = dataDict.GetCount()
40+
isPopulated: bool = dataDict.IsPopulated()
41+
isEmpty: bool = dataDict.IsEmpty()
42+
print (f"\ndataDict: {length = }, {alsoLength = }, {isPopulated = }, {isEmpty = }")
43+
44+
# Other than the standard Python dictionary, a `DataDictionary` instance will yield directly
45+
# key-value pairs when iterated. Values can also be accessed with the bracket syntax and the
46+
# method `.Get` which works similar to the method of the same name of a Python dict.
47+
print ("\nState of dataDict:")
48+
for key, value in dataDict:
49+
print (f"\t{key = }, {value = }")
50+
51+
pi: float = dataDict["pi"]
52+
# Will return the default value None, as the key "bar" does not exist.
53+
bar: typing.Optional[str] = dataDict.Get("bar", None)
54+
55+
# The occurrence of a key can be tested with the keyword `in` or the method `.Contains()`.
56+
hasKeyPi: bool = "pi" in dataDict
57+
hasKeyBar: bool = dataDict.Contains("bar")
58+
print (f"\ndataDict: {hasKeyPi = }, {hasKeyBar = }")
59+
60+
# Key-value pairs can be removed with the `del` keyword or the method `.Erase()`.
61+
del dataDict["pi"]
62+
dataDict.Erase(42)
63+
64+
print ("\nNew state of dataDict:")
65+
for key, value in dataDict:
66+
print (f"\t{key = }, {value = }")
67+
68+
# DataDictionary instances can also be compared for equaltiy but the comparison is carried out
69+
# as an identity comparison.
70+
71+
# Two data dictionaries which are are being filled with the same content.
72+
aData: maxon.DataDictionary = maxon.DataDictionary()
73+
bData: maxon.DataDictionary = maxon.DataDictionary()
74+
75+
aData[1000] = "Hello World!"
76+
aData["value"] = 42
77+
bData[1000] = "Hello World!"
78+
bData["value"] = 42
79+
80+
# Will evaluate as `True` because `xData` points to the same object as `aData`.
81+
xData: maxon.DataDictionary = aData
82+
print (f"\n{aData == xData = }")
83+
84+
# Will evaluate as `False` because `aData` points to another object than `bData`. Not the
85+
# content is being compared, but the identity of the two objects.
86+
print (f"{aData == bData = }")
87+
88+
if __name__ == "__main__":
89+
main()

scripts/02_data_algorithms/maxon_datadictionary_r20.py

-31
This file was deleted.

scripts/05_modules/node/create_nodematerial_r26.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
NodeMaterials inherit from BaseMaterial. To be able to use the functions
1010
that are in the NodeMaterial class, the BaseMaterial must be cast to a
1111
NodeMaterial. This is done with the function GetNodeMaterialReference. To
12-
add a graph to an existing node space, one must use the function AddGraph.
12+
create a graph to an existing node space, one must use the function CreateDefaultGraph.
1313
If one wants to have access to an already added node graph, one must
1414
retrieve the nimbus reference which does store the graph. Once one has
1515
retrieved the graph, one can access the root that contains all the nodes.
1616
1717
Class/method highlighted:
1818
- GetNodeMaterialReference
19-
- AddGraph
19+
- CreateDefaultGraph
2020
- GetActiveNodeSpaceId
2121
- GetChildren
2222
- GetNimbusRef
@@ -46,11 +46,11 @@ def CreateMaterialForNodeSpace(nodespaceId):
4646
raise ValueError("Cannot retrieve nodeMaterial reference.")
4747

4848
# Add a graph for the space Id
49-
addedGraph = nodeMaterial.AddGraph(nodespaceId)
50-
if addedGraph is None:
51-
raise ValueError("Cannot add a GraphNode for this NodeSpace.")
49+
createdGraph = nodeMaterial.CreateDefaultGraph(nodespaceId)
50+
if createdGraph is None:
51+
raise ValueError("Cannot create a GraphNode for this NodeSpace.")
5252

53-
# Retrieve the Nimbus reference for a specific NodeSpace. This Nimbus reference allow you to retreive the end node.
53+
# Retrieve the Nimbus reference for a specific NodeSpace. This Nimbus reference allow you to retrieve the end node.
5454
nimbusRef = mat.GetNimbusRef(nodespaceId)
5555
if nimbusRef is None:
5656
raise ValueError(
@@ -101,13 +101,13 @@ def main():
101101
# Do the same with the Redshift node space. The Redshift plugin is not
102102
# installed by default, so we call the function in an exception handling
103103
# context.
104-
redShiftNodeSpPaceId = maxon.Id("com.redshift3d.redshift4c4d.class.nodespace")
105-
if c4d.GetActiveNodeSpaceId() != redShiftNodeSpPaceId:
104+
redshiftNodeSpaceId = maxon.Id("com.redshift3d.redshift4c4d.class.nodespace")
105+
if c4d.GetActiveNodeSpaceId() != redshiftNodeSpaceId:
106106
try:
107-
root = CreateMaterialForNodeSpace(redShiftNodeSpPaceId)
107+
root = CreateMaterialForNodeSpace(redshiftNodeSpaceId)
108108
PrintChildren(root)
109109
except:
110-
print(f"The node space with id {redShiftNodeSpPaceId} does not exist")
110+
print(f"The node space with id {redshiftNodeSpaceId} does not exist")
111111

112112
# Pushes an update event to Cinema 4D
113113
c4d.EventAdd()

scripts/05_modules/node/modify_port_value_r26.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,20 @@ def main():
2626
if nodeMaterial is None:
2727
raise ValueError("Cannot retrieve nodeMaterial reference")
2828

29-
# Create the node space ID for the standard's node space
30-
nodespaceId = maxon.Id("net.maxon.nodespace.standard")
31-
32-
# Add a graph for the standard node space
33-
addedGraph = nodeMaterial.AddGraph(nodespaceId)
29+
# Define the ID of standard material node space and print a warning when the active node space
30+
# is not the the standard material node space.
31+
nodeSpaceId = maxon.Id("net.maxon.nodespace.standard")
32+
if nodeSpaceId != c4d.GetActiveNodeSpaceId():
33+
print (f"Warning: Active node space is not: {nodeSpaceId}")
34+
35+
# Add a graph for the standard node space.
36+
addedGraph = nodeMaterial.CreateDefaultGraph(nodeSpaceId)
3437
if addedGraph is None:
3538
raise ValueError("Cannot add a graph node for this node space")
3639

3740
# Retrieve the Nimbus reference for a specific node space from which we
3841
# will retrieve the graph. One could also use 'addedGraph' defined above.
39-
nimbusRef = mat.GetNimbusRef(nodespaceId)
42+
nimbusRef = mat.GetNimbusRef(nodeSpaceId)
4043
if nimbusRef is None:
4144
raise ValueError("Cannot retrieve the nimbus ref for that node space")
4245

scripts/05_modules/node/nodegraph_selection_r26.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Class/method highlighted:
1010
- BeginTransaction
1111
- SelectPort
12-
- SelectWire
12+
- SelectConnection
1313
"""
1414
import c4d
1515
import maxon
@@ -32,7 +32,7 @@ def main():
3232
nodespaceId = c4d.GetActiveNodeSpaceId()
3333

3434
# Add a graph for the space Id
35-
addedGraph = nodeMaterial.AddGraph(nodespaceId)
35+
addedGraph = nodeMaterial.CreateDefaultGraph(nodespaceId)
3636
if addedGraph is None:
3737
raise ValueError("Cannot add a graphnode for this nodespace")
3838

@@ -105,7 +105,7 @@ def PrintConnection(port):
105105
res = port.GetConnections(maxon.PORT_DIR.OUTPUT, connections)
106106
print(port, res, connections)
107107
for connection in connections:
108-
graph.SelectWire(port, connection[0])
108+
maxon.GraphModelHelper.SelectConnection(port, connection[0])
109109
return True
110110

111111
# Select the wire between the material node (end node) and the BSDF node

scripts/05_modules/node/solo_node_r26.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def main():
3030
nodespaceId = c4d.GetActiveNodeSpaceId()
3131

3232
# Add a graph for the space Id
33-
addedGraph = nodeMaterial.AddGraph(nodespaceId)
33+
addedGraph = nodeMaterial.CreateDefaultGraph(nodespaceId)
3434
if addedGraph is None:
3535
raise ValueError("Cannot add a graphnode for this nodespace")
3636

0 commit comments

Comments
 (0)