BasicOperations/FBClusterTransactions.py
 
 
 
BasicOperations/FBClusterTransactions.py
# 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:
# Shows you how to access the cluster and cluster index, while using the cluster 
# transactions.
#
# Sample scene file this script works with: FBClusterTransactions.fbx 
# 
# Topic: FBCluster
#

from pyfbsdk import *
import os
import os.path


gApp = FBApplication()
gSys = FBSystem()

gApp.FileNew()

lFilePath = os.path.abspath( os.path.join( gSys.ApplicationPath, r"..\config\FBClusterTransactions.fbx"))
print "Source File Path", lFilePath

gApp.FileOpen(lFilePath)

lSphere = FBFindModelByLabelName("pSphere1")

if lSphere:
    skinCluster = FBCluster(lSphere)
    print skinCluster.Name

    if skinCluster and skinCluster.LinkGetCount():
        for n in range (skinCluster.LinkGetCount()): 
            skinCluster.ClusterBegin(n) # Set the current cluster index
            linkName = skinCluster.LinkGetName(n)
            linkModel = skinCluster.LinkGetModel(n)
            numVerts = skinCluster.VertexGetCount() # Using the current cluster index
            print numVerts
            for v in range (numVerts):
                vertIndex = skinCluster.VertexGetNumber(v) # Using the current cluster index
                vertWeight = skinCluster.VertexGetWeight(v) # Using the current cluster index
                print "For Vertex Index %d, the weight is %d" % (vertIndex, vertWeight)
            skinCluster.ClusterEnd()