[codesyntax lang=”python”]
#*********************************************************************** # Set all instances in an EcoSystem to point in a given direction # - EcoRotate.py # - # - By Mark Caldwell # - Version 0.2 # - 25th August 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 for value 0-360 for Angles #---------------------------------------------------- def TestValAngle (messagetxt,titletxt,default): hit=-2 val=-1 while hit<0: try: if int(val) in range (0,360): 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 360\n\n"+messagetxt,val,true,titletxt) except: hit=-1 val=Prompt ("Error: Value must be an integer between 0 and 360\n\n"+messagetxt,val,true,titletxt) return float(val) #-------------------------------------------- # Get Input and Test Value for valuse 0 or 1 #-------------------------------------------- def TestValZO (messagetxt,titletxt,default): hit=-2 val=-1 while hit<0: try: if int(val) in range (0,2): hit=1; elif hit==-2: val=Prompt (messagetxt,default,true,titletxt) hit=-1 else: val=Prompt ("Error: Value must be either 0 or 1\n\n"+messagetxt,val,true,titletxt) except: hit=-1 val=-3 return 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 #-------------------------------------------------------------------------- xon=TestValZO ('Rotate on X axis? (Enter 0 for yes and 1 for no)','Rotate on X?','0') if xon=="1": rx=TestValAngle ('Rotate to X (0 to 360 degrees)','X Rotation','0') rxv=TestValAngle ('Variation of Rotation to X (0 to 360 degrees)','X Rotation Variation','0') yon=TestValZO ('Rotate on Y axis? (Enter 0 for yes and 1 for no)','Rotate on Y?','0') # Rotate y (set to 1 to change 0 to leave alone) if yon=="1": ry=TestValAngle ('Rotate to Y (0 to 360 degrees)','Y Rotation','0') ryv=TestValAngle ('Variation of Rotation to Y (0 to 360 degrees)','Y Rotation Variation','0') zon=TestValZO ('Rotate on Z axis? (Enter 0 for yes and 1 for no)','Rotate on Z?','0') # Rotate z (set to 1 to change 0 to leave alone) if zon=="1": rz=TestValAngle ('Rotate to Z (0 to 360 degrees)','Z Rotation','0') rzv=TestValAngle ('Variation of Rotation to Z (0 to 360 degrees)','Z Rotation Variation','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): currentrotation=Eco.GetInstanceRotation (i) if xon!="1": rix=currentrotation[0] else: rix=rx+random.uniform(-rxv,rxv) if yon!="1": riy=currentrotation[1] else: riy=ry+random.uniform(-ryv,ryv) if zon!="1": riz=currentrotation[2] else: riz=rz+random.uniform(-rzv,rzv) Eco.SetInstanceRotation(i,rix,riy,riz) message="Eco Rotation Success" else: message="No Scene Loaded" Message(message) # Display message #-------------------------------------------------------------------------- # End of Script #------------------------------------------------------------------------
[/codesyntax]