def get_current_anim_take_name(): """ Returns the name of the current take :return: str, name of the current take """ current_take = pyfbsdk.FBSystem().CurrentTake take_name = None if current_take: take_name = pyfbsdk.FBSystem().CurrentTake.Name return take_name
def SendSelectedToStory(): lfoldername = fb.FBSystem().CurrentTake.Name lFolder = fb.FBStoryFolder() lFolder.Label = lfoldername ## Character Track lCharTrack = fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackCharacter, lFolder) # Assign our CurrentCharacter to the track lCharTrack.Details.append(fb.FBApplication().CurrentCharacter) # Set Character Track name to Current Character Name lCharTrack.Label = fb.FBApplication().CurrentCharacter.LongName # Insert current take in the newly created track lCharTrack.CopyTakeIntoTrack(fb.FBSystem().CurrentTake.LocalTimeSpan, fb.FBSystem().CurrentTake)
def get_constraint_from_function_box(self, function_box): """ Queries all constraints in the scene and figures out which constraint the given function box belongs to. *Arguments:* * ``box`` Function box to check constraints for *Keyword Arguments:* * ``none`` *Returns:* * ``constraint`` Constraint that the function box belongs to * ``False`` if no constraint is found. """ # Check to be sure function_box value is a pyfbsdk.FBBox. if type(function_box) != pyfbsdk.FBBox: return False # Get the constraints in the scene scene = pyfbsdk.FBSystem().Scene constraints = scene.Constraints # For each constraint in the scene for constraint in constraints: # Is the constraint a relation constraint if type(constraint) == pyfbsdk.FBConstraintRelation: # Is the function box in the constraint if function_box in constraint.Boxes: return constraint # Function box is not found in any constraint self.logger.error( 'Function box [ {0} ] not associated with any constraint.'.format( function_box.Name)) return False
def create_null_object(self): """ Creates a null object to accept the constraint of the system. *Arguments:* * ``None`` *Keyword Arguments:* * ``None`` *Returns:* * ``None`` *Author:* * Jon Logsdon, [email protected], 5/22/2014 1:48:10 PM """ global constrain_null, child_obj, parent_obj constrain_null = pyfbsdk.FBModelNull("OnePointConst_UserNode") selected = vmobu.core.get_selection_order() for i in range(len(selected)): if i == 0: child_obj = selected[i] if i == 1: parent_obj = selected[i] constrain_null_vector = pyfbsdk.FBVector3d() constrain_null.GetVector( constrain_null_vector, pyfbsdk.FBModelTransformationType.kModelTranslation) constrain_null.GetVector( constrain_null_vector, pyfbsdk.FBModelTransformationType.kModelRotation) pyfbsdk.FBSystem().Scene.Evaluate() constrain_null.SetVector( pyfbsdk.FBVector3d(self.pos_null_vector), pyfbsdk.FBModelTransformationType.kModelTranslation) constrain_null.SetVector( pyfbsdk.FBVector3d(self.pos_null_vector), pyfbsdk.FBModelTransformationType.kModelRotation) for comp in pyfbsdk.FBSystem().Scene.Components: comp.Selected = False
def get_character_node_by_name(name): """ Returns character node with given long name from current scene :param name: str :return: FBCharacter or None """ for character_node in pyfbsdk.FBSystem().Scene.Characters: if name != character_node.LongName: continue return character_node
def SendAllCharactersToStory(): charIndex = 1 lClipList = [] lMyStartTime = 0 # Find all characters in the scene. Add them to story track for lChar in fb.FBSystem().Scene.Characters: # Create Track for one character lTrack = fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackCharacter) # Specify the index of the character which is one lTrack.CharacterIndex = charIndex # Creating the track names based on character names and adding a 'Track' behind. lTrack.LongName = lChar.LongName + " Track" #lTrack.Ghost = self.ui.RBEnableGhost.isChecked() # Insert current take lClip = lTrack.CopyTakeIntoTrack( fb.FBSystem().CurrentTake.LocalTimeSpan, fb.FBSystem().CurrentTake) # Shift clip to start time at 0 lClip.Start = fb.FBTime(0, 0, 0, lMyStartTime) # adding one to the index so that it will repeat for the next character in the scene. charIndex = charIndex + 1 # insert current take. lClipList.append(lClip)
def get_constraint_by_name(name, include_namespace=True): """ Returns a constraint that matches given long name :param name: str, name of the constraint :param include_namespace: bool, Whether or not to include node namespace :return: """ for constraint in pyfbsdk.FBSystem().Scene.Constraints: constraint_name = constraint.LongName if include_namespace else constraint.Name if name != constraint_name: continue return constraint
def _saveBuffer(savePath, tmpImgExtension="tif"): app = fb.FBApplication() take = fb.FBSystem().CurrentTake current = fb.FBTime(fb.FBPlayerControl().GetEditCurrentTime()) next = fb.FBTime(fb.FBPlayerControl().GetEditCurrentTime() + 1) opts = fb.FBVideoGrabber().GetOptions() videoManager = fb.FBVideoCodecManager() videoManager.VideoCodecMode = fb.FBVideoCodecMode.FBVideoCodecUncompressed opts.OutputFileName = savePath opts.RenderAudio = False opts.BitsPerPixel = fb.FBVideoRenderDepth.FBVideoRender32Bits opts.TimeSpan = fb.FBTimeSpan(current, next) opts.TimeStep = fb.FBTime(0, 0, 0, 1, 0) app.FileRender( opts )
def get_constraint_by_type(constraint_type): """ Returns a list of constraints in the current scene of the given type :param constraint_type: str, constraint type ('Aim', 'Position', etc) :return: """ found_constraints = list() for constraint in pyfbsdk.FBSystem().Scene.Constraints: class_type = getattr( pyfbsdk.kConstraintClassDict.get(constraint.Description), 'constraintType') if constraint_type != class_type: continue found_constraints.append(constraint) return found_constraints
def get_selected(type_filters=[]): """ Gets selected components :param type_filters: list of class types to filter :type type_filters: list of str :return: list of components :rtype: list of objects """ scene = pyfbsdk.FBSystem().Scene selected = [] for comp in scene.Components: if comp.Selected and \ hasattr(comp, "Animatable") and \ comp.ClassName() not in type_filters: selected.append(comp) return selected
def create_constraint(constraint_type, name=None): """ Creates a constraint with the given type :param constraint_type: str, constraint type found in CONSTRAINT_TYPES :param name: str, optional name to give to constraint. :return: """ try: constraint = pyfbsdk.FBConstraintManager().TypeCreateConstraint( pyfbsdk.kConstraintTypes[constraint_type]) except KeyError: raise Exception( 'Invalid constraint type given: "{}"'.format(constraint_type)) pyfbsdk.FBSystem().Scene.Constraints.append(constraint) if name: constraint.Name = name return constraint
def setup(): """ adds package to python folder in motionbuilder """ package_path = this_path("AnimIO") python_path = pyfbsdk.FBSystem().GetPythonStartupPath()[0] dest_path = os.path.join(python_path, "AnimIO") # remove dir if exists to reinstall if os.path.exists(dest_path): result = pyfbsdk.FBMessageBox("Reinstall", "Reinstall AnimIO?", "Ok", "Cancel") if result == 1: shutil.rmtree(dest_path) else: raise RuntimeError("AnimIO not reinstalled!") shutil.copytree(package_path, dest_path) pyfbsdk.FBMessageBox("Installed", "AnimIO has been installed", "Ok")
def get_dcc_version(dcc_name): version = '' if dcc_name == 'maya': import maya.cmds version = int(maya.cmds.about(version=True)) elif dcc_name == 'max': from pymxs import runtime max_version = runtime.maxVersion() version = int(2000 + (math.ceil(max_version[0] / 1000.0) - 2)) if max_version[0] < 20000 else int(max_version[7]) elif dcc_name == 'mobu': import pyfbsdk version = int(2000 + math.ceil(pyfbsdk.FBSystem().Version / 1000.0)) elif dcc_name == 'houdini': import hou version = '.'.join(hou.applicationVersionString().split('.')[:-1]) elif dcc_name == 'unreal': import unreal version = '.'.join(unreal.SystemLibrary.get_engine_version().split( '+++')[0].split('-')[0].split('.')[:-1]) return str(version)
def find_constraint(self, constraint_name): """ Searches through the scene's list of constraints to find the constraint associated with the name supplied. *Arguments:* * ``none`` *Keyword Arguments:* * ``none`` *Returns:* * ``constraint`` <FBConstraintRelation> * ``False`` If no constraint in the scene matches the name given """ scene = pyfbsdk.FBSystem().Scene constraints = scene.Constraints for constraint in constraints: if constraint.LongName == constraint_name: return constraint self.logger.warning('No constraint found that matches name {0}'.format( constraint_name)) return False
def __init__(self, parent): QtGui.QWidget.__init__(self, parent) loader = QtUiTools.QUiLoader() self.ui = loader.load( r'D:\Dropbox (Personal)\Python\01_MotionBuilder\b_MarkerConstraintTool\ui\markerConstraintTool.ui', self) self.ui.show() self.ui.charLst.clear() p = re.compile('.+:Mesh') self.lGroupList = fb.FBSystem().Scene.Groups for i in self.lGroupList: matched = p.match(i.LongName) if matched: # sorting RTAs by Mesh layer in Groups (this is for Ubisoft pipeline) # this entierly depends on existing pipeline, if the pipeine is sorted by namespace, then use namespace. item = CustomListitem(i.LongName, i) self.ui.charLst.addItem(item) # Marker Constraint Tool Tab =================================================# self.ui.btnCreateMarker.clicked.connect(self.btnCallBackCreateMarker) self.ui.btnCreateConstraint.clicked.connect( self.btnCallBackCreateConstraint) self.ui.btnResetScene.clicked.connect(self.btnCallBackResetScene) # Set Tool Hint ==============================================================# self.ui.btnCreateMarker.setToolTip( "Creates a random-colored marker based on selection.") self.ui.btnCreateConstraint.setToolTip( "Creates a Parent-Child Constraint, Please Select Child First") self.ui.btnResetScene.setToolTip("Resets Scene !! Use with Care") # Story Tool Tab =============================================================# # Characters Buttons self.ui.btnSendSelChar.clicked.connect(self.btnCallBackSendSelToStory) self.ui.btnSendAllChar.clicked.connect(self.btnCallBackSendAllToStory) # Set Tool Hint ==============================================================# # Character Buttons's Tooltips self.ui.btnSendSelChar.setToolTip( "Sends Selected Character to Story Track with Current Take") self.ui.btnSendAllChar.setToolTip( "Sends All Characterss to Story Track with Current Take and Move Clip to Start from 0" ) self.ui.chkboxCharPlotOrNot.setToolTip( "If enabled, plots take to ControlRig and Skeleton") # Color Tool Tab =============================================================# ''' the below is to populate list of characters within the scene. ''' self.ui.charLst.itemClicked.connect(self.onItemClicked) self.ui.btnApplyCol.clicked.connect(self.btnCallBackApplySelectedColor) # creating all the materials we need # material = fb.FBMaterial('Mat_Gray') material.Diffuse = fb.FBColor(0.8, 0.8, 0.8) material = fb.FBMaterial('Mat_Red') material.Diffuse = fb.FBColor(0.59, 0.03, 0.01) material = fb.FBMaterial('Mat_Green') material.Diffuse = fb.FBColor(0.50, 0.60, 0) material = fb.FBMaterial('Mat_Blue') material.Diffuse = fb.FBColor(0.31, 0.59, 1.00) for i in mobuMat: if i.Name == "Mat_Gray": colorMat.append(i) if i.Name == "Mat_Red": colorMat.append(i) if i.Name == "Mat_Green": colorMat.append(i) if i.Name == "Mat_Blue": colorMat.append(i) print len(colorMat) for i in colorMat: print i.Name
def clearMaterialSelection(): for i in fb.FBSystem().Scene.Materials: i.Selected = False
def clearSelection(): for i in fb.FBSystem().Scene.Components: i.Selected = False
import os import pyfbsdk as fb import pyfbsdk_additions as fba from pyfbsdk import FBMessageBox import re import random as rand from functools import partial from time import gmtime, strftime from PySide import QtCore, QtGui, QtUiTools from PySide.QtCore import Signal mobuApp = fb.FBApplication() mobuSys = fb.FBSystem() mobuGrp = fb.FBSystem().Scene.Groups mobuMat = fb.FBSystem().Scene.Materials colorMat = [] def clearSelection(): for i in fb.FBSystem().Scene.Components: i.Selected = False def clearMaterialSelection(): for i in fb.FBSystem().Scene.Materials: i.Selected = False
from functools import wraps class ContextDecorator(object): """contextlib.ContextDecorator backport.""" def __call__(self, func): @wraps(func) def decorated(*args, **kwargs): with self: return func(*args, **kwargs) return decorated # ------------------------------------------------------------------------------ lapp = pyfbsdk.FBApplication() lsys = pyfbsdk.FBSystem() lplayer = pyfbsdk.FBPlayerControl() lundo = pyfbsdk.FBUndoManager() # ------------------------------------------------------------------------------ class SuspendRefresh(ContextDecorator): def __enter__(self): pyfbsdk.FBBeginChangeAllModels() def __exit__(self, exc_type, exc_val, exc_tb): pyfbsdk.FBEndChangeAllModels() return False # ------------------------------------------------------------------------------
def __init__(self): self._system = native.FBSystem()