EcoSystem to Objects

This is a python script that will place a cube at the same location as each instance in an EcoSystem. It gives each cube the same rotation as the instance. It also scales it by the same scale factor in each direction as the instance. There is an additional parameter to allow the scaling to be modified to give better results. A second parameter limits the number of instances that will have objects created for them as the script can crash Vue if large numbers of objects are created. You can increase this number if your computer can cope with larger numbers of objects.

An enhanced version developed for Vue 6 using Vue 6 Pre Release is also included in the zip file. It includes a simple interface so you don’t need to edit the script. It place any of the standard Vue primitive solids at the position of each instance of an object in an ecosystem. You can optionally group or create a metablob from the objects.

These scripts have been supperseeded by the addition of a better feature to do this in Vue itself I’ve left them here as examples of what can be achieved in Vue using Python.

  1. #******************************************************
  2. # Place an object at the position of each instance
  3. # in an ecosystem
  4. #
  5. # - ecotoobject.py
  6. # - By Mark Caldwell
  7. # - Version 0.4
  8. # - 24th April 2007
  9. # - Tested with Vue 6 Infinite
  10. #
  11. # How to use in 4 easy steps
  12. #
  13. # 1. Download this file onto your computer
  14. #
  15. # 2. Select an object with a populated EcoSystem applied
  16. #
  17. # 3. Then run script
  18. # To run it go to Python -> Run Python Script
  19. # Then locate the file on your computer
  20. #
  21. # 4. Respond to the scripts options and then wait for
  22. # it to work
  23. #
  24. #******************************************************
  25.  
  26. #----------------------------------------------
  27. # Collect the user's input
  28. #----------------------------------------------
  29.  
  30. group=Prompt('Group Objects?\n 1: Group\n 2: Metablob \n3: No','1',true,'')
  31.  
  32. form=Prompt('Object Type?\n 1: Cube\n 2: Sphere \n3: Cylinder \n4: Pyramid\n5: Cone\n 6: Torus','1',true,'')
  33.  
  34. maximum_objects=int(Prompt('Maximum number of objects to create?','1000',true,''))
  35.  
  36. scale_factor=float(Prompt('Scale Factor for Objects','0.1',true,''))
  37.  
  38. #--------------------------------------------------------------------------
  39. # Test the user has a scene loaded
  40. #--------------------------------------------------------------------------
  41.  
  42. if TestLoaded():
  43.  
  44. #--------------------------------------------------------------------------
  45. # Test the user has 1 object selected with an Eco System on it
  46. #--------------------------------------------------------------------------
  47.  
  48. numselected=CountSelectedObjects()
  49.  
  50. if numselected>1:
  51. message="Please select only one object."
  52. elif numselected<1:
  53. message="Please select an object."
  54. else:
  55.  
  56. #--------------------------------------------------------------------------
  57. #Set Up a Few Variables
  58. #--------------------------------------------------------------------------
  59.  
  60. bObject=GetSelectedObjectByIndex(0) # Get first selected object
  61. Eco = GetEcosystemOnObject(bObject) # Get EcoSystem on first selected
  62.  
  63. if Eco==None:
  64. message="Please select an object with an EcoSystem material applied to it."
  65. elif bObject.IsLocked(): # Check object isn't locked
  66. message="Please select an object that isn't locked."
  67. else:
  68. ecocount=Eco.GetInstanceCount () # Count number of instances in EcoSystem
  69.  
  70. if ecocount>maximum_objects: # If this is greater than maximum_objects restrict it to maximum objects
  71. ecocount=maximum_objects
  72.  
  73. if ecocount==0:
  74. message="Please select an EcoSystem that has been populated."
  75. else:
  76.  
  77. #--------------------------------------------------------------------------
  78. # Create Objects
  79. #--------------------------------------------------------------------------
  80.  
  81. for i in range(0,ecocount):
  82. pos=Eco.GetInstancePosition (i) # Get instance position
  83. rot=Eco.GetInstanceRotation (i) # Get instance rotation
  84. sca=Eco.GetInstanceScale (i) # Get instance scale
  85.  
  86. if form=='2':
  87. obj=AddSphere()
  88. elif form=='3':
  89. obj=AddCylinder()
  90. elif form=='4':
  91. obj=AddPyramid()
  92. elif form=='5':
  93. obj=AddCone()
  94. elif form=='6':
  95. obj=AddTorus()
  96. else:
  97. obj=AddCube() # Create Object
  98. obj.SetPosition(pos[0],pos[1],pos[2]) # Set object's position
  99. obj.Rotate(rot[0],rot[1],rot[2]) # Set object's rotation
  100. obj.ResizeAxis(sca[0]*scale_factor,sca[1]*scale_factor,sca[2]*scale_factor) # Set object's size
  101.  
  102. if group=='1' or group=='2':
  103. if i>0:
  104. obj.SetName(name)
  105. else:
  106. name=obj.Name()
  107.  
  108. DeselectAll()
  109.  
  110. if group=='1':
  111. SelectByName(name)
  112. Group()
  113. elif group=='2':
  114. SelectByName(name)
  115. MetaBlob()
  116.  
  117. DeselectAll()
  118. Select(bObject)
  119.  
  120. message="Eco to Object Successful"
  121. else:
  122. message="No Scene Loaded"
  123.  
  124. Message(message) # Display message
  125.  
  126. #--------------------------------------------------------------------------
  127. # End of Script
  128. #--------------------------------------------------------------------------

