-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkBoxList and ProcessBar C4D GUI Example.py
270 lines (214 loc) · 10.4 KB
/
LinkBoxList and ProcessBar C4D GUI Example.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
"""
LinkBoxList & ProcessBar GUI Example
Author: Asthon Rolle AKA AP Asthon
Cinema 4D Python Script For C4D
Compatible:
- Win / Mac
- R16, R17, R18, R19, R20, R21
"""
# // Imports for Cinema 4D //
import c4d
import os
import sys
import webbrowser
import math
import random
import urllib
import glob
import shutil
import time
import datetime
from c4d import plugins, gui, bitmaps, documents, storage, utils
from random import randint
# Colors
BG_DARK = c4d.Vector(0.1015625, 0.09765625, 0.10546875)
DARK_BLUE_TEXT_COL = c4d.Vector(0, 0.78125, 0.99609375)
DARK_RED_TEXT_COL = c4d.Vector(0.99609375, 0, 0)
# ---------------------------------------------------------------------
# Creating GUI Instance Functions UI Elements Operations
# Hepler Methods.
# ---------------------------------------------------------------------
def AddLinkBoxList_GUI(ui_ins, ui_id, w_size, h_size, enable_state_flags):
"""
This GUI name is really call a c4d.gui.InExcludeCustomGui.
/ InExclude custom GUI (CUSTOMGUI_INEXCLUDE_LIST).
"""
#First create a container that will hold the items we will allow to be dropped into the INEXCLUDE_LIST gizmo
acceptedObjs = c4d.BaseContainer()
acceptedObjs.InsData(c4d.Obase, "") # -> # Accept all objects / you change as desired
# Take a look at c4d Objects Types in SDK.
# Create another base container for the INEXCLUDE_LIST gizmo's settings and add the above container to it
bc_IEsettings = c4d.BaseContainer()
bc_IEsettings.SetData(c4d.IN_EXCLUDE_FLAG_SEND_SELCHANGE_MSG, True)
bc_IEsettings.SetData(c4d.IN_EXCLUDE_FLAG_INIT_STATE, 1)
"""
Its buttons with states for each object in the list container gui of the CUSTOMGUI_INEXCLUDE_LIST.
feel free to enable this in the ui by seting the enable_state_flags to True.
"""
if enable_state_flags == True:
bc_IEsettings.SetData(c4d.IN_EXCLUDE_FLAG_NUM_FLAGS, 2)
# button 1
bc_IEsettings.SetData(c4d.IN_EXCLUDE_FLAG_IMAGE_01_ON, 1039241) # -> Id Icon or Plugin Id
bc_IEsettings.SetData(c4d.IN_EXCLUDE_FLAG_IMAGE_01_OFF, 1039241)
# button 2
bc_IEsettings.SetData(c4d.IN_EXCLUDE_FLAG_IMAGE_02_ON, 1039801)
bc_IEsettings.SetData(c4d.IN_EXCLUDE_FLAG_IMAGE_02_OFF, 1036394)
bc_IEsettings.SetData(c4d.DESC_ACCEPT, acceptedObjs)
ui_ins.AddCustomGui(ui_id, c4d.CUSTOMGUI_INEXCLUDE_LIST, "", c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT, w_size, h_size, bc_IEsettings)
return True
def Add_ProgressBar_GUI(ui_ins, progressbar_ui_id, strText_id, w_size, h_size):
"""
Create ProgressBar GUI
"""
ui_ins.GroupBegin(0, c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT, 0, 1)
ui_ins.GroupBorderNoTitle(c4d.BORDER_THIN_IN)
# ProgressBar
ui_ins.AddCustomGui(progressbar_ui_id, c4d.CUSTOMGUI_PROGRESSBAR, "", c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT, w_size, h_size)
ui_ins.AddSeparatorV(0, c4d.BFV_SCALEFIT)
# Static UI Text
ui_ins.AddStaticText(strText_id, c4d.BFH_MASK, 50, h_size, "", c4d.BORDER_WITH_TITLE_BOLD)
ui_ins.GroupEnd() # Group End
return True
def Run_PrcoessBar(ui_ins, progressbar_ui_id, currentNum, amountOfObjects, col):
# Prcoess Bar
percent = float(currentNum)/amountOfObjects*100
# Set Data to PROGRESSBAR
progressMsg = c4d.BaseContainer(c4d.BFM_SETSTATUSBAR)
progressMsg[c4d.BFM_STATUSBAR_PROGRESSON] = True
progressMsg[c4d.BFM_STATUSBAR_PROGRESS] = percent/100.0
# this if you want a custom color
if col:
ui_ins.SetDefaultColor(progressbar_ui_id, c4d.COLOR_PROGRESSBAR, col)
ui_ins.SendMessage(progressbar_ui_id, progressMsg)
# Return Percent String Data
return str(int(percent))+"%"
def Stop_ProgressBar(ui_ins, progressbar_ui_id):
progressMsg = c4d.BaseContainer(c4d.BFM_SETSTATUSBAR)
progressMsg.SetBool(c4d.BFM_STATUSBAR_PROGRESSON, False)
ui_ins.SendMessage(progressbar_ui_id, progressMsg)
return True
# ------------------------------------------------------------------------------------ #
# ----------------------------------------
# // UI Main Window //
# ----------------------------------------
class Tool_WindowDialog(c4d.gui.GeDialog):
# GUI Ids
IDS_VER = 999
IDS_OverallGrp = 1000
IDS_StaticText = 1001
IDS_BTN_01 = 1002
IDS_LINKBOXLIST = 1003
IDS_MULTI_LINE_STRINGBOX = 1004
IDS_PROCESSBAR_GUI = 1006
IDS_PROCESSBAR_TEXT = 1007
def Get_ObjectsLinkList(self):
""" Get Objects """
LinkList = self.FindCustomGui(self.IDS_LINKBOXLIST, c4d.CUSTOMGUI_INEXCLUDE_LIST)
Get_ObjectListData = LinkList.GetData()
objs = Get_ObjectListData.GetObjectCount()
if objs:
currentNum = 1
amountOfObjects = objs
for i in xrange(objs):
self.SetString(self.IDS_PROCESSBAR_TEXT,
Run_PrcoessBar(ui_ins=self,
progressbar_ui_id=self.IDS_PROCESSBAR_GUI,
currentNum=currentNum,
amountOfObjects=amountOfObjects,
col=None #DARK_BLUE_TEXT_COL # DARK_RED_TEXT_COL
)
)
# Get Data From Objects
objName_data = Get_ObjectListData.ObjectFromIndex(doc, i).GetName()
objID_data = Get_ObjectListData.ObjectFromIndex(doc, i).GetGUID()
# Print to Your Custom GUI Log
data = self.GetString(self.IDS_MULTI_LINE_STRINGBOX)
show_data = data +"\n" +objName_data+" | ID : "+str(objID_data)
self.SetString(self.IDS_MULTI_LINE_STRINGBOX, show_data)
print(show_data)
currentNum += 1
Stop_ProgressBar(ui_ins=self, progressbar_ui_id=self.IDS_PROCESSBAR_GUI)
return True
# ====================================== #
# Main GeDialog Class Overrides
# ====================================== #
def __init__(self):
"""
The __init__ is an Constuctor and help get
and passes data on from the another class.
"""
super(Tool_WindowDialog, self).__init__()
# UI Layout
def CreateLayout(self):
# Dialog Title
self.SetTitle("LinkBoxList & ProcessBar GUI")
# Top Menu addinng Tool Version
self.GroupBeginInMenuLine()
self.AddStaticText(self.IDS_VER, 0)
self.SetString(self.IDS_VER, " v1.0 ")
self.GroupEnd()
self.GroupBegin(self.IDS_OverallGrp, c4d.BFH_SCALEFIT, 1, 0, "") # Overall Group.
# Static UI Text
self.AddStaticText(self.IDS_StaticText, c4d.BFH_CENTER, 0, 15, "LinkBoxList & ProcessBar GUI Example", c4d.BORDER_WITH_TITLE_BOLD)
self.AddSeparatorH(0, c4d.BFH_SCALEFIT) # Line Separator / eg: self.AddSeparatorH(0, c4d.BFH_MASK) and AddSeparatorV
self.GroupBegin(0, c4d.BFH_SCALEFIT, 3, 0, "")
self.GroupBorderSpace(5, 5, 5, 5)
self.GroupBegin(0, c4d.BFH_SCALEFIT, 1, 0, "")
self.AddStaticText(self.IDS_StaticText, c4d.BFH_LEFT, 0, 15, " Add Objects :", c4d.BORDER_WITH_TITLE_BOLD)
AddLinkBoxList_GUI(ui_ins=self, ui_id=self.IDS_LINKBOXLIST, w_size=290, h_size=200, enable_state_flags=False)
self.GroupEnd()
self.AddSeparatorV(0, c4d.BFV_SCALEFIT)
self.GroupBegin(0, c4d.BFH_SCALEFIT, 1, 0, "")
self.AddStaticText(self.IDS_StaticText, c4d.BFH_LEFT, 0, 15, " Log :", c4d.BORDER_WITH_TITLE_BOLD)
self.AddMultiLineEditText(self.IDS_MULTI_LINE_STRINGBOX, c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT, 290, 200, c4d.DR_MULTILINE_MONOSPACED)
self.GroupEnd()
self.GroupEnd()
self.AddSeparatorH(0, c4d.BFH_SCALEFIT)
Add_ProgressBar_GUI(ui_ins=self, progressbar_ui_id=self.IDS_PROCESSBAR_GUI, strText_id=self.IDS_PROCESSBAR_TEXT, w_size=100, h_size=10)
self.AddSeparatorH(0, c4d.BFH_SCALEFIT)
self.AddButton(self.IDS_BTN_01, c4d.BFH_SCALEFIT, 100, 15, name="Run Process of Objects")
self.AddSeparatorH(0, c4d.BFH_SCALEFIT)
self.GroupEnd()
self.GroupEnd() # End of the overall group.
return True
def InitValues(self):
"""
Called when the dialog is initialized by the GUI / GUI's startup values basically.
"""
self.SetDefaultColor(self.IDS_OverallGrp, c4d.COLOR_BG, BG_DARK)
self.SetDefaultColor(self.IDS_StaticText, c4d.COLOR_TEXT, DARK_BLUE_TEXT_COL)
self.SetDefaultColor(self.IDS_VER, c4d.COLOR_TEXT, DARK_RED_TEXT_COL)
self.SetString(self.IDS_PROCESSBAR_TEXT, "0%")
#self.Enable(self.IDS_MULTI_LINE_STRINGBOX, False)# --> # Disable or Enable Mode of the user interaction
return True
def Command(self, id, msg):
"""
This Method is called automatically when the user clicks on a gadget and/or changes its value this function will be called.
It is also called when a string menu item is selected.
:param messageId: The ID of the gadget that triggered the event.
:param bc: The original message container
:return: False if there was an error, otherwise True.
"""
if id:
print(str(id))
if (id == self.IDS_BTN_01):
self.Get_ObjectsLinkList()
return True
def CoreMessage(self, id, msg):
"""
Override this function if you want to react to Cinema 4D core messages.
The original message is stored in msg
"""
if id == c4d.EVMSG_CHANGE:
pass
return True
def DestroyWindow(self):
"""
DestroyWindow Override this method - this function is
called when the dialog is about to be closed temporarily,
for example for layout switching.
"""
print("Script Tool GUI Dialog Close.")
if __name__=='__main__':
class_dialog = Tool_WindowDialog()
class_dialog.Open(c4d.DLG_TYPE_ASYNC, defaultw=200, defaulth=10)