import c4d
from c4d import gui
import imp
import os
import warnings
import random
import time
warnings.filterwarnings("ignore")
dir, file = os.path.split(__file__)


count =0
stop = False
head = dir
tail = ""
stop = False
while tail != "Signal Scripts":
    count = count+1
    dir = head
    head, tail = os.path.split(head)
    if count >10:
        stop = True
        c4d.gui.MessageDialog("Error with Signal.\nPlease try to reinstall the scripts.")
        break 

try:
	api = imp.load_source('Functions.txt',os.path.join(dir,"res", "Functions.txt"))
	ID = imp.load_source('Ids.txt',os.path.join(dir,"res", "Ids.txt"))
except:
	stop = True
	c4d.gui.MessageDialog("Error with Signal.\nPlease try to reinstall the scripts.")
        

def main():
    if stop == True:
        return
    
  
    doc.StartUndo()
    random.seed(time.time())
    RandomLightTags = []
    for obj in doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN):
        if obj.GetType() == 5102: #Light
        #start here
                
          
            RandomLightTags.append(api.LoadPreset(obj,c4d.Obase,"RandomLightIntensity"))
            
            RandomLightTags.append(api.LoadPreset(obj,c4d.Obase,"RandomLightShadowDensity"))
            
            RandomLightTags.append(api.LoadPreset(obj,c4d.Obase,"RandomLightPosition"))
            
            RandomLightTags.append(api.LoadPreset(obj,c4d.Obase,"RandomLightColor"))
            
            
        
        #End here
    for tag in RandomLightTags:
        noises = api.GetTabs(tag,ID.Noise)#Gets all noise tabs     tag, then the type of tab
        for noise in noises:
            SeedId = api.GetId(tag,ID.ModNoiseSeed,noise)
            tag[SeedId] = random.randrange(0, 99999)
    doc.EndUndo()
    c4d.EventAdd()
if __name__=='__main__':
    main()
