Repository navigation
Expand file tree
/
Copy pathvertex_color_points.py
More file actions
57 lines (44 loc) · 1.58 KB
/
Copy pathvertex_color_points.py
File metadata and controls
57 lines (44 loc) · 1.58 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
53
54
55
56
57
"""Gets and Sets Vertex Colors in Point mode: Changes all black Vertex Colors to red.
Topics:
* VertexColorTag.GetDataAddressR()
* VertexColorTag.GetPoint()
* VertexColorTag.GetDataAddressW()
* VertexColorTag.SetPoint()
Note:
- Only RGB vertex colors are supported by this script
"""
__author__ = "Yannick Puech"
__copyright__ = "Copyright (C) 2026 MAXON Computer GmbH"
__license__ = "Apache-2.0 License"
__version__ = "R18"
import c4d
def main():
# Checks if selected object is valid
if op is None:
raise ValueError("op is none, please select one object.")
# Retrieves the Vertex Color Tag
tag = op.GetTag(c4d.Tvertexcolor)
if tag is None:
raise TypeError("Failed to retrieve the vertex tag color.")
# Checks in Point mode
if not tag.IsPerPointColor():
# If not changes to Point mode
tag.SetPerPointMode(True)
# Obtains vertex colors data R/W addresses
addrR = tag.GetDataAddressR()
addrW = tag.GetDataAddressW()
# Initializes black and red colors
black = c4d.Vector4d(0, 0, 0, 1)
red = c4d.Vector4d(1, 0, 0, 1)
# By default the Vertex Color Tag is in Point mode
# So GetDataCount() returns the number of points
count = tag.GetDataCount()
for idx in range(count):
# If point color is black then changes it to red
point = c4d.VertexColorTag.GetPoint(addrR, None, None, idx)
if point == black:
c4d.VertexColorTag.SetPoint(addrW, None, None, idx, red)
# Pushes an update event to Cinema 4D
c4d.EventAdd()
if __name__ == '__main__':
main()