Python for 3ds max – list scene objects

Software:
3ds max 2019

Iterating through a list of all of an object’s hierarchy or all of the objects in the scene is a very common requirement for scripted tools and utilities in 3D animation software.
Coming from a MaxScript background, I was used to just have to write the word ‘objects‘ to reference a list of all of the objects in the scene.

Unless I’m missing something obvious,
There isn’t a shortcut like this available in the 3ds max Python API.

In order to list all the objects in the scene you need to use a recursive function that will return a list of all of a node’s children, and children’s children, etc.

In the following example, the function ‘list_children()’ will return a list all of the objects in the supplied node’s hierarchy, and when given the scene’s root node via MaxPlus.Core.GetRootNode() it will return a list of all the objects in the scene.
Wrapping ‘list_children()’ within the ‘scene_objects()’ function, provides a convenient way get a list of all the objects in the scene just by calling ‘scene_objects()’.

def scene_objects():
    def list_children(node):
       list = []
       for c in node.Children:
           list.append(c)
           list = list + list_children(c)
       return list
    return list_children(MaxPlus.Core.GetRootNode())


for o in scene_objects():
    print o.Name

* note that when copying and pasting a script from this example, the indentation may not be pasted correctly.

Advertisements

Python for 3ds max – Create Objects

Software:
3ds Max 2019

Untitled-1.jpg

from MaxPlus import ClassIds
from MaxPlus import Point3
import random

# Define Sphere geometry object:
sphere_obj = Factory.CreateGeomObject(ClassIds.Sphere)
sphere_obj.ParameterBlock.Radius.Value = 5
sphere_obj.ParameterBlock.Segs.Value = 64

# Create a list of 10 sphere instanced objects:
spheres = []
for i in range(10):
    spheres.append(Factory.CreateNode(sphere_obj))

# Move spheres to random positions
for s in spheres:
    s.SetLocalPosition(Point3( random.randint(-50,50),
                               random.randint(-50,50),
                               random.randint(-50,50)))
    scale = 5.0 * (random.randint(30,100)/100.0)
    s.SetLocalScale(Point3(scale,scale,scale))

* note that when copying and pasting a script from this example, the indentation may not be pasted correctly.

Blender Python – Make an unselectable object local so it can be selected..

Software:
Blender 2.79

If you happen to link an external object that was made unselectable in the original blend file, You will have no interactive way to make it selectable again, or local, or even delete it from the current blend file.

The good news is that it can easily be done by a very short Python script:

import bpy

obj = bpy.data.objects['the_untouchable_object']
obj.make_local()

It should also be very easy script a loop that will find all those linked objects,
I will post an example when I’ll have a minute to breathe… 😀

Blender – Select Pattern

Software:
Blender 2.79

Use the Select Pattern tool to select multiple objects with name similarities.

  1. In the 3D View in Object mode choose Select > Select Pattern…
  2. In the Select Pattern dialog, type a part of a name with an Asterisk to define wild cards.
    For example *car* will select all objects who’s names contain the string ‘car’,
    And car* will select all objects who’s names begin with the string ‘car’.

Untitled-1

Untitled-2