Repository navigation
Expand file tree
/
Copy pathreduction_edge_level.py
More file actions
76 lines (58 loc) · 2.27 KB
/
Copy pathreduction_edge_level.py
File metadata and controls
76 lines (58 loc) · 2.27 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""Reduces the active PolygonObject to the given edge count.
Topics:
* c4d.utils.PolygonReduction
"""
__author__ = "Yannick Puech"
__copyright__ = "Copyright (C) 2026 MAXON Computer GmbH"
__license__ = "Apache-2.0 License"
__version__ = "R19"
import c4d
def main():
# Checks if selected object is valid
if op is None:
raise ValueError("op is none, please select one object.")
# Check if it's a polygon object
if not op.IsInstanceOf(c4d.Opolygon):
raise TypeError("Selected object is not a polygon Object.")
# Defines settings for PolygonReduction.PreProcess()
settings = c4d.BaseContainer()
settings[c4d.POLYREDUXOBJECT_PRESERVE_3D_BOUNDARY] = True
settings[c4d.POLYREDUXOBJECT_PRESERVE_UV_BOUNDARY] = True
# Defines data for PolygonReduction.PreProcess()
data = dict()
data['_op'] = op
data['_doc'] = doc
data['_settings'] = settings
data['_thread'] = None
# Creates PolygonReduction object
polyReduction = c4d.utils.PolygonReduction()
if polyReduction is None:
raise RuntimeError("Failed to create the PolygonReduction.")
# Pre-process the data
if not polyReduction.PreProcess(data):
raise RuntimeError("Failed to Pre-Process the PolygonReduction with data.")
# Asks for number of edges level
while True:
# Opens a Dialog where user can enter a text
userInput = c4d.gui.InputDialog("Enter number of edges level:")
# Checks if operation was cancelled
if userInput == "":
return
# Tries to convert to integer
try:
edgesLevel = int(userInput)
break
except ValueError:
c4d.gui.MessageDialog("Please enter a number.")
# Sets edges level number
polyReduction.SetRemainingEdgesLevel(min(edgesLevel, polyReduction.GetMaxRemainingEdgesLevel()))
polyReduction.SetRemainingEdgesLevel(min(edgesLevel, polyReduction.GetMaxRemainingEdgesLevel()))
# Retrieves edges level count after reduction
realEdgeResult = polyReduction.GetRemainingEdgesLevel()
print("Edge Result: {0}".format(realEdgeResult))
# Updates the original PolygonObject
op.Message(c4d.MSG_UPDATE)
# Pushes an update event to Cinema 4D
c4d.EventAdd()
if __name__ == '__main__':
main()