# Copyright 2009 Autodesk, Inc.  All rights reserved.
# Use of this software is subject to the terms of the Autodesk license agreement 
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
#
# Script description:
# Create and edit Groups of cube
#
# Topic: FBModelCube, FBGroup, FBNamespaceAction
#

from pyfbsdk import FBModelCube, FBSystem, FBGroup, FBNamespaceAction

# Setting up a test scene
cube1 = FBModelCube ("Cube 1")
cube1.Show = True
cube2 = FBModelCube ("Cube 2")
cube2.Show = True
cube3 = FBModelCube ("Cube 3")
cube3.Show = True
cube4 = FBModelCube ("Cube 4")
cube4.Show = True
cube5 = FBModelCube ("Cube 5")
cube5.Show = True
cube6 = FBModelCube ("Cube 6")
cube6.Show = True

# Creating the groups

# Creating Group One, which contains one cube
lGroup1 = FBGroup ("OneCubeGroup")
# Adding the object to the group
lGroup1.ConnectSrc( cube1 )

# Setting the attributes
lGroup1.Show = True
lGroup1.Pickable = False
lGroup1.Transformable = False

# Creating Group Two, which contains two cubes
lGroup2 = FBGroup ("TwoCubeGroup")

# Adding the objects to the group
lGroup2.ConnectSrc( cube2 )
lGroup2.ConnectSrc( cube3 )

# Setting the attributes
lGroup2.Show = True
lGroup2.Pickable = True
lGroup2.Transformable = False

# Creating Group Three, which contains three cubes
lGroup3 = FBGroup ("ThreeCubeGroup")

# Adding the objects to the group
lGroup3.ConnectSrc( cube4 )
lGroup3.ConnectSrc( cube5 )
lGroup3.ConnectSrc( cube6 )

# Setting the attributes
lGroup3.Show = True
lGroup3.Pickable = True
lGroup3.Transformable = True

# One thing to note is normally you would use the items property to add objects 
# to the group however within Python this attribute is a Tuple so you cannot add
# items to it, this is why we are using FBPlug methods to add items.

# This is how you remove objects from the group, commented out so user can see the groups in the Viewer
#lGroup1.DisconnectSrc( cube1 ) 
#lGroup2.DisconnectSrc( cube2 )
#lGroup2.DisconnectSrc( cube3 ) 
#lGroup3.DisconnectSrc( cube4 ) 
#lGroup3.DisconnectSrc( cube5 ) 
#lGroup3.DisconnectSrc( cube6 ) 

# Clean-up
del(FBModelCube, FBSystem, FBGroup, FBNamespaceAction, cube1, cube2, cube3, cube4, cube5, cube6, lGroup1, lGroup2, lGroup3)