Problems with Edit Slider



  • On 14/05/2013 at 11:15, xxxxxxxx wrote:

    Hi,

    When I assign a value in InitValues(self) for an EditSlider, I can't use the slider anymore (it stays at the same value). So when I try to get the value it doesn't work, because the slider can't be edited.

    I've followed the Python SDK instructions, but I'm not getting any further.
    Are there special things I have to do to make it work?

    Greetings,

    Casimir



  • On 14/05/2013 at 13:04, xxxxxxxx wrote:

    post your code.



  • On 15/05/2013 at 06:44, xxxxxxxx wrote:

    Here is the code:

    import c4d
    import os
    import sys
    from c4d import gui, plugins, bitmaps, documents, utils
    from c4d.modules import mograph

    PLUGIN_ID = 1000003 # Test ID

    #Global Variables

    FOOT_X = 16.0
    FOOT_Y = 4.0
    FOOT_Z = 24.0

    #Groups

    GroupFoot = 20100

    #CreateObjectMethods

    def AddLeftFoot(doc) :

    global L_Foot
      L_Foot = c4d.BaseObject(c4d.Ocube)
      L_Foot[c4d.PRIM_CUBE_LEN, c4d.VECTOR_X] = FOOT_X
      L_Foot[c4d.PRIM_CUBE_LEN, c4d.VECTOR_Y] = FOOT_Y
      L_Foot[c4d.PRIM_CUBE_LEN, c4d.VECTOR_Z] = FOOT_Z
      L_Foot[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Y] = FOOT_Y/2
      L_Foot.SetName('L_Foot')
      doc.InsertObject(L_Foot)
      c4d.EventAdd()

    #SliderDialog

    class InitializeSubDialog(c4d.gui.SubDialog) :

    def CreateLayout(self) :         #Layout
          self.SetTitle("Character Values")
          
          #Group Foot
          self.GroupBegin(GroupFoot, c4d.BFH_SCALEFIT, 2, 0, "Foot")
          self.GroupBorderSpace(5, 5, 5, 5)
          self.GroupBorder(c4d.BORDER_GROUP_IN)
          self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Foot_X", 0)
          self.AddEditSlider(20101, c4d.BFH_SCALEFIT, 500, 0)
          self.GroupEnd()
         
          return True

    def InitValues(self) :           #Initialize Layout Values (Called when the dialog is initialized by the GUI.)

    self.SetReal(id = 20101, value = None, min = 5.0, max = 20.0, step = 1.0, format = c4d.FORMAT_METER)
          return True

    def Command(self, id, msg) :     #Commands
         
          global L_Foot
          if (id == 20101) :           #Foot_X SLider
              FOOT_X = self.GetReal(20101)
              L_Foot[c4d.PRIM_CUBE_LEN, c4d.VECTOR_X] = FOOT_X
              c4d.EventAdd()
         
          return True

    #InitialDialog

    class InitializeDialog(c4d.gui.GeDialog) :

    def CreateLayout(self) :         #Layout
          self.SetTitle("Character Creator")

    self.AddStaticText(0, c4d.BFH_CENTER, 0, 0, "GENDER", 0)
          self.AddComboBox(10001, c4d.BFH_CENTER, 200, 0)
          self.AddChild(10001, 0, "MALE")
          self.AddChild(10001, 1, "FEMALE")
          self.AddSeparatorH(200, c4d.BFH_CENTER)
          self.AddButton(10002, c4d.BFH_CENTER, 150, 0, "Create Character")
     
          return True

    def InitValues(self) :           #Initialize Layout Values (Called when the dialog is initialized by the GUI.)
     
          return True

    def Command(self, id, msg) :     #Commands
         
          if (id == 10002) :           #Button Create Character
              GENDER = self.GetLong(10001)
              print GENDER
              doc = c4d.documents.GetActiveDocument()
              AddLeftFoot(doc)
              InitializeSubDialog().Open(dlgtype = c4d.DLG_TYPE_ASYNC, pluginid = PLUGIN_ID, defaultw = 500, defaulth = 600)
             
              return True

    c4d.EventAdd()

    return True

    class Initialize(c4d.plugins.CommandData) :

    dialog = None

    def Init(self, op) :
          return True

    def Message(self, type, data) :
          return True

    def Execute(self, doc) :
          if self.dialog is None:
              self.dialog = InitializeDialog()
          return self.dialog.Open(dlgtype = c4d.DLG_TYPE_ASYNC, pluginid = PLUGIN_ID, defaultw = 200, defaulth = 160)

    if __name__ == "__main__":
      bmp = c4d.bitmaps.BaseBitmap()
      dir, file = os.path.split(__file__)
      fn = os.path.join(dir, "res", "IconChar.tif")
      bmp.InitWith(fn)
      print "Character Creator Loaded."
      result = plugins.RegisterCommandPlugin(PLUGIN_ID, "Character Creator", 0, bmp, "Character Creator", Initialize())



  • On 15/05/2013 at 07:36, xxxxxxxx wrote:

    And when I don't assign a value in the SetReal, I can use the slider and get information out of it.



  • On 15/05/2013 at 08:19, xxxxxxxx wrote:

    Not relates to your problem, but you will have problems if you store L_Foot globally. Better store it somewhere else than the global scope (eg from where you call AddLeftFoot(), and return L_Foot in this function)



  • On 15/05/2013 at 09:28, xxxxxxxx wrote:

    Ditto what Nik said.
    It's ok to use globals in C4D plugins. But try not to get carried away with them.
    Put those kinds of values into your methods parameters whenever possible. It will be less confusing later on.

    The reason you're having trouble with your slider is because the main GeDialog needs an instance of the subdialog in it so it can talk to the sub dialog properly.

    Here's an example how to set up the dialogs:

    import c4d  
    import os  
    import sys  
    from c4d import gui, plugins, bitmaps, documents, utils  
      
    PLUGIN_ID = 1000003 # Test ID  
      
    GroupFoot = 2000  
    FOOT_X_TEXT = 1000  
    FOOT_X_SLIDER = 1001  
      
    ###### The sub dialog ######  
    class InitializeSubDialog(gui.GeDialog) :       #<--You don't need to use "subdialog" ...It can just be another GeDialog  
      
      def CreateLayout(self) :  
          self.SetTitle("Character Values")  
            
          #Group Foot  
          self.GroupBegin(GroupFoot, c4d.BFH_SCALEFIT, 2, 0, "Foot")  
          self.GroupBorderSpace(5, 5, 5, 5)  
          self.GroupBorder(c4d.BORDER_GROUP_IN)  
          self.AddStaticText(FOOT_X_TEXT, c4d.BFH_LEFT, 0, 0, "Foot_X", 0)  
          self.AddEditSlider(FOOT_X_SLIDER, c4d.BFH_SCALEFIT, 500, 0)  
          self.GroupEnd()  
           
          return True  
       
      
      def InitValues(self) :  
      
          self.SetReal(id = FOOT_X_SLIDER, value = 5.0, min = 5.0, max = 20.0, step = 1.0, format = c4d.FORMAT_METER)  
          return True  
      
      def Command(self, id, msg) :  
          if (id == FOOT_X_SLIDER) :  
              print self.GetReal(FOOT_X_SLIDER)   #Print the value of the slider  
           
          return True  
      
      
    ###### The main dialog ######  
    class InitializeDialog(gui.GeDialog) :  
      
      subdlg = InitializeSubDialog()       #The sub dialog's local class member instance <--- Very important!!!!!  
      
      def CreateLayout(self) :  
          self.SetTitle("Character Creator")  
      
          self.AddStaticText(0, c4d.BFH_CENTER, 0, 0, "GENDER", 0)  
          self.AddComboBox(10001, c4d.BFH_CENTER, 200, 0)  
          self.AddChild(10001, 0, "MALE")  
          self.AddChild(10001, 1, "FEMALE")  
          self.AddSeparatorH(200, c4d.BFH_CENTER)  
          self.AddButton(10002, c4d.BFH_CENTER, 150, 0, "Create Character")  
      
          return True  
      
      
      def InitValues(self) :     
          return True  
      
      
      def Command(self, id, msg) :  
           
          if (id == 10002) :           #Button Create Character  
              GENDER = self.GetLong(10001)  
              print GENDER  
              doc = c4d.documents.GetActiveDocument()          
              self.subdlg.Open(dlgtype = c4d.DLG_TYPE_ASYNC, defaultw = 500, defaulth = 600)  
               
          c4d.EventAdd()  
      
          return True  
      
    class Initialize(c4d.plugins.CommandData) :  
      
      dialog = None  
      
      def Init(self, op) :  
          return True  
      
      def Message(self, type, data) :  
          return True  
      
      def Execute(self, doc) :  
          if self.dialog is None:  
              self.dialog = InitializeDialog()  
          return self.dialog.Open(dlgtype = c4d.DLG_TYPE_ASYNC, pluginid = PLUGIN_ID, defaultw = 200, defaulth = 160)  
      
          
    if __name__ == "__main__":  
      bmp = c4d.bitmaps.BaseBitmap()  
      dir, file = os.path.split(__file__)  
      fn = os.path.join(dir, "res", "IconChar.tif")  
      bmp.InitWith(fn)  
      result = plugins.RegisterCommandPlugin(PLUGIN_ID, "Character Creator", 0, bmp, "Character Creator", Initialize()) 
    

    -ScottA



  • On 15/05/2013 at 10:34, xxxxxxxx wrote:

    Thanks for saying where to store my variables, still having a bit trouble with python variables, im more used with C++. And how do you mean, not relates to your problem?
    I really have no clue how to get that slider good.

    Greets,

    Casimir



  • On 15/05/2013 at 10:36, xxxxxxxx wrote:

    Thanks for your answer scott!! I just saw it when I posted my other reply, I think it will be fine now :)

    Greets



  • On 15/05/2013 at 10:42, xxxxxxxx wrote:

    You have to pass a float to GeDialog.SetReal() as the value parameter. None won't work. 
    I think that is breaking the slider. You also did not implement RestoreLayout() despite the 
    fact that you did instantiate a non modal dialog which will generally end in a mess.

    You should also always implement object.__int__() for each class. also use constantly self.
    Both things are not mandatory but are considered as good style for a reason.



  • On 15/05/2013 at 10:57, xxxxxxxx wrote:

    Ok, thanks for your answers guys!


Log in to reply