Python: Spoonfed - (2-12) Selection by type

And here are the promised scripts. You should be able to read the code:

This script takes a single selected tag, and selects all tags of the same type on the object that the selected tag belongs to. This can be used to quickly select all texture tags or polygon selection tags or ToDo tags on one object by clicking on a proxy to determine the type, and then trigger this function.

The only thing in this script that we haven't encountered before is the function GetObject(). Invoked on a tag, it returns a reference to the tag's object.

The second script is similar:

This one selects all similar tags - tags of the same type as the selected one - on all selected objects. The original tag does not need to be on a selected object, in which case it will be deselected.

The script does basically the same as the previous one, with one added loop over the selected objects. Also, we explicitly deselect the original tag - if it is on a selected object, and therefore should stay selected, it will be re-selected anyway during the loops.

In our third script, we return to the object level:

Here, we select all objects in the tree that have the same type as any of the currently selected objects. That means, you could select a camera and a cube, and the script will select all cameras and all cubes in the scene.

To do so, we collect all types of the selected objects in a second list typeList as first step. Then, we use the familiar treewalking function to move through the tree and perform the selection. Note that typeList and newSelection need to be global (as you can see, it is possible to declare several variables as global in one statement by just separating them with a comma).

Note that a function to select similar tags on children of the current object is already part of Cinema 4D. Also, you can use the filter functionality in the Object Manager to select objects of a certain type.

Homework: Think about what kind of selections you frequently need. What would you like to have a script for? Share your thoughts in the comments.

By becoming a patron, you'll instantly unlock access to 113 exclusive posts
113
Writings
By becoming a patron, you'll instantly unlock access to 113 exclusive posts
113
Writings