Tips for GeDialog GUI ID Management?
-
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)?
-
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. -
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. -
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. heheRE: 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