|
|
|
Tell us what you think of the site.
|
Autodesk Media & Entertainment User Community
|
Autodesk® 3ds Max®
|
|
Autodesk® Maya®
|
|
Autodesk® Softimage®
|
|
Autodesk® MotionBuilder®
|
|
Autodesk® Mudbox™
|
|
Autodesk® ImageModeler™
|
|
Autodesk® Sketchbook® Pro
|
|
Autodesk® Smoke on Mac®
|
| Python Script - Selection of Multiple Objects
|
|
|
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.
|
|
|
|
One way would be to put the flakes in an XSICollection as you create them.
|
|
|
|
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.
|
|
|
|
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)
|
|
|
|
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.
|
|
|
|
|
|