Eco Spray

This python script coats the outside of an object with an EcoSystem. It won’t cover all faces because of the way it works. It will cover a sphere, cube, cone but won’t cover all of a torus.

  1. #******************************************************
  2. # Spray an EcoSystem onto an object
  3. #
  4. # - ecospray.py
  5. # - By Mark Caldwell
  6. # - Version 0.1
  7. # - 15th September 2006
  8. # - Tested with Vue 5 Infinite 5.10 and Vue 6 Infinite Pre Release
  9. # - http://www.impworks.co.uk/
  10. #
  11. # How to use in 3 easy steps
  12. #
  13. # 1. Download this file onto your computer
  14. #
  15. # 3. Select an object with a populated EcoSystem applied
  16. #
  17. # 4. Then run script and enter values when asked
  18. # To run it go to Python -> Run Python Script
  19. # Then locate the file on your computer
  20. #
  21. #******************************************************
  22.  
  23. #--------------------------------------------
  24. # Get Input and Test Value for values 0-10000
  25. #--------------------------------------------
  26.  
  27. def TestVal (messagetxt,titletxt,default):
  28. hit=-2
  29. val=-1
  30.  
  31. while hit<0:
  32. try:
  33. if int(val) in range (0,10000):
  34. hit=1;
  35. elif hit==-2:
  36. val=Prompt (messagetxt,default,true,titletxt)
  37. hit=-1
  38. else:
  39. val=Prompt ("Error: Value must be an integer between 0 and 10000\n\n"+messagetxt,val,true,titletxt)
  40. except:
  41. hit=-1
  42. val=Prompt ("Error: Value must be an integer between 0 and 10000\n\n"+messagetxt,val,true,titletxt)
  43.  
  44. return val
  45.  
  46. #--------------------------------------------
  47. # Set up Random Numbers
  48. #--------------------------------------------
  49.  
  50. import random
  51. ran = random.Random()
  52.  
  53. #----------------------------------------------
  54. # Configuration: Get User Input
  55. #----------------------------------------------
  56.  
  57. number_instances=TestVal ('Maximum Number of Instances to use (0-10000)','Select Maximum Instance','0')
  58.  
  59. #--------------------------------------------------------------------------
  60. # Main
  61. #--------------------------------------------------------------------------
  62.  
  63. if TestLoaded(): # Test user has a scene loaded
  64.  
  65. #--------------------------------------------------------------------------
  66. # Test the user has 1 object selected with an Eco System on it
  67. #--------------------------------------------------------------------------
  68.  
  69. numselected=CountSelectedObjects()
  70.  
  71. if numselected>1:
  72. message="Please select only one object."
  73. elif numselected<1:
  74. message="Please select an object."
  75. else:
  76.  
  77. #--------------------------------------------------------------------------
  78. #Set Up a Few Variables
  79. #--------------------------------------------------------------------------
  80.  
  81. obj=GetSelectedObjectByIndex(0) # Get selected object
  82. mat=obj.Material(0) # Get material on selected object
  83. Eco = GetEcosystemOnObject(obj) # Get EcoSystem on first selected
  84.  
  85. if Eco==None: # Check object has an EcoSystem Material
  86. message="Please select an object with an EcoSystem material applied to it."
  87. elif obj.IsLocked(): # Check object isn't locked
  88. message="Please select an object that isn't locked."
  89. else:
  90.  
  91. #--------------------------------------------------------------------------------
  92. # Find out how many different objects can be used as instances for this EcoSystem
  93. #--------------------------------------------------------------------------------
  94.  
  95. newinst=0
  96. instcount=0
  97. while newinst==0:
  98. ret=Eco.AddInstance(instcount)
  99. if ret==-1:
  100. newinst=1
  101. else:
  102. instcount=instcount+1
  103. instcount=instcount-1
  104.  
  105. #--------------------------------------------------------------------------
  106. # Coat
  107. #--------------------------------------------------------------------------
  108.  
  109. Eco.ClearInstances () # Clear all instances from Eco
  110. obj2=AddCube()
  111. obj2.Resize(0.1)
  112. pos=obj.Position()
  113. rot=obj.GetRotationAngles()
  114. obj.SetPivotPosition((pos[0]),(pos[1]),(pos[2]))
  115. obj2.SetPivotPosition((pos[0]),(pos[1]),(pos[2]))
  116.  
  117. # Now apply instances
  118.  
  119. for i in range(0,int(number_instances)):
  120. x=random.uniform(0,360)
  121. y=random.uniform(0,360)
  122. z=random.uniform(0,360)
  123. obj2.SetPosition(pos[0],pos[1],(pos[2]+1100))
  124. obj.Rotate(x,y,z)
  125. hitobj=GetFirstHitObject ((pos[0],pos[1],(pos[2]+1000)),(0,0,-1))
  126. SelectOnly(hitobj)
  127. if obj.IsSelected():
  128. SelectOnly(obj2)
  129. Drop()
  130. pos2=obj2.Position()
  131. instno=random.randint(0,instcount)
  132. inst=Eco.AddInstance(instno)
  133. Eco.SetInstancePosition (inst,pos2[0],pos2[1],pos2[2])
  134. obj.SetRotationAngles(rot[0],rot[1],rot[2])
  135. SelectOnly(obj2)
  136. Delete()
  137.  
  138. message="Coating Completed. "+str(Eco.GetInstanceCount () )+" instances used."
  139.  
  140. else:
  141. message="No Scene Loaded"
  142.  
  143. Message(message) # Display message
  144.  
  145. #--------------------------------------------------------------------------
  146. # End of Script
  147. #--------------------------------------------------------------------------

impworks © Copyright Mark Caldwell 1996 - 2017