Create Radio Button in User Data
-
Hi,
I'm creating User Data through Python and I'm able to create a dropdown list (combobox) with this:cycle = c4d.GetCustomDataTypeDefault(c4d.DTYPE_LONG) cycle[c4d.DESC_CUSTOMGUI] = c4d.CUSTOMGUI_CYCLE
But this is not what I want at all, but the old and classic radio button, as below.
I'd expect to find something like 'c4d.CUSTOMGUI_RADIOBUTTONS' in the documentation, but there is nothing even close to this.
Is it possible to be created in Python?
-
Hi @danielsian,
Here's a quote from one of our source files:
#define ID_LONGTABS_GADGET 1019603
#define ID_QUICKTABSRADIO_GADGET 200000281Unfortunately, these symbols are not exposed, so you need to use them as numbers: ID_LONGTABS_GADGET instead of c4d.CUSTOMGUI_CYCLE in your code snippet.
I gratefully modified Ferdinand's simple code snippet to show the concept. Please find it below the posting.
Cheers,
Iliaimport c4d ID_QUICKTABSRADIO_GADGET = 200000281 ID_LONGTABS_GADGET = 1019603 def CreateAttribute(id: int, name: str, values: dict[int, str]) -> c4d.BaseContainer: bc: c4d.BaseContainer = c4d.GetCustomDataTypeDefault(c4d.DTYPE_LONG) bc[c4d.DESC_NAME] = name bc[c4d.DESC_CUSTOMGUI] = id cycle: c4d.BaseContainer = c4d.BaseContainer() for key, value in values.items(): cycle[key] = value bc[c4d.DESC_CYCLE] = cycle return bc def main(): radioButtons = CreateAttribute(ID_LONGTABS_GADGET, "Attribute Foo", {0: "Baz", 1: "Qux"}) tabs = CreateAttribute(ID_QUICKTABSRADIO_GADGET, "Attribute Bar", {0: "Quz", 1: "Quuz"}) op.SetUserDataContainer(c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA), c4d.DescLevel(0)), tabs) op.SetUserDataContainer(c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA), c4d.DescLevel(1)), radioButtons) if __name__ == "__main__": main() c4d.EventAdd()
-
Awesome, thanks @i_mazlov
Very nice approach to create an User Data entry.How can I find this kind of information when it is not documented, as I suppose there are other UD options without a symbol defined?
-
Hi @danielsian,
Yes, sometimes it happens that there're some approaches or symbols that are fine to be used by plugin developers even if they are not documented well enough. If you find yourself in such situation, you have a couple of ways to follow.
The most obvious way would be to come to the forum and ask Maxon team and our community about it. It's probably the easiest way to find something out, especially when the postings follow our Support Procedures and we've already collected quite significant database of Q&A threads here on the forum, so searching for something here gives positive result in most cases.
However, there's something you can try on your own as well. For example, if you find something in Cinema4D that you cannot find documentation for, you can go ahead and make a text search in the resource folders of the cinema (%YOUR_C4D_INSTALLATION_PATH%\resource). Although this might sound a little wrong, you will be surprised how effective this approach can be in some cases. For example, I personally use Git Bash for Windows with the following command:
grep -rnw . -e "YOUR TEXT TO SEARCH"
, where you can search for some "interesting" (preferably unique) text, to reduce the amount of "false positives". This can give you some hints what to search for on our docs or on the forum. Please note: our resources are partially shipped in resource.zip file, so you might want to search there as well.The approach above can give you some directions or tokens to search for, but of course it doesn't guarantee you find something, especially if we're talking about some defines that we have in the source code and do not expose to any API. In this case, you can try searching for the information youself in cinema itself. For example, you could easily get the IDs mentioned by me above, simply by iterating over the basecontainer with the radio buttons from the python script. You could've created User Data using User Data Manager and then run the following script to see, what is exactly the c4d.DESC_CUSTOMGUI id of this userdata, e.g. with the following code snippet:
import c4d def main() -> None: for cid, bc in op.GetUserDataContainer(): print(bc[c4d.DESC_CUSTOMGUI]) if __name__ == '__main__': main()
You could've also go ahead and explore the entire basecontainer using the following script. It might give a little better overview of what's actually in there:
for cid, bc in op.GetUserDataContainer(): print(cid, bc) for key, value in bc: print(f"Key: {key}, Type: {type(value)}, Value: {value}")
Cheers,
Ilia -
@i_mazlov Thanks a lot for your time.
You answered my question brilliantly.