gui input dialog as integer [SOLVED]
-
On 30/07/2015 at 02:40, xxxxxxxx wrote:
Hi everyone,
I am currently trying to create an input box, where someone can put a number in and then the number will be used for different kind of things.
So I created this field.
x = gui.InputDialog("Object ID", "ID")
that works fine, but I am always getting a string back. But I need an integer or an vector. So how can I tell my InputDialog, that this should be an integer or a vector? I know that I can create a vector by using c4d.Vector(). But how do I connect it with the InputDialog?
Would be great, if someone could help me.
Thanks a lot
Anna
-
On 30/07/2015 at 04:36, xxxxxxxx wrote:
Hello Anna
non elegant and silly example:
import c4d from c4d import gui def main() : s = gui.InputDialog("Object ID", "10.5 25 3") x, y, z = s.split()[0], s.split()[1], s.split()[2] print c4d.Vector(float(x), float(y), float(z)) if __name__=='__main__': main()
upd.
Learn how to work http://www.tutorialspoint.com/python/python_strings.htm
and int/float and etc. http://www.tutorialspoint.com/python/python_numbers.htm -
On 31/07/2015 at 02:35, xxxxxxxx wrote:
Hi,
there are no pre-made dialogs for numeric values. Ilya's solution is one way and definitely works, but this also may get tedious to check and care for user input errors.
Another option would be to create your own dialog using GeDialog class with proper gadgets for floats or vectors. There are several examples in the Python SDK setting up custom dialogs. For example the Py-MemoryViewer. -
On 31/07/2015 at 06:10, xxxxxxxx wrote:
Somewhere over forum, Niklas post solution how to use resources from Resedit solution inside c4d without plug-in skeleton.
Anna, you can prepare simple dialogs in resedit with gadget - Vector(id = 23)*, add functions and invoke in c4d environment.
It will add custom gui to scripts.* - which Andreas pointed
-
On 01/08/2015 at 07:27, xxxxxxxx wrote:
Hey you two,
thanks a lot for your answers, it is really helpful I am currently reading through all the infos and trying to write something to show. I guess I will come back with lots of more questions.
Thanks a lot again
Anna
-
On 01/08/2015 at 08:53, xxxxxxxx wrote:
another primitive example, select object and execute script:
import c4d from c4d import gui GROUP_ID1=1000 BUTTON1=1001 VX=1002 VY=1003 VZ=1004 ST=1005 class Test_Dlg(gui.GeDialog) : def addvector(self) : doc = c4d.documents.GetActiveDocument() op = doc.GetActiveObject() if not op: return False doc.StartUndo() doc.AddUndo(c4d.UNDOTYPE_CHANGE, op) op.SetAbsPos(c4d.Vector(self.GetFloat(VX),self.GetFloat(VY),self.GetFloat(VZ))) doc.EndUndo() c4d.SendCoreMessage(c4d.COREMSG_CINEMA, c4d.BaseContainer(c4d.COREMSG_CINEMA_FORCE_AM_UPDATE)) return True def CreateLayout(self) : #creat the layout of the dialog self.GroupBegin(GROUP_ID1, c4d.BFH_SCALEFIT, 4, 1) self.AddStaticText(ST, c4d.BFH_SCALE, name="Value of vector data:") self.AddEditNumberArrows(VX, c4d.BFH_SCALE) self.AddEditNumberArrows(VY, c4d.BFH_SCALE) self.AddEditNumberArrows(VZ, c4d.BFH_SCALE) self.GroupEnd() self.GroupBegin(GROUP_ID1, c4d.BFH_SCALEFIT, 2, 1) self.AddButton(BUTTON1, c4d.BFH_SCALE, name="Apply") self.GroupEnd() return True def InitValues(self) : #initiate the gadgets with values self.SetTitle('Add vector') return True def Command(self, id, msg) : #handle user input if id==BUTTON1: self.addvector() c4d.DrawViews(c4d.DA_ONLY_ACTIVE_VIEW|c4d.DA_NO_THREAD|c4d.DA_NO_ANIMATION) self.Close() return True dlg = Test_Dlg() dlg.Open(c4d.DLG_TYPE_MODAL, xpos=600, ypos=350, defaultw=400, defaulth=100)