Python Reference Guide
 
Loading...
Searching...
No Matches
Tasks\CreateAndPopulateAConstraintRelation.py
1# Copyright 2009 Autodesk, Inc. All rights reserved.
2# Use of this software is subject to the terms of the Autodesk license agreement
3# provided at the time of installation or download, or which otherwise accompanies
4# this software in either electronic or hard copy form.
5#
6# Topic: FBConstraintRelation, FBConnect
7#
8from pyfbsdk import FBConstraintRelation, FBModelMarker, FBConnect
9
10# Define a utility function to look up a named animation node
11# under a given parent. Will not recurse in the hierarchy.
12def FindAnimationNode( pParent, pName ):
13 lResult = None
14 for lNode in pParent.Nodes:
15 if lNode.Name == pName:
16 lResult = lNode
17 break
18 return lResult
19
20# Create a constraint relation. No need to use the FBConstraintManager.
21lConstraintRelation = FBConstraintRelation( 'AConstraintRelation' )
22
23# Create an object which will be constrained in the relation.
24lModel = FBModelMarker( 'AModelMarker' )
25lModel.Translation.SetAnimated(True)
26lModel.Visible = True
27
28# Create a source and place it in 2D space.
29lSineRampBox = lConstraintRelation.CreateFunctionBox( 'Sources', 'Sine Ramp' )
30lConstraintRelation.SetBoxPosition( lSineRampBox, 30, 30 )
31
32# Create a converter.
33lNumberToVectorBox = lConstraintRelation.CreateFunctionBox( 'Converters', 'Number to Vector' )
34lConstraintRelation.SetBoxPosition( lNumberToVectorBox, 400, 30 )
35
36# Now insert the marker in the constraint. Set its position.
37lPlaceHolderBox = lConstraintRelation.ConstrainObject( lModel )
38lConstraintRelation.SetBoxPosition(lPlaceHolderBox, 700, 30)
39
40# In order to set up the constraint, we need to connect the boxe's
41# animation node together.
42
43# We will connect the sine ramp to the converter.
44lSineRampOut = FindAnimationNode( lSineRampBox.AnimationNodeOutGet(), 'Result' )
45lNumberToVectorIn = FindAnimationNode( lNumberToVectorBox.AnimationNodeInGet(), 'Y' )
46if lSineRampOut and lNumberToVectorIn:
47 FBConnect( lSineRampOut, lNumberToVectorIn )
48
49# And connect the converter to the translation of the marker.
50lNumberToVectorOut = FindAnimationNode( lNumberToVectorBox.AnimationNodeOutGet(), 'Result' )
51lModelIn = FindAnimationNode( lPlaceHolderBox.AnimationNodeInGet(), 'Translation' )
52if lNumberToVectorOut and lModelIn:
53 FBConnect( lNumberToVectorOut, lModelIn )
54
55# Finally activate the constraint.
56lConstraintRelation.Active = True
57
58# Cleanup of local variables.
59del( lModelIn, lNumberToVectorOut, lNumberToVectorIn, lSineRampOut, lPlaceHolderBox, lNumberToVectorBox, lSineRampBox, lModel, lConstraintRelation )
60
61# Cleanup of local functions.
62del( FindAnimationNode )
63
64# Cleanup of imported symbols.
65del( FBConstraintRelation, FBModelMarker, FBConnect )
ConstraintRelation class.
Definition: pyfbsdk_generated.h:5087
Model marker class.
Definition: pyfbsdk_generated.h:11380