[codesyntax lang=”python”]
#****************************************************** # Spray an EcoSystem onto an object # # - ecospray.py # - By Mark Caldwell # - Version 0.1 # - 15th September 2006 # - Tested with Vue 5 Infinite 5.10 and Vue 6 Infinite Pre Release # - http://www.impworks.co.uk/ # # How to use in 3 easy steps # # 1. Download this file onto your computer # # 3. Select an object with a populated EcoSystem applied # # 4. Then run script and enter values when asked # To run it go to Python -> Run Python Script # Then locate the file on your computer # #****************************************************** #-------------------------------------------- # Get Input and Test Value for values 0-10000 #-------------------------------------------- def TestVal (messagetxt,titletxt,default): hit=-2 val=-1 while hit<0: try: if int(val) in range (0,10000): hit=1; elif hit==-2: val=Prompt (messagetxt,default,true,titletxt) hit=-1 else: val=Prompt ("Error: Value must be an integer between 0 and 10000\n\n"+messagetxt,val,true,titletxt) except: hit=-1 val=Prompt ("Error: Value must be an integer between 0 and 10000\n\n"+messagetxt,val,true,titletxt) return val #-------------------------------------------- # Set up Random Numbers #-------------------------------------------- import random ran = random.Random() #---------------------------------------------- # Configuration: Get User Input #---------------------------------------------- number_instances=TestVal ('Maximum Number of Instances to use (0-10000)','Select Maximum Instance','0') #-------------------------------------------------------------------------- # Main #-------------------------------------------------------------------------- if TestLoaded(): # Test user has a scene loaded #-------------------------------------------------------------------------- # Test the user has 1 object selected with an Eco System on it #-------------------------------------------------------------------------- numselected=CountSelectedObjects() if numselected>1: message="Please select only one object." elif numselected<1: message="Please select an object." else: #-------------------------------------------------------------------------- #Set Up a Few Variables #-------------------------------------------------------------------------- obj=GetSelectedObjectByIndex(0) # Get selected object mat=obj.Material(0) # Get material on selected object Eco = GetEcosystemOnObject(obj) # Get EcoSystem on first selected if Eco==None: # Check object has an EcoSystem Material message="Please select an object with an EcoSystem material applied to it." elif obj.IsLocked(): # Check object isn't locked message="Please select an object that isn't locked." else: #-------------------------------------------------------------------------------- # Find out how many different objects can be used as instances for this EcoSystem #-------------------------------------------------------------------------------- newinst=0 instcount=0 while newinst==0: ret=Eco.AddInstance(instcount) if ret==-1: newinst=1 else: instcount=instcount+1 instcount=instcount-1 #-------------------------------------------------------------------------- # Coat #-------------------------------------------------------------------------- Eco.ClearInstances () # Clear all instances from Eco obj2=AddCube() obj2.Resize(0.1) pos=obj.Position() rot=obj.GetRotationAngles() obj.SetPivotPosition((pos[0]),(pos[1]),(pos[2])) obj2.SetPivotPosition((pos[0]),(pos[1]),(pos[2])) # Now apply instances for i in range(0,int(number_instances)): x=random.uniform(0,360) y=random.uniform(0,360) z=random.uniform(0,360) obj2.SetPosition(pos[0],pos[1],(pos[2]+1100)) obj.Rotate(x,y,z) hitobj=GetFirstHitObject ((pos[0],pos[1],(pos[2]+1000)),(0,0,-1)) SelectOnly(hitobj) if obj.IsSelected(): SelectOnly(obj2) Drop() pos2=obj2.Position() instno=random.randint(0,instcount) inst=Eco.AddInstance(instno) Eco.SetInstancePosition (inst,pos2[0],pos2[1],pos2[2]) obj.SetRotationAngles(rot[0],rot[1],rot[2]) SelectOnly(obj2) Delete() message="Coating Completed. "+str(Eco.GetInstanceCount () )+" instances used." else: message="No Scene Loaded" Message(message) # Display message #-------------------------------------------------------------------------- # End of Script #--------------------------------------------------------------------------
[/codesyntax]