Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® MotionBuilder® / Python / Group Creation - crash
  RSS 2.0 ATOM  

Group Creation - crash
Rate this thread
 
58655
 
Permlink of this thread  
avatar
  • Mlle
  • Posted: 02 August 2011 12:04 AM
  • Total Posts: 39
  • Joined: 21 March 2008 04:11 PM

Below is a function called by a button action.

Ths code should :
- get the name given by the user in an edittext field.
- parse scene to see if the name exists.
- if yes, append selected objects to the existing group
- if not, add a new group with the new name and add selected objects to it.

I can create new groups the first time I launch the script. But when I try to add objects to a group that I created with the script, Motion Builder crashes.

I cannot find out what is wrong with this code ? :(

def CreateGroupfromSelection(control,event):

    global 
nameGroup
    
   
# nameGroupTxtLyt = FBEdit where user can name the group
    
nameGroup nameGroupTxtLyt.Text
 
    
if nameGroup != "":
       
        
modelList FBModelList()
        
FBGetSelectedModels(modelListNoneTrue)  # gets selected objects #
        
sel modelList.GetCount()

        if 
sel 0:
            
            
# Accessing the scene to view all the groups
            
lScene FBSystem().Scene
            lGroups 
lScene.Groups
            
            
# Append all the groups in the scene in a list            
            
for group in lGroups:

                if 
group.Name == nameGroup:
                    
                    
# Connect selected objects to group
                    
for model in modelList:
                        
group.ConnectSrc(model)
                    
                
elif group.Name != nameGroup:
                    
                    
# Rename group according to username
                    
group FBGroup (nameGroupTxtLyt.Text)
                    
                    
# Connect selected objects to group
                    
for model in modelList:
                        
group.ConnectSrc(model)


** **

Replies: 0