collect meshes by namespace with Python

collect meshes by namespace with Python

Anonymous
Not applicable
1,930 Views
6 Replies
Message 1 of 7

collect meshes by namespace with Python

Anonymous
Not applicable

Hi All,

 

If I have a namespace string is it possible to collect all of the meshes that are under that namespace using python? I noticed a command to collect by namespace but it looks like it's been depreciated. Can anyone give me an example that works in Mobu 2018?

 

Many thanks

Dan

0 Likes
Accepted solutions (1)
1,931 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

Hello,

I've made progress:

 

cl = FBComponentList()

FBFindObjectsByName( ( "myNameSpace:*"), cl , True , True)

 

This gets me everything with the namespace "myNameSpace" but I need to further filter the list so it only contains objects that have polygons? Can anyone provide an example please?

Thanks for reading

 

 

0 Likes
Message 3 of 7

vdebaie
Advocate
Advocate
Accepted solution

you can go through the list you created using the names space and search for the class FBModel:

def getFBModels( list ):
    foundModels = []
    
    for i in list:
        if i.__class__ is FBModel:
            myModels.extend( [i] )
    
    return myModels

This will return another list that only has Models in them. You can also adjust your pipeline so that all Models that are imported into MotionBuilder have the suffix "_GEO" or something that will make it stand out.

Message 4 of 7

Anonymous
Not applicable

Hi, Thanks for the example that helps a lot. I noticed there is a sub class of 'FBMesh' in the docs, is it possible use that in some way to filter the list? Thanks again for the help. 

0 Likes
Message 5 of 7

vdebaie
Advocate
Advocate

you can do something like this:

def GetFBModelByNameSpace( pNameSpace = str ):
    modelList = []
    for c in FBSystem().Scene.Components:
        if c.__class__  is FBModel and c.LongName.rsplit(':', 1)[0] == pNameSpace:
                modelList.extend( [c] )
    if len(modelList) != 0:
        return modelList
Message 6 of 7

Mocappy
Advocate
Advocate

Sorry, bit late to this one, but you can also use "NamespaceSelectContent" - this is the new version of the Namespace commands it sounds like you used before.

 

from pyfbsdk import *

NAMESPACE = ""

# Select All objects in "NAMESPACE"
FBSystem().Scene.NamespaceSelectContent(NAMESPACE, True)

# Create FBModelList for mesh objects
meshList = FBModelList()
# Go through all the components in the scene
for sceneComponent in FBSystem().Scene.Components:
    if sceneComponent.Selected\
    and sceneComponent.TypeInfo is FBModel_TypeInfo():
        # Add object to meshList
        meshList.append(sceneComponent)
        # Deselect?
        # sceneComponent.Selected = False
    else:
        sceneComponent.Selected = False
# Print Items in List
print [i for i in meshList]

 

Similar to Vic's suggestion, just using alternate functions.

 

Hope this helps,

0 Likes
Message 7 of 7

vdebaie
Advocate
Advocate

I like this, I'll have to remember to use it.

FBSystem().Scene.NamespaceSelectContent(NAMESPACE, True)

 

Thanks!! 🙂