|
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(modelList, None, True) # 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)
** **
|
|
|