Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    How to recover a float type value?

    Scheduled Pinned Locked Moved PYTHON Development
    4 Posts 0 Posters 738 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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 value

      import c4d
      from c4d import gui, documents

      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)

      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 down 😠

      self.Close()
              return True

      if __name__=='__main__':
          dlg = sample()
          dlg.Open(0,c4d.DLG_TYPE_MODAL_RESIZEABLE,500,300,200)
          c4d.EventAdd()

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        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

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          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, documents

          def 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)    #ok 🙂

          self.Close()
                  return True

          if __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, documents

          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)
                  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)    #ok 🙂

          self.Close()
                  return True

          if __name__=='__main__':
              dlg = sample()
              dlg.Open(0,c4d.DLG_TYPE_MODAL_RESIZEABLE,500,300,200)
              c4d.EventAdd()

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            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 SDK

            Called when the dialog is initialized by the GUI.
            
            1 Reply Last reply Reply Quote 0
            • First post
              Last post