forked from Maxon-Computer/Cinema-4D-Python-API-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgridaccessor_read_r20.py
More file actions
52 lines (38 loc) · 1.4 KB
/
gridaccessor_read_r20.py
File metadata and controls
52 lines (38 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
Copyright: MAXON Computer GmbH
Author: Maxime Adam
Description:
- Reads the Float value of the first channel available from a Volume stored in a Volume Builder.
Class/method highlighted:
- maxon.GridAccessorInterface
- GridAccessorRef.GetValue()
"""
import c4d
import maxon
def main():
# Checks if there is an active object
if op is None:
raise RuntimeError("Failed to retrieve op.")
# Checks if the active object is a Volume builder
if not op.IsInstanceOf(c4d.Ovolumebuilder):
raise TypeError("op is not a c4d.Ovolumebuilder.")
# Gets the C4D Volume Object from the cache
cache = op.GetCache()
if cache is None:
raise RuntimeError("Failed to retrieve the cache of the volume builder.")
# Checks if the cache is a C4D Volume Object
if not cache.IsInstanceOf(c4d.Ovolume):
raise TypeError("cache is not a c4d.Ovolume.")
# Gets the Volume object linked to this Ovolume object.
volume = cache.GetVolume()
if volume is None:
raise RuntimeError("Failed to retrieve the maxon.VolumeRef.")
# Initializes a Float Grid with our existing volume data
access = maxon.GridAccessorInterface.Create(maxon.Float32)
access.Init(volume)
# Reads the Float value stored at the c4d.Vector(0, 0, 0) position
vec = c4d.Vector(0, 0, 0)
value = access.GetValue(vec)
print(value)
if __name__ == '__main__':
main()