Last active
December 9, 2020 16:45
-
-
Save ArashHosseini/9c4f2fe2749b3eec3d09ac121dfcbfad to your computer and use it in GitHub Desktop.
export opticals animation from motion builder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyfbsdk as fb | |
def CreateParentConstraint(parent, child, offset, weight): | |
##Get Object By Name | |
def GetObjectByName(name): | |
lModel = fb.FBFindModelByLabelName(name) | |
return lModel | |
##Set Parent Object | |
objParent = GetObjectByName(parent) | |
##Set Child Object | |
objChild = GetObjectByName(child) | |
print objParent.Name, ">>>", objChild.Name | |
##Create "Parent/Child" Constraint | |
for i in range( fb.FBConstraintManager().TypeGetCount() ): | |
if "Parent/Child" in fb.FBConstraintManager().TypeGetName(i): | |
lMyConstraint = fb.FBConstraintManager().TypeCreateConstraint(i) | |
#for index, element in enumerate(selected_objects): | |
lMyConstraint.ReferenceAdd (0, objChild) | |
lMyConstraint.ReferenceAdd (1, objParent) | |
#Snap if user desires | |
if offset == True: | |
lMyConstraint.Snap() | |
#weight of the constraint | |
lMyConstraint.Weight = weight | |
##Activate Constraint | |
lMyConstraint.Active = True | |
opticals_grp = fb.FBFindModelByLabelName("Opticals") | |
for opt in opticals_grp.Children: | |
if not "CREW" in opt.Name: | |
null_object = fb.FBModelCube("{0}_null".format(opt.Name)) | |
null_object.Show=True | |
parent_trans = opt.Translation | |
null_object.Translation=fb.FBVector3d(parent_trans[0], | |
parent_trans[1], | |
parent_trans[2]) | |
CreateParentConstraint(opt.Name, | |
"{0}_null".format(opt.Name), | |
False, | |
100.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment