Skip to content

Commit a73d4ba

Browse files
committed
S24 Hotfix 1
Replaced py-cv_rss by py-commandata-dialog (simpler and more descriptive of a basic GeDialog and CommandData example). Fix various plugins issues
1 parent 13f9d2a commit a73d4ba

File tree

8 files changed

+116
-492
lines changed

8 files changed

+116
-492
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
"""
2+
Copyright: MAXON Computer GmbH
3+
Author: Maxime Adam
4+
5+
Description:
6+
- Creates a Dialog which display 2 buttons OK and Cancel.
7+
8+
Class/method highlighted:
9+
- c4d.plugins.CommandData
10+
- CommandData.Execute()
11+
- c4d.gui.GeDialog
12+
- GeDialog.CreateLayout()
13+
- GeDialog.Command()
14+
"""
15+
import c4d
16+
17+
18+
# Be sure to use a unique ID obtained from www.plugincafe.com
19+
PLUGIN_ID = 1057171
20+
21+
22+
class ExampleDialog(c4d.gui.GeDialog):
23+
24+
def CreateLayout(self):
25+
"""This Method is called automatically when Cinema 4D Create the Layout (display) of the Dialog."""
26+
# Defines the title of the Dialog
27+
self.SetTitle("This is an example Dialog")
28+
29+
# Creates a Ok and Cancel Button
30+
self.AddDlgGroup(c4d.DLG_OK | c4d.DLG_CANCEL)
31+
32+
return True
33+
34+
def Command(self, messageId, bc):
35+
"""This Method is called automatically when the user clicks on a gadget and/or changes its value this function will be called.
36+
It is also called when a string menu item is selected.
37+
38+
Args:
39+
messageId (int): The ID of the gadget that triggered the event.
40+
bc (c4d.BaseContainer): The original message container.
41+
42+
Returns:
43+
bool: False if there was an error, otherwise True.
44+
"""
45+
# User click on Ok buttonG
46+
if messageId == c4d.DLG_OK:
47+
print("User Click on Ok")
48+
return True
49+
50+
# User click on Cancel button
51+
elif messageId == c4d.DLG_CANCEL:
52+
print("User Click on Cancel")
53+
54+
# Close the Dialog
55+
self.Close()
56+
return True
57+
58+
return True
59+
60+
61+
class ExampleDialogCommand(c4d.plugins.CommandData):
62+
"""Command Data class that holds the ExampleDialog instance."""
63+
dialog = None
64+
65+
def Execute(self, doc):
66+
"""Called when the user executes a command via either CallCommand() or a click on the Command from the extension menu.
67+
68+
Args:
69+
doc (c4d.documents.BaseDocument): The current active document.
70+
71+
Returns:
72+
bool: True if the command success.
73+
"""
74+
# Creates the dialog if its not already exists
75+
if self.dialog is None:
76+
self.dialog = ExampleDialog()
77+
78+
# Opens the dialog
79+
return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=400, defaulth=32)
80+
81+
def RestoreLayout(self, sec_ref):
82+
"""Used to restore an asynchronous dialog that has been placed in the users layout.
83+
84+
Args:
85+
sec_ref (PyCObject): The data that needs to be passed to the dialog.
86+
87+
Returns:
88+
bool: True if the restore success
89+
"""
90+
# Creates the dialog if its not already exists
91+
if self.dialog is None:
92+
self.dialog = ExampleDialog()
93+
94+
# Restores the layout
95+
return self.dialog.Restore(pluginid=PLUGIN_ID, secret=sec_ref)
96+
97+
98+
# main
99+
if __name__ == "__main__":
100+
# Registers the plugin
101+
c4d.plugins.RegisterCommandPlugin(id=PLUGIN_ID,
102+
str="Py-CommandData Dialog",
103+
info=0,
104+
help="Display a basic GUI",
105+
dat=ExampleDialogCommand(),
106+
icon=None)

0 commit comments

Comments
 (0)