Tutorial: how to create a dialog plugin
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 06/12/2012 at 08:56, xxxxxxxx wrote:
This tutorial will explain how to create a 'floating' dialog using Python.
What you will learn:
- Register the plugin
- Define Tabs
- Define, read and write a Link field using the AddCustomGui function
- Define Separators
- Define, read and write a Combo Box
- Define and read File Input field using again the AddCustomGui function
You can download the zip file with the pdf tutorial, the source and the plugin from my blog.
Everybody on the forum, thanks for your help.
-
On 01/01/2013 at 06:29, xxxxxxxx wrote:
Dear users,
I see this video for create a script for show a dialog, but when i run the script, show me the next message: "EnvironmmentError: cannot find the pyp file - plugin registration failed".
I sure that the problem is because i don´t know how to create the pyp file.
This is my script:
import c4d
from c4d import gui
from c4d import utils
from c4d import pluginsPLUGIN_ID=1029596
#Welcome to the world of Python
class MiDialogo(c4d.gui.GeDialog) :
def CreateLayout(self) :
self.element=self.AddStaticText(id=1001,flags=c4d.BFH_LEFT,initw=200, name="Diametro")
self.element=self.AddEditText(id=1001,flags=c4d.BFH_SCALEFIT|C4D.BFV_SCALEFIT,initw=400,inith=10,name="VDiametro")
return Trueclass MyMenuPlugin(c4d.plugins.CommandData) :
dialog = None
def Execute(self, doc) :
#self.dialog=MiDialogo()
return MiDialogo.Open(dlgtype=c4d.DLG_TYPE_ASYNC,pluginid=PLUGIN_ID,xpos=-1, ypos=-1,defaultw=200, defaulth=150)def RestoreLayout(self, sec_ref) :
# manage the dialog
if self.dialog is None:
self.dialog = MyDialog()
return self.dialog.Restore(pluginid=PLUGIN_ID, secret=sec_ref)
if __name__=='__main__':
okyn = plugins.RegisterCommandPlugin(PLUGIN_ID, "Generador de anillos",0,None, "Menu de anillos", MyMenuPlugin())
if (okyn) :
print "Inicializado el generador de anillos"
main()Thanks.
-
On 01/01/2013 at 08:47, xxxxxxxx wrote:
Script?
Are you trying to run this code in the script manager?
The code you're using is meant to be put in a .pyp file that sits in your plugins folder.There are also some mistakes in your code:
-Don't use Main() like this in plugins. That's usually a scripting thing.
-You had a C4D in the AddEditText() function instead of c4d
-AddEditText() does not have a "name" keyword. Each gizmo has their own parameters. Always check the docs for that.
-You have self.dialog = MiDialogo() commented out.Create a .txt file and paste this code into it:
import c4d from c4d import gui from c4d import utils from c4d import plugins PLUGIN_ID=1029596 #Welcome to the world of Python class MiDialogo(c4d.gui.GeDialog) : def CreateLayout(self) : self.element=self.AddStaticText(id=1001,flags=c4d.BFH_LEFT,initw=200, name="Diametro") self.element=self.AddEditText(id=1002,flags=c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT,initw=400,inith=10) return True class MyMenuPlugin(c4d.plugins.CommandData) : dialog = None def Execute(self, doc) : # create the dialog if self.dialog is None: self.dialog = MiDialogo() 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 the dialog if self.dialog is None: self.dialog = MiDialogo() return self.dialog.Restore(pluginid=PLUGIN_ID, secret=sec_ref) if __name__=='__main__': okyn = plugins.RegisterCommandPlugin(PLUGIN_ID, "Generador de anillos",0,None, "Menu de anillos", MyMenuPlugin()) if (okyn) : print "Inicializado el generador de anillos"
Then change the file extension from .txt to .pyp. ANd put it in your plugins folder.
It should run fine after doing that.-ScottA
-
On 01/01/2013 at 09:20, xxxxxxxx wrote:
Generador de anillos either sounds like something very tasty with loads of garlic or like something making you so drunk that everything is 'very t.asty with loads of garlic' for you.
-
On 01/01/2013 at 10:54, xxxxxxxx wrote:
Thanks ScottA, this code run perfectly in the plugin. It´s my first trial in cinema4d programming.