コード例 #1
0
def createConstraintBySelection(pActive, pType, pSnap, pLock):
    '''
    To allow users to query what is their existing selection
    and base the constraint nature as Maya's Child-first, Parent-later. 

    pActive : True = Constraint On, False = Not On
    pType : Constraint Type
    pLock : True = Locked, False = Not Locked
    '''
    lModels = fb.FBModelList()
    fb.FBGetSelectedModels(lModels, None, True, True)
    for s in lModels:
        print s.Name
    # Here we are doing a check if there are 2 objects in selection, or if != 2, then throw an error window
    lSelectedObj = [
        fb.FBFindObjectByFullName(model.FullName) for model in lModels
    ]
    # If two objects are selected, create the constraint
    if len(lSelectedObj) == 2:
        Con = fb.FBConstraintManager().TypeCreateConstraint(pType)
        Con.Name = "Child-" + str([lModels[0].Name]) + "_to_Parent-" + str(
            [lModels[1].Name]) + "-mToolbox"
        Con.ReferenceAdd(0, lModels[0])
        Con.ReferenceAdd(1, lModels[1])
        if pSnap == True:
            Con.Snap()
        Con.Active = pActive
        Con.Lock = pLock
    # If selection is not 2, error message.
    elif len(lSelectedObj) != 2:
        fb.FBMessageBox(
            "Error", "Can't create constraint, Please select only two objects",
            "OK")
コード例 #2
0
 def three_point_constraint(self):
     selected = vmobu.core.get_selection_order()
     pconstraint = pyfbsdk.FBConstraintManager().TypeCreateConstraint(9)
     for i in range(len(selected)):
         if i == 0:
             pconstraint.ReferenceAdd(1, selected[i])
         else:
             pconstraint.ReferenceAdd(0, selected[i])
コード例 #3
0
def run():
    One_Point_Constraint().create_null_object()

    null_vector = pyfbsdk.FBVector3d()
    constrain_null.GetVector(
        null_vector, pyfbsdk.FBModelTransformationType.kModelTranslation)
    constrain_null.GetVector(null_vector,
                             pyfbsdk.FBModelTransformationType.kModelRotation)

    child_obj.Parent = constrain_null

    selected = vmobu.core.get_selection_order()
    constraint_pc = pyfbsdk.FBConstraintManager().TypeCreateConstraint(3)
    constraint_pc.Name = "OnePointConst"

    constraint_pc.ReferenceAdd(1, parent_obj)
    constraint_pc.ReferenceAdd(0, constrain_null)

    constraint_pc.Snap()
コード例 #4
0
ファイル: constraint.py プロジェクト: tpDcc/tpDcc-dccs-mobu
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
コード例 #5
0
ファイル: constraint.py プロジェクト: tpDcc/tpDcc-dccs-mobu
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
Module that contains functions and classes related with constraints for MotionBuilder
"""

from __future__ import print_function, division, absolute_import

import logging

import pyfbsdk

logger = logging.getLogger('tpDcc-dccs-mobu')

CONSTRAINT_TYPES = dict(
    (pyfbsdk.FBConstraintManager().TypeGetName(i), i)
    for i in range(pyfbsdk.FBConstraintManager().TypeGetCount()))


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