Python Code – ecotoobject.py

  1. #******************************************************
  2. # Place a cube at the position of each instance of an
  3. # object in an ecosystem
  4. #
  5. # - ecotoobject.py
  6. # - By Mark Caldwell
  7. # - Version 0.1
  8. # - 29th June 2006
  9. # - Tested with Vue 5 Infinite 5.10 and Vue 6 Pre Release
  10. #
  11. # How to use in 4 easy steps
  12. #
  13. # 1. Download this file onto your computer
  14. #
  15. # 2. Edit the configuration variable maximum_objects below
  16. # if you want to risk more that 1000 objects
  17. #
  18. # 3. Select an object with a populated EcoSystem applied
  19. #
  20. # 4. Then run script and wait for it to work
  21. # To run it go to Python -> Run Python Script
  22. # Then locate the file on your computer
  23. #
  24. #******************************************************
  25.  
  26. #----------------------------------------------
  27. # Configuration: Set these to alter end result
  28. #----------------------------------------------
  29.  
  30. maximum_objects=1000 # maximum_objects sets the maximum number of instances that the script will replace with objects
  31. # this stops it running away and crashing Vue by trying to add 1 million cubes
  32.  
  33. #--------------------------------------------------------------------------
  34. # Test the user has a scene loaded
  35. #--------------------------------------------------------------------------
  36.  
  37. if TestLoaded():
  38.  
  39. #--------------------------------------------------------------------------
  40. # Test the user has 1 object selected with an Eco System on it
  41. #--------------------------------------------------------------------------
  42.  
  43. numselected=CountSelectedObjects()
  44.  
  45. if numselected>1:
  46. message="Please select only one object."
  47. elif numselected<1:
  48. message="Please select an object."
  49. else:
  50.  
  51. #--------------------------------------------------------------------------
  52. #Set Up a Few Variables
  53. #--------------------------------------------------------------------------
  54.  
  55. bObject=GetSelectedObjectByIndex(0) # Get first selected object
  56. Eco = GetEcosystemOnObject(bObject) # Get EcoSystem on first selected
  57.  
  58. objlist=[bObject]
  59.  
  60. if Eco==None:
  61. message="Please select an object with an EcoSystem material applied to it."
  62. elif bObject.IsLocked(): # Check object isn't locked
  63. message="Please select an object that isn't locked."
  64. else:
  65. ecocount=Eco.GetInstanceCount () # Count number of instances in EcoSystem
  66.  
  67. if ecocount>maximum_objects: # If this is greater than maximum_objects restrict it to maximum objects
  68. ecocount=maximum_objects
  69.  
  70. if ecocount==0:
  71. message="Please select an EcoSystem that has been populated."
  72. else:
  73.  
  74. #--------------------------------------------------------------------------
  75. # Create Objects
  76. #--------------------------------------------------------------------------
  77.  
  78. for i in range(0,ecocount):
  79. pos=Eco.GetInstancePosition (i) # Get instance position
  80. rot=Eco.GetInstanceRotation (i) # Get instance rotation
  81. sca=Eco.GetInstanceScale (i) # Get instance scale
  82. object=AddCube() # Create Object
  83. object.SetPosition(pos[0],pos[1],pos[2]) # Set object's position
  84. object.Rotate(rot[0],rot[1],rot[2]) # Set object's rotation
  85. object.ResizeAxis(sca[0],sca[1],sca[2]) # Set object's size
  86.  
  87. message="Eco to Object Successful"
  88. else:
  89. message="No Scene Loaded"
  90.  
  91. Message(message) # Display message
  92.  
  93. #--------------------------------------------------------------------------
  94. # End of Script
  95. #--------------------------------------------------------------------------

impworks © Copyright Mark Caldwell 1996 - 2017