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

    Tips for GeDialog GUI ID Management?

    General Talk
    r21 python
    3
    4
    685
    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.
    • B
      bentraje
      last edited by

      Hi,

      I'm currently working a GeDialog that requires different elements such as edit text, combo box, button etc.
      With these elements, they each require a unique ID.

      I understand that choosing an ID is arbitrary, but may I ask if anyone has tips on how they handle this kind of thing?

      If my memory serves me right, Maya allows accessing an element not by an integer as an ID but through a string. So I never really had this problem since my string ids are descriptive as they can be.

      Is there the same functionality on C4D (i.e string ID instead of integer ID)?

      1 Reply Last reply Reply Quote 0
      • M
        mp5gosu
        last edited by

        No, not that I know of.
        But you can indeed create adapter functions for queries that convert query strings to their corresponding Int equivalent.
        I wouldn't recommend it though, because this adds another level of abstraction.

        1 Reply Last reply Reply Quote 1
        • M
          m_adam
          last edited by

          Hi, @bentraje there is nothing built-in for that.

          Just to be clear GeDialog Gadget ID should be unique only to the current GeDialog instance.
          Moreover, it's also advised to use only iD superior to 1000.

          After that, you are free to do whatever you want. The easiest way is to create a variable with a proper name that will represent this ID. And you will use this variable everywhere you need to. This way you ensure to not do a typo.

          But if you really want to go the string way here is one of the few possible ways of achieving it:

          import c4d
          
          class AutoId(object):
              
              baseId = 10000
              dct = {}
              
              def __new__(self, name, wantedId=None):
                  if name in self.dct:
                      return self.dct[name]
                  
                  if isinstance(wantedId, int):
                      self.dct[name] = wantedId
                      return self.dct[name]
          
                  self.dct[name] = self.baseId + len(self.dct)
                  return self.dct[name]
                      
          
          # Main function
          def main():
              print AutoId("Something")
              print AutoId("Something")
              print AutoId("SomethingElse")
              print AutoId("SomethingElse")
          
          # Execute main()
          if __name__=='__main__':
              main()
          

          Cheers,
          Maxime.

          MAXON SDK Specialist

          Development Blog, MAXON Registered Developer

          1 Reply Last reply Reply Quote 2
          • B
            bentraje
            last edited by

            Thanks for the response

            @mp5gosu
            Yea, this "another level of abstraction" might bite me in other sections of the code but this is the only way I can be sane for now. hehe

            @m_adam

            RE: it's also advised to use only iD superior to 1000.
            Thanks for the note.

            RE:here is one of the few possible ways
            The code works as expected. Thanks again! Should make things easier now 🙂

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