I have a gui.GeDialog with a few Edit Text boxes and I wanted to drop textures from my Windows Explorer on there and get the full path of each texture, just like in the texture field on a material.
I found a couple of useful posts approaching the same question, but the solution seems to be directed to more experienced Python users, as they have only parts of code, not a full working example.
I'd appreciate if someone could share an example on how to do that in this dialog here:
self.AddEditText(1000, c4d.BFH_SCALEFIT, initw=0, inith=0)
self.AddEditText(1001, c4d.BFH_SCALEFIT, initw=0, inith=0)
self.AddEditText(1002, c4d.BFH_SCALEFIT, initw=0, inith=0)
self.AddEditText(1003, c4d.BFH_SCALEFIT, initw=0, inith=0)
dialog = MyDialog()
dialog.Open(dlgtype=c4d.DLG_TYPE_MODAL_RESIZEABLE, defaultw=500, defaulth=500)
if __name__ == '__main__':
thank you for reaching out to us. To replicate the BitmapShader behaviour you have to use a FilenameCustomGui. It comes with drag and drop support out of the box. Below is an example showcasing how to create such an element in a GeDialog and how to interact with drag and drop events.
"""Example for creating a CUSTOMGUI_FILENAME in a GeDialog and how to handle
drag and drop events.
As discussed in:
ID_FILE_LINK_1 = 1000
# Add a filename custom GUI to the dialog. You can read more about it
# in the C++ documentation . The type itself has not been wrapped
# for Python, but you can interact with it as a BaseCustomGui.
self.AddCustomGui(ID_FILE_LINK_1, c4d.CUSTOMGUI_FILENAME, "",
c4d.BFH_SCALEFIT, 0, 0, c4d.BaseContainer())
def Message(self, msg, result):
# When the message id is BFM_ACTION.
if msg.GetId() == c4d.BFM_ACTION:
# An action send from the filename GUI ID_FILE_LINK_1.
if msg[c4d.BFM_ACTION_ID] == ID_FILE_LINK_1:
# The newly set file path value.
filePath = msg[c4d.BFM_ACTION_VALUE]
# You can also access the directly element like so:
filePath = self.GetString(ID_FILE_LINK_1)
return c4d.gui.GeDialog.Message(self, msg, result)
DIALOG = None
DIALOG = MyDialog()
if __name__ == '__main__':
Hey Ferdinand, thank you very much for your time. I really appreciate that!
A custom GUI is so much easier, that I think my whole script is gonna be much shorter and with a pretty nice new functionality.
I am glad that it works for you, @m_magalhaes also pointed out that the custom gui flags (you have to write them into the BaseContainer passed an argument to the AddCustomGui call) might be helpful to you in case you want the gui to look more like a text box. The flag NOSELECT will make the ... button disappear. You can play around with the flags in the user data manager.
The user data manager with a Filename element and its flags: