How to recover a float type value?
-
On 16/02/2018 at 18:38, xxxxxxxx wrote:
Hi,
How to recover a float type value, with Python ?
The code below, allows the input of a value of type float, but I recover a rounded valueimport c4d
from c4d import gui, documentsclass sample(gui.GeDialog) :
button_ID = 1001
def CreateLayout(self) :
self.GroupBegin(100,c4d.BFH_CENTER,2,0,"Infos");
self.GroupBorder(c4d.BORDER_GROUP_IN)
self.GroupBorderSpace(10,5,10,5)
self.SetTitle("Sample")self.AddStaticText(1, c4d.BFH_LEFT, 0, 0, "Name", c4d.BORDER_NONE)
self.AddEditText(2,c4d.BFH_LEFT,200,10)self.AddStaticText(3, c4d.BFH_LEFT, 0, 0, "Weight", c4d.BORDER_NONE)
self.AddEditNumber(4, c4d.BFH_LEFT,100,10)self.GroupEnd()
self.AddButton(self.button_ID,c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT, 100, 15, "Print in console")return True
def Command(self, id, msg) :
if id == self.button_ID:
print self.GetString(2) #ok
print self.GetFloat(4) #rounded downself.Close()
return Trueif __name__=='__main__':
dlg = sample()
dlg.Open(0,c4d.DLG_TYPE_MODAL_RESIZEABLE,500,300,200)
c4d.EventAdd() -
On 17/02/2018 at 04:20, xxxxxxxx wrote:
you need to add the following code:
def InitValues(self) : self.SetFloat(4,0.0)
It seems that AddEditNumber use a int as default type
-
On 17/02/2018 at 09:23, xxxxxxxx wrote:
Hi,
Thank you Pyr, your solution works perfectly
***********************************************************************
The new code
***********************************************************************
import c4d
from c4d import gui, documentsdef InitValues(self) :
** self.SetFloat(4,0.0)**
class sample(gui.GeDialog) :
button_ID = 1001
def CreateLayout(self) :
self.GroupBegin(100,c4d.BFH_CENTER,2,0,"Infos");
self.GroupBorder(c4d.BORDER_GROUP_IN)
self.GroupBorderSpace(10,5,10,5)
self.SetTitle("Sample")self.AddStaticText(1, c4d.BFH_LEFT, 0, 0, "Name", c4d.BORDER_NONE)
self.AddEditText(2,c4d.BFH_LEFT,200,10)self.AddStaticText(3, c4d.BFH_LEFT, 0, 0, "Weight", c4d.BORDER_NONE)
self.AddEditNumber(4, c4d.BFH_LEFT,100,10)
InitValues(self)self.GroupEnd()
self.AddButton(self.button_ID,c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT, 100, 15, "Print in console")return True
def Command(self, id, msg) :
if id == self.button_ID:
print self.GetString(2) #ok
print self.GetFloat(4) #okself.Close()
return Trueif __name__=='__main__':
dlg = sample()
dlg.Open(0,c4d.DLG_TYPE_MODAL_RESIZEABLE,500,300,200)
c4d.EventAdd()***********************************************************************
with variant
***********************************************************************
import c4d
from c4d import gui, documentsclass sample(gui.GeDialog) :
button_ID = 1001
def CreateLayout(self) :
self.GroupBegin(100,c4d.BFH_CENTER,2,0,"Infos");
self.GroupBorder(c4d.BORDER_GROUP_IN)
self.GroupBorderSpace(10,5,10,5)
self.SetTitle("Sample")self.AddStaticText(1, c4d.BFH_LEFT, 0, 0, "Name", c4d.BORDER_NONE)
self.AddEditText(2,c4d.BFH_LEFT,200,10)self.AddStaticText(3, c4d.BFH_LEFT, 0, 0, "Weight", c4d.BORDER_NONE)
self.AddEditNumber(4, c4d.BFH_LEFT,100,10)
self.SetFloat(4,0.0)self.GroupEnd()
self.AddButton(self.button_ID,c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT, 100, 15, "Print in console")return True
def Command(self, id, msg) :
if id == self.button_ID:
print self.GetString(2) #ok
print self.GetFloat(4) #okself.Close()
return Trueif __name__=='__main__':
dlg = sample()
dlg.Open(0,c4d.DLG_TYPE_MODAL_RESIZEABLE,500,300,200)
c4d.EventAdd() -
On 18/02/2018 at 00:31, xxxxxxxx wrote:
i would recommend that you put the initValue inside of your GeDialog class
the advantage is that you didn't need to call the function manually:
See GeDialog.InitValue SDKCalled when the dialog is initialized by the GUI.