Software Community Services About Contact

Reply to topic Page 1 of 1
Script: find a constraint and turn it off
Author Message
Reply with quote
Post Script: find a constraint and turn it off 
Code:
from pyfbsdk import *

# initialize the needed variables

lScene = FBSystem().Scene

for lcon in lScene.Components:
    if lcon:
        # searching for constraint with Toe in name
        if lcon.Name.find("Toe") != -1:
            if lcon.ClassName() == "FBConstraint":
             # got it, so print name to check
             print (lcon.Name + " " +lcon.ClassName()+"\n\n")
             #ok now find its active properties to set
             fCon = lcon.PropertyList.Find("Active")
             #print it so we know what it was for debug
             print fCon.Data
             #set it to 0 to deactiave it
             fCon.Data = 0
             #print it agian to see if it changed for debuging
             print fCon.Data
             # deactivate the constraint.


This code can be cleaned up but the process to find the constraint, find a property and then set that property was just about impossible to find help or examples on. Hope it helps some one else out there.

Thanks Al for setting this forum up.
Brad


_________________
Brad Clark
Motion Editor/Animator/Character TD... The Animation Farm ...Austin TX
View user's profile Send private message
Reply with quote
Post  
Hey Brad,

This is another way of doing it through the FBConstraintManager. Might be a bit quicker on larger scenes as it only searches through the list of constraints and not the whole scene

Code:

from pyfbsdk import FBConstraintManager

# Initialize the constraint manager
lConstraintManager = FBConstraintManager()
# get the number of constraints
count = lConstraintManager.ConstraintGetCount()
lTargetName = 'test' # just a sample name - this could be passed as an arg.

counter = 0
while counter < count:  # iterate through the list of constraints
    iConstraint = lConstraintManager.ConstraintGet( counter )
    if iConstraint.Name == lTargetName:
        print 'Turning %s(%s) OFF'%(iConstraint.Name, iConstraint.Description)
        iConstraint.SetActive( False )
    counter += 1

del( FBConstraintManager )


Just another way of doing the same thing. Have to agree with you on the 'impossible to find help' comment. Gonna love this forum! Nice one Al!

Cheers,
Phil


_________________
phil boltt | motion edit | weta digital
View user's profile Send private message
Reply with quote
Post  
ah cool, thanks

Funny I tried first with the constraint manager but I thought the "list of Constraints" was for creating them and not accessing them. Since I could use it to build the constraint I was just not able to figure out how to have it find ones that exist.

Thanks again Phil and say hi to Bassim.


_________________
Brad Clark
Motion Editor/Animator/Character TD... The Animation Farm ...Austin TX
View user's profile Send private message
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
  


RegisterSearchFAQMemberlistUsergroupsLog in