On 02/06/2013 at 11:04, xxxxxxxx wrote:
I think the code LD posted is more designed for a Node based plugin. Not a GeDialog.
I've used the filename gizmo in one of my examples.
Here's the entire code:
""" This is an example of using a .res based link box gizmo. And a customgui FILENAME gizmo """
#Id's for the custom LinkBox GUI if needed
#CUSTOMGUI_LINKBOX = 1009415,
#CUSTOMGUI_INLINE = 300001044,
import c4d,os,sys
from c4d import plugins, utils, bitmaps, gui, documents
Plugin_ID=1000011 # Testing id ONLY!!!!!!!
ResBasedMenu = 10001
MY_FILE = 10002
MY_LINK = 10003
MY_GROUP = 10004
class MyDialog_Gui(gui.GeDialog) :
mylink = None
file = None
def CreateLayout(self) :
res = self.LoadDialogResource(ResBasedMenu) #Loads GUI stuff from the .res file
self.GroupBegin(MY_GROUP, 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("LinkBox Example")
self.AddStaticText(1111,c4d.BFH_LEFT,50,10,"input",c4d.BORDER_NONE) #id, flags, height, width, text, borderstyle
#A linkbox gizmo created in the .res file
self.mylink = self.FindCustomGui(MY_LINK, c4d.CUSTOMGUI_LINKBOX)
#A FileName gizmo created here in the code(not in the .res file)
settings = c4d.BaseContainer()
#settings.SetBool(c4d.FILENAME_DIRECTORY, True) #Use this to restrict selections to a folder(not a file)
#settings.SetBool(c4d.FILENAME_SAVE, True) #Use this to open the save dialog
#settings.SetBool(c4d.FILENAME_TEXTURE, True) #Texture mode...Makes the "do you want to create a project copy" message window pop up
self.file = self.AddCustomGui(MY_FILE, c4d.CUSTOMGUI_FILENAME, "", c4d.BFH_SCALEFIT|c4d.BFV_CENTER, 0, 0, settings)
self.GroupEnd()
return res
def InitValues(self) :
return True
def Command(self, id, msg) :
doc = documents.GetActiveDocument()
if id == MY_LINK: #When an object is droppped into the linkbox
print self.mylink.GetLink().GetName() #print that object's name
c4d.EventAdd()
return True
def CoreMessage(self, id, msg) :
if id == c4d.EVMSG_CHANGE:
doc = documents.GetActiveDocument()
#print "Event Occurred"
linkedFile = self.GetString(MY_FILE) #Gets the fn(string) path of the file in the gizmo
if len(linkedFile) != 0: #If there's a file in the gizmo
print linkedFile #Do something with that file
return True
#-------------------------------------------------------------------------
# MyDialog_Main --- Where the plugin stuff happens--Don't edit this part
#-------------------------------------------------------------------------
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, xpos=-1, ypos=-1)
def RestoreLayout(self, sec_ref) :
#Manage the async dialog so it can be docked in the UI
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")) #Uses a folder called "icons" inside the "res" folder to hold the icon
plugins.RegisterCommandPlugin(Plugin_ID, "LinkBox Example", 0, None, "", myDialog_Main())
When an image file is added to the filename gizmo using the file browser. The EVMSG_CHANGE message is sent to C4D. So you can use that message in place of a drag&drop message.
-ScottA