Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® MotionBuilder® / Python / python help producing function box on Relational Constraint
  RSS 2.0 ATOM  

python help producing function box on Relational Constraint
Rate this thread
 
22893
 
Permlink of this thread  
avatar
  • Total Posts: 9
  • Joined: 17 February 2009 03:03 PM

hi all,

I am trying to create an Add function box inside a relational constraint.

I have managed to create the relational constraint on the selected object and created other sender boxes/FunctionBoxes (number to vector, etc) inside of the constraint and connected them succesfully.

But on creating the Add Function box it crashes motionbuilder.  I have even rewritten it three times in a seperate script and it still crashes Motionbuilder Can anyone see what I am doing wrong?

The code:

selectedModels = FBModelList()
FBGetSelectedModels (selectedModels, None, True)

lConstraintRelation = FBConstraintRelation( ‘Sue_ZNull_constraint’ )

lAddBox = lConstraintRelation.CreateFunctionBox(’Number’, ‘Add’)
lConstraintRelation.SetBoxPosition(lAddBox, 10, 50)

The line:
lAddBox = lConstraintRelation.CreateFunctionbox(’Number’, ‘Add’)
is the same code used to create a successful ‘If cond a and b’ functionbox.  The only thing changed is the name of the function ‘Add’

help! a confused Sue.

I am using Motionbuilder 2009

many thanks in advance.

Sue.



Replies: 0
avatar
  • Avalon
  • Posted: 17 February 2009 11:36 AM

Hi Sue,
MB usually crashes when you add a none existing box into a relation constriant. So the in your sample above should be:

lAddBox = lConstraintRelation.CreateFunctionBox(’Number’, ‘Add (a + b)’)

Just as an example as it can be tricky to se i’ve clearified the spaces with an underscore “Add_(a_+_b)”

Hope it helped!

Cheers,
AV



Choose a job you love, and you will never have to work a day in your life.

Replies: 0
avatar

hi AV,

Many thanks for your response. It worked.

I did try a few different variations with different spaces with and without the a and b.  But obviously not that combination, doh!

Thanks again.

Sue



Replies: 0
avatar

hi AV and other MB TD’s,

Just a couple of quick questions.  I have almost finished my script but I need to change the sender and reciever boxes to local transformations.  The only relevant class I have found are to do with the matrix.  Is there any other route to do this? 

The other thing is changing a specific value so again in my add box I need to change the value of ‘a’ to an integer of -131 (same as right clicking and Set Value).  So far the closest I have found is the WriteData (although I am not entirely clear how this works and what it does) and the SetCandidate.  Also is it actually possible to do this in Python?

As you can probably tell I am new to motionbuilder and Python (VB and XSI Person) so would appreciate any help.

many thanks again,

Sue.



Replies: 0
avatar
  • Avalon
  • Posted: 18 February 2009 10:58 AM

Hi Sue!
To set the senders and receivers to local do the following:

tmpBox tmpRelation.ConstrainObjecttmpObj )
tmpBox.UseGlobalTransforms = (False)
tmpRelation.SetBoxPositiontmpBox050 )

For setting a value in one of the nodes:

# Find Animation Node in relation constraint
def FindAnimationNodepParentpName ):
    
lResult None
    
for lNode in pParent.Nodes:
        if 
lNode.Name == pName:
            
lResult lNode
            
break
    return 
lResult
#-------------------------------------------------------------
inPlugs FindAnimationNode(tmpBox .AnimationNodeInGet(), 'a')
inPlugs.WriteData ([0])

Hope it helped!

Cheers,
Avalon



Choose a job you love, and you will never have to work a day in your life.

Replies: 0
avatar

hi Avalon,

Thank you so much.  I did just manage to find the global transforms in the end but it took me ages to find it in the documentation.

However the changing of the set value I had not been able to do all day and it is getting close to home time which is a great help to me.

By the way I was chatting to my Supervisor Daven and he seems to think you guys might know each other.  He worked at Northern lights(I think?) and the other Mocap company in Uppsala.  Do you know him?  He is a Canadian guy.  Anyway he seems to think he may know some of your colleagues at the very least.

I work at Digi guys in Ealing Studios with him.

Thanks again, it is quite stressful learning both Motionbuilder constraints and Python.

Sue.



Replies: 0
avatar
  • Avalon
  • Posted: 18 February 2009 01:21 PM

Hi Sue!
Hehe! Of course I know Daven! We worked together for a while a few years back!! I now work, as you mentioned at Northern Light Studios in Uppsala!
Say hi to him from me!

Drop me a mail if you need any more help!

All the best,
Avalon



Choose a job you love, and you will never have to work a day in your life.

Replies: 0
avatar

hi avalon,

I was going to send you a mail but I could not attach an image which I need to do…

Many thanks for all your help with my past problems with python scripting I would not have done it in the time I did without you.
The relation constraint script was completed but there are a few issues with it.  For example we wanted to tie the translation of an object to the z translation of another object and the x and Y would be animatable (translated by the animator ) but this is not the case in motionbuilder 2009 . the x and y is fixed so it cannot be moved.  We are trying to find a solution for this we have tried expression constraints but that did not work either, still locked.  Obviously I do not expect you to do the job for me but it would be of great help if you had any ideas or had a similiar issue.  I am new to motionbuilder constraints as well as the sdk and the python so my brain is feeling a little overloaded right now and don’t quite know where to look to solve this one. 

cheers Av,

Sue.



Attachment Attachment
Replies: 0
avatar
  • Avalon
  • Posted: 26 February 2009 08:57 AM

Hi Sue!
No problem, glad I could help!

I think I can understand what your trying to do.
Problem here is that you lock the X and Y with your coditions in one way but doesnt allow it to transfere anything else.
You’d need to pipe the values from your Z_Null.Translation --> IF Cond b number I’d imagine. Also, if you’d add animation ontop of the already existing animation from the “Hips” node you could easily add the Translation from your Hips node to your Z_NULL at the beginning or end in the chain. This will allow you to move the Z_Null but till recive it from the Hips…
I hope this made sense..?!?!

If you’d like me to take a closer look you could email me the relation constraint and the Z_Null object and I can take a closer look! I can send you a PM with my mail address.

Cheers,
AV



Choose a job you love, and you will never have to work a day in your life.

Replies: 0
avatar
  • lokkook
  • Posted: 04 February 2010 02:42 AM

Hi all,

Thanks for this interesting post. I still have some question :

# Find Animation Node in relation constraint
def FindAnimationNode( pParent, pName ):
lResult = None
for lNode in pParent.Nodes:
if lNode.Name == pName:
lResult = lNode
break
return lResult
#-------------------------------------------------------------
inPlugs = FindAnimationNode(tmpBox .AnimationNodeInGet(), ‘a’)
inPlugs.WriteData ([0])

Is there a way to perform a “ReadData”? I searched for a while and did not find anything…
Do you have an idea ?

Thanks,
L.



Replies: 0