MOBU - can't fully delete with python

I don’t know if it’s a known issue but I’m hoping someone have either a workaround or a fix for this.

So the problem started with an animator using cube in his scene and we somehow noticed we had trouble accessing this cube through our tools. After a quick investigation we noticed that the animator created and delete several cube… and if you delete a cube manually it won’t really be deleted and mobu will keep a FBMesh in the components of the scene…

cube = FBModelCube('Cube')

def getBrokenCube():
    for n in FBSystem().Scene.Components:
        if n.Name == 'Cube':
            print n
            return n
      
    print 'nothing found'

theCube = getBrokenCube()

This will return a FBModel , now if you manually delete it in the scene and re-run the getBrokenCube you will get a FBMesh…

This behaviour only seems to occur with Cube… and happens in both mobu 2017 and 2015 ( havent tested other versions)

I tried getting the FBMesh and then do a FBDelete() but the object remains… Any way to get rid of this mesh and fix the “corrupted scene” ?

Thanks

After looking into this, it unfortunately seems that I cannot get that FBMesh to get deleted as well. Its an interesting problem, and maybe someone else has insight on how to do it from the MotionBuilder UI.

You can delete child objects of the root model by looking it up in Python by label name. Heres a quick pyside UI to illustrate.

# Built in

# Third Party
from pyfbsdk import FBSystem, FBFindModelByLabelName
from PySide.QtGui import (
    QDialog, 
    QPushButton, 
    QListWidget, 
    QVBoxLayout, 
    QApplication,
    QListWidgetItem
)

# Custom


class MainWin(QDialog):
    """ Main window of the app """
    
    def __init__(self, parent=None):
        """ Initialization """
        super(MainWin, self).__init__(parent)
        self.setWindowTitle('Model Recursive Delete')
        
        self.main_layout = QVBoxLayout()
        self.setLayout(self.main_layout)
        
        self.model_list = QListWidget()
        self.populate_list()
        
        self.refresh_button = QPushButton('Refresh list')
        self.refresh_button.clicked.connect(self.populate_list)
        
        self.del_button = QPushButton('Delete model')
        self.del_button.clicked.connect(self.recursive_del)
        
        self.main_layout.addWidget(self.model_list)
        self.main_layout.addWidget(self.refresh_button)
        self.main_layout.addWidget(self.del_button)
        
    def populate_list(self):
        """ Populates the list widget with the scene root models. """
        self.model_list.clear()
        
        for model in FBSystem().Scene.RootModel.Children:
            item = QListWidgetItem(model.Name)
            self.model_list.addItem(item)
        
    def recursive_del(self):
        """ Deletes a top model and children. """
        models_selected = self.model_list.selectedItems()
        
        for model in models_selected:
            self.delete_obj(FBFindModelByLabelName(str(model.text())))
            self.model_list.takeItem(self.model_list.row(model))
        
    def delete_obj(self, obj):
        """ Recursively performs the delete op.
        
        Args:
            obj (FBType): FB model. May be child.
        """
        while len(obj.Children) > 0:
            self.delete_obj(obj.Children[-1])
            
        obj.FBDelete()
        

app = MainWin(parent=QApplication.activeWindow())
app.show()

I can’t repro your issue in 2016 (sp1hf7) or 2018.

FBDelete method works fine. Are you sure there’s nothing else that may prevent deletion, like a FBPlug callback? If you have custom tools installed, try running without them and try again.

Hello, I also have such a problem at present, so I would like to ask if you have found a solution? If you find it, can you share it with me? Looking forward to your reply^^~

We fixed it by telling animator that cube are little evil fuckers. Alternatively autodesk sent us a patched version so we didn’t really had to push the investigation.

Sorry

ok,I’ve learned,thank you~