def addNamespace(self, node=None, ns='', hier=False):
		''' adds a namespace
			Params:
				node: node to add to
				ns: namespace to add
				hier: process hierarchy or not
			Returns: True/False
		'''
		if not node:
			moBuLogger.error("No node passed.")
		if not ns:
			moBuLogger.error("No namespace passed.")
		
		# skip if namespace already there
		if ns in node.LongName:
			moBuLogger.debug("'%s' already in object: '%s'" % (ns, node.LongName))
			return False
		
		try:
			if hier:
				node.ProcessNamespaceHierarchy(FBNamespaceAction.kFBConcatNamespace, ns, None, False)
			else:
				node.ProcessObjectNamespace(FBNamespaceAction.kFBConcatNamespace, ns, None, False)
		except:
			return False
		return True 
    def addNamespace(self, node=None, ns='', hier=False):
        ''' adds a namespace
			Params:
				node: node to add to
				ns: namespace to add
				hier: process hierarchy or not
			Returns: True/False
		'''
        if not node:
            moBuLogger.error("No node passed.")
        if not ns:
            moBuLogger.error("No namespace passed.")

        # skip if namespace already there
        if ns in node.LongName:
            moBuLogger.debug("'%s' already in object: '%s'" %
                             (ns, node.LongName))
            return False

        try:
            if hier:
                node.ProcessNamespaceHierarchy(
                    FBNamespaceAction.kFBConcatNamespace, ns, None, False)
            else:
                node.ProcessObjectNamespace(
                    FBNamespaceAction.kFBConcatNamespace, ns, None, False)
        except:
            return False
        return True
	def checkForValues(self, pModel):
		#Check the values on the Reference node
		nonZero = 0
		pymbModel = self.getObject(pModel, pyMB=True, quiet=True)
		if pymbModel:
			trans = pymbModel.GetTranslation()
			rot = pymbModel.GetRotation()
			moBuLogger.debug("'%s' trans='%s', rot='%s'" % (pymbModel, trans, rot))
			if  trans[0] != 0 or trans[1] != 0 or trans[2] != 0 or rot[0] != 0 or rot[1] != 0 or rot[2] != 0:
				nonZero = 1
		return nonZero
	def listTakeNames(self):
		''' prints and returns list of all Takes in scene
		Params: n/a
		Returns: [list] of take names
		'''
		takeNames = []
		allTakes = self.listTakes()
		for pTake in allTakes:
			if not pTake.Name == "None":
				takeNames.append(pTake.Name)
				moBuLogger.debug(pTake.Name)
		return takeNames
	def getLastTake(self):
		''' does not work because listTakes does not return Takes in correct order in scene '''
		# have to use self.listTakeNames because cannot do len() on FBPropertyListTake
		allTakes = self.listTakeNames()
		if not allTakes:
			return None
		numTakes = len(allTakes)
		lastTake = allTakes[numTakes - 1]
		for pTake in FBSystem().Scene.Takes:
			if pTake.Name == lastTake:
				moBuLogger.debug(pTake.Name)
				return pTake
	def getSelectedCharacters(self):
		''' returns list of selected FBCharacter objects
		Params:
			None
		Returns: [list]
		'''
		pList = []
		lScene = FBSystem().Scene
		charactersList = lScene.Characters
		for character in charactersList:
			if character.Selected:
				moBuLogger.debug("%s is selected" % character.Name)
				pList.append (character)
		return pList
	def getAllByType(self, _type='all'):
		''' return list[] of everything in scene of specific type
		Params:
			#_type: passed FBobject type
			_type: passed FBObject type as a str
			found: [list] of objects of type
		'''
		# check for str(_type)
		if not isinstance(_type, str):
			moBuLogger.error("_type arg must be type(str) now.")
			
		allComps = FBSystem().Scene.Components
		pObjects = []
		for comp in allComps:
			if _type == 'all':
				
				# skip __SYSTEM objects
				if '__SYSTEM' in comp.LongName:
					continue
				
				# skip animationLayers
				if comp.ClassName() == 'FBBox':
					if "Anim" in comp.Name:
						continue
				
				# skip if type(FBBox), BaseAnimation
				if isinstance(comp, FBBox) and ('BaseAnimation' in comp.Name or 'AnimLayer1' in comp.LongName):
					continue
				
				# skip if type(FBModel), 'ActorBodyBone' and 'ActorBodyMesh'
				if isinstance(comp, FBModel) and ('ActorBodyBone' in comp.LongName or 'ActorBodyMesh' in comp.LongName):
					continue
				
				# skip if type(FBModel), 'Motion Blend Result'
				if isinstance(comp, FBModel) and 'Motion Blend Result' in comp.Name:
					continue
				
				pObjects.append(comp)
				
				
			elif _type == comp.ClassName():
				pObjects.append(comp)
			moBuLogger.debug("Adding %s  <---type	 %s  <--LongName" % (comp.ClassName(), comp.LongName))
			
		return pObjects
	def getObject(self, name, pyMB=False, exact=False, quiet=False):
		''' gets FBObject or PMBObject
			Params:
				name: string name of object
				pyMB: return PMBObject type
				exact: if true search namespace as well
				quiet: if true does not warn when object doesn't exist
			Returns: FBObject/PMBObject
		'''
		# use 2014 command
		if self.mobuVer == 2014:
			FBFindModelByName = FBFindModelByLabelName
			
		if not isinstance(name, str):
			moBuLogger.debug("MoBu.getObject() was passed '%s'" % name)
			# probably already an object
			if pyMB:
				if not isinstance(name, PMBModel):
					pModel = name.ConvertToPyMoBu()
					return pModel
			return name
			
		pModel = FBFindModelByName(name)
		exactWord = ''
		if exact:
			# Need to find EXACT name
			pModel = FBFindModelByLabelName(name)
			exactWord = 'exact '

		# convert to PMBModel?
		if pModel:
			if pyMB:
				if not isinstance(pModel, PMBModel):
					pModel = pModel.ConvertToPyMoBu()
			return pModel
		
		if not quiet:
			moBuLogger.warning("Could not find object with %sname '%s'" % (exactWord, name))
		return None
	def deleteAll(self, pObjects=[]):
		''' deletes all objects passed in the list
			Params:
				pObjects: list of FBObjects
			Returns: True/False
		'''
		success = True
		
		# try selected if nothing passed
		if len(pObjects) == 0:
			pObjects = self.getSelected(_type='all', found=False)
			if len(pObjects) == 0:
				moBuLogger.warning("Must pass list or have something selected.")
				return False
		
		# covert to python list from FBPropertyListComponent
		pObjectsList = []
		if isinstance(pObjects, FBPropertyListComponent):
			for obj in pObjects:
				pObjectsList.append(obj)
		else:
			pObjectsList = pObjects
		
		# cull FBModelSkeleton type out to delete last
		deleteList = []
		modelSkels = []
		for _object in pObjectsList:
			if not isinstance(_object, FBModelSkeleton):
				deleteList.append(_object)
			else:
				modelSkels.append(_object)
		
		
		# delete everything but FBModelSkeletons
		count = 0
		for obj in deleteList:
			
			try:
				# stupid list and unbound, have to test
				try:
					name = obj.Name	# have to store before deleting
					obj.FBDelete()
					moBuLogger.debug("Deleted: %s" % name)
					count += 1
				except UnboundWrapperError:
					moBuLogger.debug("%s already deleted, skipping." % name)
			except:
				moBuLogger.debug("Failed to delete: %s" % name)
				success = False
		
		##WARNING!! Must delete other objects BEFORE
		##deleting FBModelSkeletons via children first

		# destroy FBModelSkeleton from hier up
		for modelSkel in modelSkels:
			try:
				# stupid list and unbound, have to test
				try:
					name = modelSkel.Name	# have to store before deleting
					modelSkel.FBDelete()
					moBuLogger.debug("Deleted: %s" % name)
					count += 1
				except UnboundWrapperError:
					moBuLogger.debug("%s already deleted, skipping." % name)
			except:
				moBuLogger.debug("Failed to delete: %s" % name)
				success = False
		
		moBuLogger.info("Deleted '%d' objects" % count)
		
		# clean
		del(pObjectsList, pObjects)
			
		return success
	def replaceNamespaceOnChar(self, nSpace='', quiet=False):
		''' replace namespace on character or add if none
			Params:
				nSpace: namespace to add/replace with
				quiet: suppress message
			Returns: True/False
		'''
		
		success = True
		
		# get selected reference or find it
		selected = self.getSelected(_type='all', found=True)
		if not selected:
			# try to select
			selected = self.getReference(namespace='', pyMB=False)
			if not selected:
				# run again
				if not quiet:
					moBuLogger.errorDialog("Select a node from the character")
				else:
					moBuLogger.error("Select a node from the character")
				return False
		
		# get the FBSet associated with the character
		if isinstance(selected, FBSet):
			charSet = selected
		else:
			charSet = mbSets.findSetFromObject(pObject=selected, quiet=quiet)
		if not charSet:
			return False
	
		# iterate through all items in set		
		for item in charSet.Items:
			# check if already has namespaces
			currentNS = None
			if mbNamespace.getNamespace(node=item):
				for ns in mbNamespace.getNamespace(node=item):
					# do NOT replace '*_Template' Namespaces
					if not '_Template' in ns:
						currentNS = ns
						
						# check for replace or add
						if not mbNamespace.replaceNamespace(node=item, nsOrig=currentNS, nsReplace=nSpace, hier=False):
							moBuLogger.debug("Failed to replaceNamespace on: '%s'" % item.LongName)
							success = False
					else:	#_Template Namespace
						# check for existence of new nSpace
						if not nSpace in mbNamespace.getNamespace(node=item):
							# add
							if not mbNamespace.addNamespace(node=item, ns=nSpace, hier=False):
								moBuLogger.debug("Failed to addNamespace on: '%s'" % item.LongName)
								success = False
			else:
				if not mbNamespace.addNamespace(node=item, ns=nSpace, hier=False):
					moBuLogger.debug("Failed to addNamespace on: '%s'" % item.LongName)
					success = False
			
		# add nameSpace to set as well
		if not mbNamespace.addNamespace(node=charSet, ns=nSpace, hier=False):
			moBuLogger.debug("Failed to addNamespace on: '%s'" % charSet.LongName)
			# no need to report False, already getting added
		
		return success
 def listCallback(self, control, event):
     self.listSelection = control.Items[control.ItemIndex]
     moBuLogger.debug("%s has been selected!" % self.listSelection)
 def goButtonCallback(self, control, event):
     moBuLogger.info("Button '%s' pressed" % control.Name)
     # create set
     newSet = FBSet(self.listSelection)
     moBuLogger.debug("Result of set creation is '%s'" % newSet)
     self.addAllToSet(name=newSet.Name, quiet=False)
	def listCallback(self, control, event):
		self.listSelection = control.Items[control.ItemIndex] 
		moBuLogger.debug("%s has been selected!" % self.listSelection)
	def goButtonCallback(self, control, event):
		moBuLogger.info("Button '%s' pressed" % control.Name)
		# create set
		newSet = FBSet(self.listSelection)
		moBuLogger.debug("Result of set creation is '%s'" % newSet)
		self.addAllToSet(name=newSet.Name, quiet=False)
    def replaceNamespaceOnChar(self, nSpace='', quiet=False):
        ''' replace namespace on character or add if none
			Params:
				nSpace: namespace to add/replace with
				quiet: suppress message
			Returns: True/False
		'''

        success = True

        # get selected reference or find it
        selected = self.getSelected(_type='all', found=True)
        if not selected:
            # try to select
            selected = self.getReference(namespace='', pyMB=False)
            if not selected:
                # run again
                if not quiet:
                    moBuLogger.errorDialog("Select a node from the character")
                else:
                    moBuLogger.error("Select a node from the character")
                return False

        # get the FBSet associated with the character
        if isinstance(selected, FBSet):
            charSet = selected
        else:
            charSet = mbSets.findSetFromObject(pObject=selected, quiet=quiet)
        if not charSet:
            return False

        # iterate through all items in set
        for item in charSet.Items:
            # check if already has namespaces
            currentNS = None
            if mbNamespace.getNamespace(node=item):
                for ns in mbNamespace.getNamespace(node=item):
                    # do NOT replace '*_Template' Namespaces
                    if not '_Template' in ns:
                        currentNS = ns

                        # check for replace or add
                        if not mbNamespace.replaceNamespace(node=item,
                                                            nsOrig=currentNS,
                                                            nsReplace=nSpace,
                                                            hier=False):
                            moBuLogger.debug(
                                "Failed to replaceNamespace on: '%s'" %
                                item.LongName)
                            success = False
                    else:  #_Template Namespace
                        # check for existence of new nSpace
                        if not nSpace in mbNamespace.getNamespace(node=item):
                            # add
                            if not mbNamespace.addNamespace(
                                    node=item, ns=nSpace, hier=False):
                                moBuLogger.debug(
                                    "Failed to addNamespace on: '%s'" %
                                    item.LongName)
                                success = False
            else:
                if not mbNamespace.addNamespace(
                        node=item, ns=nSpace, hier=False):
                    moBuLogger.debug("Failed to addNamespace on: '%s'" %
                                     item.LongName)
                    success = False

        # add nameSpace to set as well
        if not mbNamespace.addNamespace(node=charSet, ns=nSpace, hier=False):
            moBuLogger.debug("Failed to addNamespace on: '%s'" %
                             charSet.LongName)
            # no need to report False, already getting added

        return success