Python script to select group

Python script to select group

megazor
Contributor Contributor
1,684 Views
2 Replies
Message 1 of 3

Python script to select group

megazor
Contributor
Contributor

Hej! 🙂

I want to select a specific (selection?) group in my scene using Python.

megazor_0-1618814366447.png

 

I'm on Motionbuilder 2019.

 

The idea is to make this line of code part of an export script or a hotkey for selecting the content of a specific group.

It feels like this should be simple, but I haven't been able to figure it out or find a solution for it on the interwebs. 🙂

 

Thanks in advance!

 

//Martin

0 Likes
Accepted solutions (1)
1,685 Views
2 Replies
Replies (2)
Message 2 of 3

vdebaie
Advocate
Advocate
Accepted solution

try this:

 

from pyfbsdk import *

def GetGroupedObjects(groupName=str):
    ##This will unselect all objects within your scene
    for comp in FBSystem().Scene.Components:
        comp.Selected = False
    ##This will select only the objects that are in the desired group    
    for group in FBSystem().Scene.Groups:
        if groupName == group.Name:
            for n in range(group.GetSrcCount()):
                group.GetSrc(n).Selected = True

            
##Replace "MyGroup" with the name of the group that has the objects you want selected
GetGroupedObjects("MyGroup")
Message 3 of 3

megazor
Contributor
Contributor

@vdebaie

This is great! Thank you very much! It seems to do just what I hoped for 🙂

0 Likes