I have a problem with filling a dropdown cycle dynamically with options. Right now I’m doing this with userdata for the sake of simplicity. But in the end I want to use it in a Tag Plugin…
So, the setup is as follows. I have a cube (just to have a dummy host object to test the code with) that holds a python tag. The python tag holds the userdata dropdown cycle with the options I want to choose from. Inside the code I swap out the entries of the dropdown cycle based on the condition whether the fillet switch of the cube is active.
So the endgame here is to react to changes of the host object.
While this is all nice and dandy I encounter a problem I can’t seem to resolve. When ever I switch the fillet of the cube the dropdown cycle entries are changed accordingly BUT after the switch the dropdown cycle somehow seems to remember the last selected index and tries to set an entry with this remembered index as the "selected" one. This obviously fails if the entries being switched are of different length. So the entries are there but the dropdown cycle appears so to speak blank.
So question here is, how can I tell the dropdown cycle after the switch to select from the "new" indices. I’m probably missing something simple here.
import c4d #Welcome to the world of Python def main(): options1 = [ "Option 1", "Option 2" ] options2 = [ "Option 1", "Option 2", "Option 3", "Option 4" ] cube = op.GetObject() fillet = cube[c4d.PRIM_CUBE_DOFILLET] bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_LONG) bc.SetString(c4d.DESC_NAME, "Options") bc.SetInt32(c4d.DESC_CUSTOMGUI, c4d.CUSTOMGUI_CYCLE) cycle = c4d.BaseContainer() if not fillet: for i, option in enumerate(options1): cycle.SetString(i, option) else: for i, option in enumerate(options2): cycle.SetString(i, option) bc.SetContainer(c4d.DESC_CYCLE, cycle) op.SetUserDataContainer([c4d.ID_USERDATA, 1], bc) print op[c4d.ID_USERDATA,1]