[codesyntax lang=”python”]
#*********************************************************************** # Set all instances in an EcoSystem to have random heights # - EcoVerticalScatter.py # - # - By Mark Caldwell # - Version 0.1 # - 5th September 2007 # - Checked with Vue 6.5 Infinite # # How to use in 4 easy steps # 1. Select an object with a populated EcoSystem # # 2. Run this script # # 3. Enter the values requested by the script # # 4. Wait for the script to work # #*********************************************************************** #------------------------------------------------------ # Get Input and Test Value is a positive floating point #------------------------------------------------------ def TestVal (messagetxt,titletxt,default): hit=-2 val=-1 while hit<0: try: if float(val)>=0: hit=1; elif hit==-2: val=Prompt (messagetxt,default,true,titletxt) hit=-1 else: val=Prompt ("Error: Value must an positive number\n\n"+messagetxt,val,true,titletxt) except: hit=-1 val=Prompt ("Error: Value must an positive number\n\n"+messagetxt,val,true,titletxt) return float(val) #-------------------------------------------- # Start of Main Code #-------------------------------------------- import random #-------------------------------------------------------------------------- # Test the user has a scene loaded #-------------------------------------------------------------------------- if TestLoaded(): #-------------------------------------------------------------------------- # 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: #-------------------------------------------------------------------------- # Get User values for rotation required, which to rotate and randomness #-------------------------------------------------------------------------- heightup=TestVal ('Maximum Z Increase','Maximum Z Increase','100')# heightdown=TestVal ('Maximum Z Decrease','Maximum Z Decrease','0') #-------------------------------------------------------------------------- #Set Up a Few Variables #-------------------------------------------------------------------------- bObject=GetSelectedObjectByIndex(0) # Get first selected object Eco = GetEcosystemOnObject(bObject) # Get EcoSystem on first selected objlist=[bObject] if Eco==None: message="Please select an object with an EcoSystem material applied to it." elif bObject.IsLocked(): # Check object isn't locked message="Please select an object that isn't locked." else: ecocount=Eco.GetInstanceCount () # Count number of instances in EcoSystem if ecocount==0: message="Please select an EcoSystem that has been populated." else: #-------------------------------------------------------------------------- # Rotate EcoObjects #-------------------------------------------------------------------------- for i in range(0,ecocount): currentposition=Eco.GetInstancePosition (i) x=currentposition[0] y=currentposition[1] z=currentposition[2]+random.uniform((-heightdown),heightup) Eco.SetInstancePosition(i,x,y,z) message="Eco Vertical Scatter Complete" else: message="No Scene Loaded" Refresh() Message(message) # Display message #-------------------------------------------------------------------------- # End of Script #------------------------------------------------------------------------
[/codesyntax]