THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/04/2011 at 08:50, xxxxxxxx wrote:
I didn't see any examples of creating menus and sub menus in the SDK.
So here is an entire plugin example that shows how to create them. And does some other common tasks.
import os
import sys
import c4d
from c4d import plugins, utils, bitmaps, gui, documents
Plugin_ID=1000009 # Testing id ONLY!!!!!!!
#enums
MENU_ITEM1 = 1
MENU_ITEM2 = 2
MENU_ITEM3 = 3
MENU_ITEM4 = 4
RESET_BUTTON = 5
#---------------------------------------------------
# MyDialog_Gui class --- where GUI items are added
#---------------------------------------------------
class MyDialog_Gui(gui.GeDialog) :
def CreateLayout(self) :
#This is the first menu code
self.MenuFlushAll();
self.MenuSubBegin("Menu1")
self.MenuAddString(MENU_ITEM1,"item1")
self.MenuAddString(MENU_ITEM2,"item2")
self.MenuAddSeparator()
self.MenuSubBegin("SubMenu1")
self.MenuAddCommand(1001153) # Creates an atom object
self.MenuSubBegin("SubMenu2")
self.MenuAddCommand(1001154) # Creates a double circle object
self.MenuSubEnd()
self.MenuSubEnd()
self.MenuSubEnd()
self.MenuFinished() #Ends the first menu & submenu list
#This is the second menu code
#Notice that we don't make another MenuFlushAll() function
self.MenuSubBegin("Menu2")
self.MenuAddString(MENU_ITEM3,"test1")
self.MenuAddString(MENU_ITEM4,"test2")
self.MenuAddSeparator()
self.MenuSubBegin("SubMenu1")
self.MenuAddCommand(5159) # Creates a Cube primitive
self.MenuSubBegin("SubMenu2")
self.MenuAddCommand(5160) # Creates a Sphere primitive
self.MenuSubEnd()
self.MenuSubEnd()
self.MenuSubEnd()
self.MenuFinished() #Ends the second menu & submenu list
self.GroupBeginInMenuLine() #Adds the Button to the menu area of the dialog window
self.AddButton(RESET_BUTTON, c4d.BFH_CENTER, 60, 10, name="Reset") #id, flags, width, height, caption
self.GroupEnd() #Ends the group formatting
self.GroupBegin(0, c4d.BFH_SCALEFIT|c4d.BFH_SCALEFIT, 1, 3, "Group Title",0) #id, flags, columns, rows, grouptext, groupflags
self.GroupBorder(c4d.BORDER_BLACK)
self.GroupBorderSpace(5, 20, 5, 20) #Left, top, Right, Bottom
self.SetTitle("myPythonDialog")
self.AddStaticText(4001,c4d.BFH_LEFT,50,10,"input",c4d.BORDER_NONE) #id, flags, height, width, text, borderstyle
self.AddEditText(4002,c4d.BFH_SCALEFIT,4,10,0) #id, flags, height, width, password
self.AddEditText(4003,c4d.BFH_SCALEFIT,2,10,0) #id, flags, height, width, password
self.AddButton(1001, c4d.BFH_CENTER, 100, 10, name="Execute X-Ray") #Puts the button in the menu bar
self.GroupEnd()
return True
#--------------------------------------------------------------------------
# MyDialog_Gui method --- where gui items are set up with default values
#--------------------------------------------------------------------------
def InitValues(self) :
self.SetString(4002,"Waiting") #Sets the text inside of the field when the plugin opens
self.SetString(4003,"Waiting") #Sets the text inside of the field when the plugin opens
return True
#---------------------------------------------------------------------------------------------
# MyDialog_Gui method --- Executes your code when GUI is used. Put your python code in here
#---------------------------------------------------------------------------------------------
def Command(self, id, msg) :
doc = documents.GetActiveDocument()
op = doc.GetActiveObject()
if id == 1001:
print "Button was pushed"
if not op:
gui.MessageDialog("Select an object first!")
return True
op[c4d.ID_BASEOBJECT_XRAY]=1
self.SetString(4002,"Button Worked!") #Sets the text inside of the field when the button is pushed
self.SetString(4003,"Congradulations!") #Sets the text inside of the field when the button is pushed
#gui.MessageDialog("Button was pushed") # Makes a pop up message appear whe the button is pushed
if id == RESET_BUTTON:
self.SetString(4002,"Waiting") #ReSets the text
self.SetString(4003,"Waiting") #ReSets the text
op[c4d.ID_BASEOBJECT_XRAY]=0 #Turns the Xray option off
c4d.EventAdd()
return True
#---------------------------------------------------------------
# MyDialog_Main --- Where the plugin stuff happens--Don't edit
#---------------------------------------------------------------
class myDialog_Main(plugins.CommandData) :
dialog = None
def Execute(self, doc) :
# create the dialog
if self.dialog is None:
self.dialog = MyDialog_Gui()
return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=Plugin_ID, defaultw=200, defaulth=150, xpos=-1, ypos=-1)
def RestoreLayout(self, sec_ref) :
# manage nonmodal dialog
if self.dialog is None:
self.dialog = MyDialog_Gui()
return self.dialog.Restore(pluginid=Plugin_ID, secret=sec_ref)
if __name__ == "__main__":
path, fn = os.path.split(__file__)
bmp = bitmaps.BaseBitmap()
bmp.InitWith(os.path.join(path, "res/icons/", "None"))
plugins.RegisterCommandPlugin(Plugin_ID, "myPythonDialog",0,None,"", myDialog_Main())
-ScottA