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
    • Recent
    • Tags
    • Users
    • Login

    Adjust Objects with 2 Editsliders

    Scheduled Pinned Locked Moved PYTHON Development
    9 Posts 0 Posters 819 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 23/05/2013 at 10:45, xxxxxxxx wrote:

      Hi,

      I need to adjust an object, but the values I need for that come from two different sliders.
      Does somebody know an easy way to accomplish that?

      Tnx

      Casimir

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

        On 23/05/2013 at 11:14, xxxxxxxx wrote:

        please describe exactly what you want to do. we know nothing about the location of
        the gui gadgets.

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

          On 23/05/2013 at 11:44, xxxxxxxx wrote:

          L_Leg[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_Y] = FOOT_Y/2 + LEG_Y/2
          --> This is the one that needs to change

          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

          ZERO = 0

          FOOT_Y_TEXT = 1002
          FOOT_Y_SLIDER = 1003

          LEG_Y_TEXT = 1010
          LEG_Y_SLIDER = 1011

          #Groups

          GroupFoot = 20100
          GroupLeg = 20101

          def AddLeftLeg(doc) :

          FOOT_Y = 4.0
            FOOT_AXIS_X = 11.0
            LEG_X = 14.0
            LEG_Y = 38.0
            LEG_Z = 14.0

          if (doc.SearchObject('L_Leg') == None) :
                global L_Leg
                L_Leg = c4d.BaseObject(c4d.Ocube)
                L_Leg[c4d.PRIM_CUBE_LEN, c4d.VECTOR_X] = LEG_X
                L_Leg[c4d.PRIM_CUBE_LEN, c4d.VECTOR_Y] = LEG_Y
                L_Leg[c4d.PRIM_CUBE_LEN, c4d.VECTOR_Z] = LEG_Z
                L_Leg[c4d.PRIM_CUBE_SUBY] = 2                   #Segments
                L_Leg[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_X] = FOOT_AXIS_X
                #L_Leg[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_Y] = FOOT_Y/2 + LEG_Y/2
                L_Leg.SetName('L_Leg')
                doc.InsertObject(L_Leg)
                c4d.EventAdd()

          #SliderDialog

          class InitializeSubDialog(c4d.gui.GeDialog) :

          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(FOOT_Y_TEXT, c4d.BFH_LEFT, 100, 0, "Foot_Y", 0)
                self.AddEditSlider(FOOT_Y_SLIDER, c4d.BFH_SCALEFIT, 100, 0)
                self.GroupEnd()

          #Group Leg
               
                self.GroupBegin(GroupLeg, c4d.BFH_SCALEFIT, 2, 0, "Leg")
                self.GroupBorderSpace(5, 5, 5, 5)
                self.GroupBorder(c4d.BORDER_GROUP_IN)
                self.AddStaticText(LEG_Y_TEXT, c4d.BFH_LEFT, 100, 0, "Leg_Y", 0)
                self.AddEditSlider(LEG_Y_SLIDER, c4d.BFH_SCALEFIT, 100, 0)
                self.GroupEnd()
               
                return True

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

          self.SetReal(id = FOOT_Y_SLIDER, value = 4.0, min = 2.0, max = 10.0, step = 1.0, format = c4d.FORMAT_METER)

          self.SetReal(id = LEG_Y_SLIDER, value = 38.0, min = 20.0, max = 60.0, step = 1.0, format = c4d.FORMAT_METER)

          return True

          def Command(self, id, msg) :     #Commands
               
                FOOT_Y = 4.0
                LEG_Y = 38.0

          if (id == FOOT_Y_SLIDER) :           #Foot_Y Slider
                    FOOT_Y = self.GetReal(FOOT_Y_SLIDER)
                    #L_Leg[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_Y] = FOOT_Y/2 + LEG_Y/2
                    c4d.EventAdd()

          if (id == LEG_Y_SLIDER) :            #Leg_Y Slider
                    LEG_Y = self.GetReal(LEG_Y_SLIDER)
                    L_Leg[c4d.PRIM_CUBE_LEN, c4d.VECTOR_Y] = LEG_Y
                    #L_Leg[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_Y] = FOOT_Y/2 + LEG_Y/2
                    c4d.EventAdd()

          return True

          #MainDialog

          class InitializeDialog(c4d.gui.GeDialog) :
           
            subdlg = InitializeSubDialog()  #The sub dialog's local class member instance <--- VERY IMPORTANT

          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()
                    AddLeftLeg(doc)
                    c4d.CallCommand(12148)  #Frame Geometry
                    self.subdlg.Open(dlgtype = c4d.DLG_TYPE_ASYNC, pluginid = PLUGIN_ID, defaultw = 500, defaulth = 600)
                   
                c4d.EventAdd()

          return True

          #PluginData

          class Initialize(c4d.plugins.CommandData) :

          dialog = None

          def Init(self, op) :
                self.RestoreLayout()
                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", "CHARACTER_CREATOR.tif")
            bmp.InitWith(fn)
            print "Character Creator Loaded."
            result = plugins.RegisterCommandPlugin(PLUGIN_ID, "Character Creator", 0, bmp, "Character Creator", Initialize())

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

            On 23/05/2013 at 12:02, xxxxxxxx wrote:

            I'm currently not in the mood to read through your wall of code. You either describe the problem
            *specifically* or wait/hope for someone to dig through your code and probably get the gist of
            your problem.

            One of my favorite tips that might help you describe your problem:

            - Where exactly in your code is the problem? Provide a short snippet with the line(s) highlighted
            and a short explanation of the context.

            -Nik

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

              On 23/05/2013 at 12:17, xxxxxxxx wrote:

              Well, I want to change an objects position, but that position should be the sum of the two edit sliders (something like that). It also needs to be updated whenever a slider changes.

              def Command(self, id, msg) :     #Commands
                   
                    FOOT_Y = 4.0
                    LEG_Y = 38.0

              if (id == FOOT_Y_SLIDER) :           #Foot_Y Slider
                        FOOT_Y = self.GetReal(FOOT_Y_SLIDER)
                        #L_Leg[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_Y] = FOOT_Y/2 + LEG_Y/2
                        c4d.EventAdd()

              if (id == LEG_Y_SLIDER) :            #Leg_Y Slider
                        LEG_Y = self.GetReal(LEG_Y_SLIDER)
                        L_Leg[c4d.PRIM_CUBE_LEN, c4d.VECTOR_Y] = LEG_Y
                        #L_Leg[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_Y] = FOOT_Y/2 + LEG_Y/2
                        c4d.EventAdd()

              return True

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

                On 23/05/2013 at 12:30, xxxxxxxx wrote:

                That's better already. But where is the actual problem? The code you show looks ok. When
                you uncomment the purple lines, it should behave as expected: The object's y-position is set to
                the result of the equation FOOT_Y/2 + LEG_Y/2.

                PS: Please use the BB CODE tags or format your code accordingly so it is easier to read.

                -Nik

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

                  On 23/05/2013 at 12:43, xxxxxxxx wrote:

                  After uncommenting the code, when I change the Leg-Slider, it works fine but when I change the Foot-Slider, instead of using the new LEG_Y value, he just uses the old LEG_Y value, which I don't want to happen.

                  Greets

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

                    On 23/05/2013 at 12:49, xxxxxxxx wrote:

                    As I said, the expected behaviour. 🙂
                    You are setting LEG_Y to 4.0. If the Command() message passes the id FOOT_Y_SLIDER, you do
                    not obtain the slider value for LEG_Y, but instead use the 4.0 from above.

                    def Command(self, id, msg) :
                        # In case you also have other widgets that don't require the
                        # L_Leg object to change, use this to only update the object
                        # when necessary.
                        if id in (FOOT_Y_SLIDER, LEG_Y_SLIDER) :
                            FOOT_Y = self.GetReal(FOOT_Y_SLIDER)
                            LEG_Y = self.GetReal(LEG_Y_SLIDER)
                      
                            pos = L_Leg.GetRelPos()
                            pos.y = (FOOT_Y + LEG_Y) / 2.0
                            L_Leg.SetRelPos(pos)
                            c4d.EventAdd()
                      
                        return True
                    

                    id in (FOOT_Y_SLIDER, LEG_Y_SLIDER) is equal to id == FOOT_Y_SLIDER or id == LEG_Y_SLIDER.

                    -Nik

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

                      On 23/05/2013 at 13:07, xxxxxxxx wrote:

                      Thanx for your answers!
                      It works now 🙂

                      Greets,

                      Casimir

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post