impworks Logo - a grinning imp in flight

EcoSystem Vertical Scatter

This python script vertically scatters the objects in a Vue EcoSystem by a random amount and works with Vue Infinite and xStream.

This script has been superseeded by Vue features and is provided as a code example of working with EcoSystems through python.

  1. #***********************************************************************
  2. # Set all instances in an EcoSystem to have random heights
  3. # - EcoVerticalScatter.py
  4. # -
  5. # - By Mark Caldwell
  6. # - Version 0.1
  7. # - 5th September 2007
  8. # - Checked with Vue 6.5 Infinite
  9. #
  10. # How to use in 4 easy steps
  11. # 1. Select an object with a populated EcoSystem
  12. #
  13. # 2. Run this script
  14. #
  15. # 3. Enter the values requested by the script
  16. #
  17. # 4. Wait for the script to work
  18. #
  19. #***********************************************************************
  20. #------------------------------------------------------
  21. # Get Input and Test Value is a positive floating point
  22. #------------------------------------------------------
  23.  
  24. def TestVal (messagetxt,titletxt,default):
  25. hit=-2
  26. val=-1
  27.  
  28. while hit<0:
  29. try:
  30. if float(val)>=0:
  31. hit=1;
  32. elif hit==-2:
  33. val=Prompt (messagetxt,default,true,titletxt)
  34. hit=-1
  35. else:
  36. val=Prompt ("Error: Value must an positive number\n\n"+messagetxt,val,true,titletxt)
  37. except:
  38. hit=-1
  39. val=Prompt ("Error: Value must an positive number\n\n"+messagetxt,val,true,titletxt)
  40.  
  41. return float(val)
  42.  
  43. #--------------------------------------------
  44. # Start of Main Code
  45. #--------------------------------------------
  46.  
  47. import random
  48.  
  49. #--------------------------------------------------------------------------
  50. # Test the user has a scene loaded
  51. #--------------------------------------------------------------------------
  52.  
  53. if TestLoaded():
  54.  
  55. #--------------------------------------------------------------------------
  56. # Test the user has 1 object selected with an Eco System on it
  57. #--------------------------------------------------------------------------
  58.  
  59. numselected=CountSelectedObjects()
  60.  
  61. if numselected>1:
  62. message="Please select only one object."
  63. elif numselected<1:
  64. message="Please select an object."
  65. else:
  66.  
  67. #--------------------------------------------------------------------------
  68. # Get User values for rotation required, which to rotate and randomness
  69. #--------------------------------------------------------------------------
  70.  
  71. heightup=TestVal ('Maximum Z Increase','Maximum Z Increase','100')#
  72. heightdown=TestVal ('Maximum Z Decrease','Maximum Z Decrease','0')
  73.  
  74. #--------------------------------------------------------------------------
  75. #Set Up a Few Variables
  76. #--------------------------------------------------------------------------
  77.  
  78. bObject=GetSelectedObjectByIndex(0) # Get first selected object
  79. Eco = GetEcosystemOnObject(bObject) # Get EcoSystem on first selected
  80.  
  81. objlist=[bObject]
  82.  
  83. if Eco==None:
  84. message="Please select an object with an EcoSystem material applied to it."
  85. elif bObject.IsLocked(): # Check object isn't locked
  86. message="Please select an object that isn't locked."
  87. else:
  88. ecocount=Eco.GetInstanceCount () # Count number of instances in EcoSystem
  89.  
  90. if ecocount==0:
  91. message="Please select an EcoSystem that has been populated."
  92. else:
  93.  
  94. #--------------------------------------------------------------------------
  95. # Rotate EcoObjects
  96. #--------------------------------------------------------------------------
  97.  
  98. for i in range(0,ecocount):
  99. currentposition=Eco.GetInstancePosition (i)
  100.  
  101. x=currentposition[0]
  102. y=currentposition[1]
  103. z=currentposition[2]+random.uniform((-heightdown),heightup)
  104.  
  105. Eco.SetInstancePosition(i,x,y,z)
  106.  
  107. message="Eco Vertical Scatter Complete"
  108. else:
  109. message="No Scene Loaded"
  110.  
  111. Refresh()
  112.  
  113. Message(message) # Display message
  114.  
  115. #--------------------------------------------------------------------------
  116. # End of Script
  117. #------------------------------------------------------------------------

impworks © Copyright Mark Caldwell 1996 - 2017