The problem here is that Message() is called before Main() (nothing you can changed)
Hello.
Thank you so much. I've understood. Yea, it works. I'd break my mind to understand it by myself. So, then I gonna optimize drawcalls (don't know how to call it another) of LaunchUpdate() func
I get the same issue. The script gives only previous data (randint limit). I know why, but I don't know how to get an active data.
def message(id, data):
if id == c4d.MSG_DESCRIPTION_COMMAND:
randomButtons = [5] #Random buttons Ids
buttonID = data['id']
SubList = [] #container storing id's values to have to changing
SubList = randomId_new(SubList,[3,4])#filling the container
if buttonID[0].id == c4d.ID_USERDATA:#check for user data
for RandomButtonId in range (0,len(randomButtons)):#loop for each button
if buttonID[1].id == randomButtons[RandomButtonId]:#check button ID
for SublistId in range (0,len(SubList[RandomButtonId])):
RandomLimit = 0 #limit for randint
for id, bc in op.GetUserDataContainer():
if (id == c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA, c4d.DTYPE_SUBCONTAINER,0), c4d.DescLevel(SubList[RandomButtonId][SublistId]))): #check id
cycleBC = bc.GetContainer(c4d.DESC_CYCLE)
for element in cycleBC: #define len of cycleList
RandomLimit += 1
op[c4d.ID_USERDATA,SubList[RandomButtonId][SublistId]] = randint(0,RandomLimit - 1) #generate random value
print(str(SubList[RandomButtonId][SublistId]) + ': ' + str(RandomLimit)) #checking to console
What do you mean with "hierarhy disturbing"? What do you mean with "generate active object after generating random"?
"Hierarhy disturbing".
Simply put, there is first func (where there are object details) and there is the second func which generate a random number, but data of active object stores in the first func. Need to execute the second func before first to make it works. But it doesn't right cause' it disturbs actions timeline. Right way is: First display object to the viewport, then generate random nimber after pressing button. But this code requires to run second func before first one.
"generate active object after generating random"
I think attached video link better speaks for me.
Hello everyone.
There are a few classes.
One for choosing an object in the CycleList.
Two for choosing a random object via change c4d.userdata value
One works fine. But when I choose a random object I need to click on the viewport to update showing object. How to update viewport without clicking?
if (config['hideState'] == True): #hide selected object
for indexObjectHide in range (0, limit): #loop for geting all objects
if (indexObjectHide == self.userdataGroup[c4d.ID_USERDATA,userDataId]): #which object is selected
self.parentObject.GetChildren()[indexObjectHide].SetEditorMode(2)
self.parentObject.GetChildren()[indexObjectHide].SetRenderMode(2)
else:
self.parentObject.GetChildren()[indexObjectHide].SetEditorMode(1)
self.parentObject.GetChildren()[indexObjectHide].SetRenderMode(1)
Random class:
if (self.userdataGroup[c4d.ID_USERDATA,userDataId] == True): #If random button clicked
SubLists = [] #
for ListIndex in range (0,len(config['Random id'])):#config['Random id'] is var where I can point userdata ids ehich will be randomed
SubLists.append([config['Random id'][ListIndex]])
indexList = []
for indexEl in range (0,len(SubLists)): #Loop for each id
for id, bc in self.userdataGroup.GetUserDataContainer():
cycleBC = bc.GetContainer(c4d.DESC_CYCLE)
if (id == c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA, c4d.DTYPE_SUBCONTAINER,0), c4d.DescLevel(SubLists[indexEl][0]))):
for element in cycleBC: # get userdata data
if (len(indexList) == indexEl):
indexList.append([element[0]])
else:
indexList[indexEl].append(element[0])
self.userdataGroup[c4d.ID_USERDATA,SubLists[indexEl][0]] = randint(0,len(indexList[indexEl]) - 1) #Change userdata values
self.userdataGroup[c4d.ID_USERDATA,userDataId] = False
You can see full code in the attached c4d file. Pls help me
For better understanding what I want, watch the video:
Experieces.c4d
/////
Seems I've understood why I get the issue. I put random class before object class and it works 'cause in this code, I get an active object before getting random value. But it is doesn't correct in point of view of the code. It's hierarhy disturbing. Ways to generate active object after generating random?