THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/10/2011 at 13:26, xxxxxxxx wrote:
I'm not sure if you can do this in R12. Because SetImage() was not supported yet.
But it does work in R13.
Here's a complete dialog plugin example:
import c4d, os, sys
from c4d import plugins, utils, bitmaps, gui, documents
Plugin_ID=1000009 # Testing id ONLY!!!!!!!
#enums
myBitButton = 100010
class MyDialog_Gui(gui.GeDialog) :
def CreateLayout(self) :
bc = c4d.BaseContainer() #Create a new container to store the image we will load for the button later on
self.GroupBegin(0, c4d.BFH_SCALEFIT|c4d.BFH_SCALEFIT, 1, 1, "Bitmap Example",0) #id, flags, columns, rows, grouptext, groupflags
self.GroupBorder(c4d.BORDER_BLACK)
bc.SetLong(c4d.BITMAPBUTTON_BORDER, c4d.BORDER_OUT) #Sets the border to look like a button
bc.SetBool(c4d.BITMAPBUTTON_BUTTON, True)
fn = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_DESKTOP) #Gets the desktop path
path = os.path.join(fn,'image1.jpg') #The path to the image file
bc.SetFilename(100010, path) #Fill the empty container with the id#, and the image's location(string value)
#Lets check our container to see if the image's ID# and location are now stored in it properly
image = bc.GetData(100010)
print image
for i in bc:
print i
self.myBitButton=self.AddCustomGui(100010, c4d.CUSTOMGUI_BITMAPBUTTON, "Bitmap Button", c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 30, 30, bc)
self.myBitButton.SetImage(path, False)
self.LayoutChanged(10042) #Updates the custom gizmo changes made to the GUI
self.GroupEnd()
return True
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
self.SetReal(1002, 0, 0,100,1) #Sets the slider's value to 0... With a range of 0-100... Step=1
return True
def Command(self, id, msg) :
doc = documents.GetActiveDocument()
if id == 100010:
print"Bitmap Button was Pushed"
self.myBitButton.SetToggleState(True)
fn2 = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_DESKTOP) #Gets the desktop path
path = os.path.join(fn2,'image2.jpg') #The path to the image file
self.myBitButton.SetImage(fn2, False) #This does not work like in C++ !!!
self.LayoutChanged(10042) #Updates the custom gizmo changes made to the GUI
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())
Make sure you change the image references to image files you have on your desktop.
Or change the paths to where you want them to look for the button images.
As you can see. One thing I'm having trouble with is swapping the button's image when it's clicked.
This works perfectly in C++. But I can't get it to work with Python in R13.
-ScottA