Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® Softimage® / XSI SDK / Python Script - Selection of Multiple Objects
  RSS 2.0 ATOM  

Python Script - Selection of Multiple Objects
Rate this thread
 
30140
 
Permlink of this thread  
avatar
  • smshaler
  • Posted: 04 December 2008 04:31 AM
  • Total Posts: 16
  • Joined: 29 May 2008 07:26 PM

I am creating multiple objects within a script
while i < N:
flake=Application.ActiveSceneRoot.addGeometry(’cube’,’MeshSurface’)
flake.SclX = 4 + random()
flake.PosY = random() * 30.

How can I select all N cubes?  Using the SelectAll command is too inclusive.

After selection of the N objects, they are turned into Rigid Bodies using

Application.CreateActiveRigidBody(” list of selected geometries “)

I want to be able to write this succiently as for large N typing “cube, cube1, cube2, ...” is not viable. It seems I should be able to reference flake in some fashion, but haven’t figured it out yet.

Thanks for any solutions or suggestions.



Replies: 0
avatar

One way would be to put the flakes in an XSICollection as you create them.



Replies: 0
avatar
  • ThE_JacO
  • Posted: 04 December 2008 09:22 AM

as Stephen says, collect them inside the loop.
Create a list before the loop like aFlakes = []
and inside the loop use aFlakes.append(flake) and you’ll be good.
Or use a collection instead of the list if you want.

Better again for speed though would be adding all those things to a model rather than under the root, and then after the loop collet all model’s siblings and pass them to the RBD create.



Replies: 0
avatar
  • smshaler
  • Posted: 09 December 2008 06:20 AM

Thanks Jaco! The .append works great. I’ll look at speed issues soon enough..

Below is a snippet of the Python code for anyone interested..

aflakes=[]
i=0
NUMFLAKES = 20
while i < NUMFLAKES:
oflake = Application.CreatePrim("Cube”,"MeshSurface")
oflake.SclX = 4 + random()
.
.
.
oflake.RotX = random()*12
aflakes.append(oflake)
i += 1
Application.CreateActiveRigidBody(aflakes)



Replies: 0
avatar
  • ThE_JacO
  • Posted: 09 December 2008 09:26 AM

btw in python you don’t need to increment manually like that.
Instead of while < and managing the iterator yourself (which is also slightly dangerous if at some point something happens to the iterator while you prototype), you can do:
for i in range(20):

Also, forum wise, if you post code remember code tags, they are pretty useful.
Same as quote, but you use {code}, {/code} with square brackets instead, and it will preserve formatting and all that stuff and come up in a monospaced font.



Replies: 0